/
font-optimization_spec.ts
74 lines (63 loc) · 2.25 KB
/
font-optimization_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
/**
* @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 { Architect } from '@angular-devkit/architect';
import { browserBuild, createArchitect, host } from '../../testing/test-utils';
describe('Browser Builder font optimization', () => {
const target = { project: 'app', target: 'build' };
const overrides = {
optimization: {
styles: false,
fonts: true,
},
};
let architect: Architect;
beforeEach(async () => {
await host.initialize().toPromise();
architect = (await createArchitect(host.root())).architect;
host.replaceInFile(
'/src/index.html',
'<head>',
`<head><link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">`,
);
});
afterEach(async () => host.restore().toPromise());
it('works', async () => {
const { files } = await browserBuild(architect, host, target, overrides);
const html = await files['index.html'];
expect(html).not.toContain('href="https://fonts.googleapis.com/css?family=Roboto:300,400,500"');
expect(html).toContain(`font-family: 'Roboto'`);
});
it('should not add woff', async () => {
const { files } = await browserBuild(architect, host, target, overrides);
const html = await files['index.html'];
expect(html).toContain(`format('woff2');`);
expect(html).not.toContain(`format('woff');`);
});
it('should remove comments and line breaks when styles optimization is true', async () => {
const { files } = await browserBuild(architect, host, target, {
optimization: {
styles: true,
fonts: true,
},
});
const html = await files['index.html'];
expect(html).not.toContain('/*');
expect(html).toContain(';font-style:normal;');
});
it('should not remove comments and line breaks when styles optimization is false', async () => {
const { files } = await browserBuild(architect, host, target, {
optimization: {
styles: false,
fonts: true,
},
});
const html = await files['index.html'];
expect(html).toContain('/*');
expect(html).toContain(' font-style: normal;\n');
});
});