forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 1
/
named-chunks_spec.ts
70 lines (55 loc) · 2.09 KB
/
named-chunks_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
/**
* @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 { buildApplication } from '../../index';
import { APPLICATION_BUILDER_INFO, BASE_OPTIONS, describeBuilder } from '../setup';
const MAIN_OUTPUT = 'dist/main.js';
const NAMED_LAZY_OUTPUT = 'dist/lazy-module-7QZXF7K7.js';
const UNNAMED_LAZY_OUTPUT = 'dist/chunk-OW5RYMPM.js';
describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
describe('Option: "namedChunks"', () => {
beforeEach(async () => {
// Setup a lazy loaded chunk
await harness.writeFiles({
'src/lazy-module.ts': 'export const value = 42;',
'src/main.ts': `import('./lazy-module');`,
});
});
it('generates named files in output when true', async () => {
harness.useTarget('build', {
...BASE_OPTIONS,
namedChunks: true,
});
const { result } = await harness.executeOnce();
expect(result?.success).toBe(true);
harness.expectFile(MAIN_OUTPUT).toExist();
harness.expectFile(NAMED_LAZY_OUTPUT).toExist();
harness.expectFile(UNNAMED_LAZY_OUTPUT).toNotExist();
});
it('does not generate named files in output when false', async () => {
harness.useTarget('build', {
...BASE_OPTIONS,
namedChunks: false,
});
const { result } = await harness.executeOnce();
expect(result?.success).toBe(true);
harness.expectFile(MAIN_OUTPUT).toExist();
harness.expectFile(NAMED_LAZY_OUTPUT).toNotExist();
harness.expectFile(UNNAMED_LAZY_OUTPUT).toExist();
});
it('does not generates named files in output when not present', async () => {
harness.useTarget('build', {
...BASE_OPTIONS,
});
const { result } = await harness.executeOnce();
expect(result?.success).toBe(true);
harness.expectFile(MAIN_OUTPUT).toExist();
harness.expectFile(NAMED_LAZY_OUTPUT).toNotExist();
harness.expectFile(UNNAMED_LAZY_OUTPUT).toExist();
});
});
});