-
Notifications
You must be signed in to change notification settings - Fork 12k
/
Copy pathaugment-index-html_spec.ts
115 lines (104 loc) · 3.33 KB
/
augment-index-html_spec.ts
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
109
110
111
112
113
114
115
/**
* @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.io/license
*/
import { tags } from '@angular-devkit/core';
import { AugmentIndexHtmlOptions, augmentIndexHtml } from './augment-index-html';
describe('augment-index-html', () => {
const indexGeneratorOptions: AugmentIndexHtmlOptions = {
html: '<html><head></head><body></body></html>',
baseHref: '/',
sri: false,
files: [],
loadOutputFile: async (_fileName: string) => '',
entrypoints: [
['scripts', false],
['polyfills', true],
['main', true],
['styles', false],
],
};
const oneLineHtml = (html: TemplateStringsArray) =>
tags.stripIndents`${html}`.replace(/(>\s+)/g, '>');
it('can generate index.html', async () => {
const source = augmentIndexHtml({
...indexGeneratorOptions,
files: [
{ file: 'styles.css', extension: '.css', name: 'styles' },
{ file: 'runtime.js', extension: '.js', name: 'main' },
{ file: 'main.js', extension: '.js', name: 'main' },
{ file: 'runtime.js', extension: '.js', name: 'polyfills' },
{ file: 'polyfills.js', extension: '.js', name: 'polyfills' },
],
});
const html = await source;
expect(html).toEqual(oneLineHtml`
<html>
<head><base href="/">
<link rel="stylesheet" href="styles.css">
</head>
<body>
<script src="runtime.js" type="module"></script>
<script src="polyfills.js" type="module"></script>
<script src="main.js" type="module"></script>
</body>
</html>
`);
});
it('should replace base href value', async () => {
const source = augmentIndexHtml({
...indexGeneratorOptions,
html: '<html><head><base href="/"></head><body></body></html>',
baseHref: '/Apps/',
});
const html = await source;
expect(html).toEqual(oneLineHtml`
<html>
<head><base href="/Apps/">
</head>
<body>
</body>
</html>
`);
});
it('should add lang attribute', async () => {
const source = augmentIndexHtml({
...indexGeneratorOptions,
lang: 'fr',
});
const html = await source;
expect(html).toEqual(oneLineHtml`
<html lang="fr">
<head>
<base href="/">
</head>
<body>
</body>
</html>
`);
});
it(`should add script and link tags even when body and head element doesn't exist`, async () => {
const source = augmentIndexHtml({
...indexGeneratorOptions,
html: `<app-root></app-root>`,
files: [
{ file: 'styles.css', extension: '.css', name: 'styles' },
{ file: 'runtime.js', extension: '.js', name: 'main' },
{ file: 'main.js', extension: '.js', name: 'main' },
{ file: 'runtime.js', extension: '.js', name: 'polyfills' },
{ file: 'polyfills.js', extension: '.js', name: 'polyfills' },
],
});
const html = await source;
expect(html).toEqual(oneLineHtml`
<link rel="stylesheet" href="styles.css">
<script src="runtime.js" type="module"></script>
<script src="polyfills.js" type="module"></script>
<script src="main.js" type="module"></script>
<app-root></app-root>
`);
});
});