forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy-url_spec.ts
More file actions
108 lines (93 loc) · 3.71 KB
/
deploy-url_spec.ts
File metadata and controls
108 lines (93 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { buildApplication } from '../../index';
import { APPLICATION_BUILDER_INFO, BASE_OPTIONS, describeBuilder } from '../setup';
describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
describe('Option: "deployUrl"', () => {
beforeEach(async () => {
// Add a global stylesheet to test link elements
await harness.writeFile('src/styles.css', '/* Global styles */');
// Reduce the input index HTML to a single line to simplify comparing
await harness.writeFile(
'src/index.html',
'<html><head><base href="/"></head><body><app-root></app-root></body></html>',
);
});
it('should update script src and link href attributes when option is set to relative URL', async () => {
harness.useTarget('build', {
...BASE_OPTIONS,
styles: ['src/styles.css'],
deployUrl: 'deployUrl/',
});
const { result } = await harness.executeOnce();
expect(result?.success).toBe(true);
harness
.expectFile('dist/browser/index.html')
.content.toEqual(
`<html><head><base href="/"><link rel="stylesheet" href="deployUrl/styles.css"></head>` +
`<body><app-root></app-root>` +
`<script src="deployUrl/main.js" type="module"></script></body></html>`,
);
});
it('should update script src and link href attributes when option is set to absolute URL', async () => {
harness.useTarget('build', {
...BASE_OPTIONS,
styles: ['src/styles.css'],
deployUrl: 'https://example.com/some/path/',
});
const { result } = await harness.executeOnce();
expect(result?.success).toBe(true);
harness
.expectFile('dist/browser/index.html')
.content.toEqual(
`<html><head><base href="/"><link rel="stylesheet" href="https://example.com/some/path/styles.css"></head>` +
`<body><app-root></app-root>` +
`<script src="https://example.com/some/path/main.js" type="module"></script></body></html>`,
);
});
it('should prepend deploy URL to file loader import URLs', async () => {
await harness.writeFile(
'./src/types.d.ts',
'declare module "*.svg" { const url: string; export default url; }',
);
await harness.writeFile('./src/app/test.svg', '<svg></svg>');
await harness.writeFile(
'src/main.ts',
`import svgUrl from './app/test.svg';\nconsole.log(svgUrl);`,
);
harness.useTarget('build', {
...BASE_OPTIONS,
loader: {
'.svg': 'file',
},
deployUrl: 'https://example.com/some/path/',
});
const { result } = await harness.executeOnce();
expect(result?.success).toBeTrue();
harness
.expectFile('dist/browser/main.js')
.content.toContain('https://example.com/some/path/media/test.svg');
});
it('should update resources component stylesheets to reference deployURL', async () => {
await harness.writeFile('src/app/test.svg', '<svg></svg>');
await harness.writeFile(
'src/app/app.component.css',
`* { background-image: url('./test.svg'); }`,
);
harness.useTarget('build', {
...BASE_OPTIONS,
deployUrl: 'https://example.com/some/path/',
});
const { result } = await harness.executeOnce();
expect(result?.success).toBeTrue();
harness
.expectFile('dist/browser/main.js')
.content.toContain('background-image: url("https://example.com/some/path/media/test.svg")');
});
});
});