-
Notifications
You must be signed in to change notification settings - Fork 12k
/
Copy pathoptimization-level_spec_large.ts
95 lines (79 loc) · 3.2 KB
/
optimization-level_spec_large.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
/**
* @license
* Copyright Google Inc. 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 '../utils';
describe('Browser Builder optimization level', () => {
const target = { project: 'app', target: 'build' };
let architect: Architect;
beforeEach(async () => {
await host.initialize().toPromise();
architect = (await createArchitect(host.root())).architect;
});
afterEach(async () => host.restore().toPromise());
it('works', async () => {
const overrides = { optimization: true };
const { files } = await browserBuild(architect, host, target, overrides);
expect(await files['main.js']).not.toContain('AppComponent');
});
it('tsconfig target changes optimizations to use ES2015', async () => {
host.replaceInFile('tsconfig.json', '"target": "es5"', '"target": "es2015"');
const overrides = { optimization: true };
const { files } = await browserBuild(architect, host, target, overrides);
expect(await files['vendor.js']).toMatch(/class \w{constructor\(\){/);
});
it('supports styles only optimizations', async () => {
const overrides = {
optimization: {
styles: true,
scripts: false,
},
aot: true,
extractCss: true,
styles: ['src/styles.css'],
};
host.appendToFile('src/main.ts', '/** js comment should not be dropped */');
host.appendToFile('src/app/app.component.css', 'div { color: white }');
host.writeMultipleFiles({
'src/styles.css': `div { color: white }`,
});
const { files } = await browserBuild(architect, host, target, overrides);
expect(await files['main.js']).toContain('js comment should not be dropped');
expect(await files['main.js']).toContain('color:#fff');
expect(await files['styles.css']).toContain('color:#fff');
});
it('supports scripts only optimizations', async () => {
const overrides = {
optimization: {
styles: false,
scripts: true,
},
aot: true,
extractCss: true,
styles: ['src/styles.css'],
};
host.appendToFile('src/main.ts', '/** js comment should be dropped */');
host.appendToFile('src/app/app.component.css', 'div { color: white }');
host.writeMultipleFiles({
'src/styles.css': `div { color: white }`,
});
const { files } = await browserBuild(architect, host, target, overrides);
expect(await files['main.js']).not.toContain('js comment should be dropped');
expect(await files['main.js']).toContain('color: white');
expect(await files['styles.css']).toContain('color: white');
});
it('outputs ASCII only content', async () => {
const overrides = { aot: true, optimization: true };
host.writeMultipleFiles({
'src/app/app.component.html': `<p>€€€</p>`,
});
const { files } = await browserBuild(architect, host, target, overrides);
expect(await files['main.js']).not.toContain('ɵ');
expect(await files['main.js']).not.toContain('€€€');
expect(await files['main.js']).toContain('\\u20ac\\u20ac\\u20ac');
});
});