Skip to content

Commit cbbb3d2

Browse files
clydinalan-agius4
authored andcommitted
test(@angular-devkit/build-angular): add browser builder namedChunks option tests
This change adds expanded unit tests for the browser builder's `namedChunks` option using the builder test harness.
1 parent ee64411 commit cbbb3d2

File tree

2 files changed

+69
-11
lines changed

2 files changed

+69
-11
lines changed

packages/angular_devkit/build_angular/src/browser/specs/lazy-module_spec.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,6 @@ describe('Browser Builder lazy modules', () => {
176176
expect(files['lazy-module.js']).not.toBeUndefined();
177177
});
178178

179-
it(`supports hiding lazy bundle module name`, async () => {
180-
host.writeMultipleFiles({
181-
'src/lazy-module.ts': 'export const value = 42;',
182-
'src/main.ts': `const lazyFileName = 'module'; import('./lazy-' + lazyFileName);`,
183-
});
184-
host.replaceInFile('src/tsconfig.app.json', `"module": "es2015"`, `"module": "esnext"`);
185-
186-
const { files } = await browserBuild(architect, host, target, { namedChunks: false });
187-
expect(files['0.js']).not.toBeUndefined();
188-
});
189-
190179
it(`supports making a common bundle for shared lazy modules`, async () => {
191180
host.writeMultipleFiles({
192181
'src/one.ts': `import * as http from '@angular/common/http'; console.log(http);`,
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
import { buildWebpackBrowser } from '../../index';
9+
import { BASE_OPTIONS, BROWSER_BUILDER_INFO, describeBuilder } from '../setup';
10+
11+
const MAIN_OUTPUT = 'dist/main.js';
12+
const NAMED_LAZY_OUTPUT = 'dist/lazy-module.js';
13+
const UNNAMED_LAZY_OUTPUT = 'dist/0.js';
14+
15+
describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
16+
describe('Option: "namedChunks"', () => {
17+
beforeEach(async () => {
18+
// Setup a lazy loaded chunk
19+
await harness.writeFiles({
20+
'src/lazy-module.ts': 'export const value = 42;',
21+
'src/main.ts': `import('./lazy-module');`,
22+
});
23+
});
24+
25+
it('generates named files in output when true', async () => {
26+
harness.useTarget('build', {
27+
...BASE_OPTIONS,
28+
namedChunks: true,
29+
});
30+
31+
const { result } = await harness.executeOnce();
32+
33+
expect(result?.success).toBe(true);
34+
35+
harness.expectFile(MAIN_OUTPUT).toExist();
36+
harness.expectFile(NAMED_LAZY_OUTPUT).toExist();
37+
harness.expectFile(UNNAMED_LAZY_OUTPUT).toNotExist();
38+
});
39+
40+
it('does not generate named files in output when false', async () => {
41+
harness.useTarget('build', {
42+
...BASE_OPTIONS,
43+
namedChunks: false,
44+
});
45+
46+
const { result } = await harness.executeOnce();
47+
48+
expect(result?.success).toBe(true);
49+
50+
harness.expectFile(MAIN_OUTPUT).toExist();
51+
harness.expectFile(NAMED_LAZY_OUTPUT).toNotExist();
52+
harness.expectFile(UNNAMED_LAZY_OUTPUT).toExist();
53+
});
54+
55+
it('generates named files in output when not present', async () => {
56+
harness.useTarget('build', {
57+
...BASE_OPTIONS,
58+
});
59+
60+
const { result } = await harness.executeOnce();
61+
62+
expect(result?.success).toBe(true);
63+
64+
harness.expectFile(MAIN_OUTPUT).toExist();
65+
harness.expectFile(NAMED_LAZY_OUTPUT).toExist();
66+
harness.expectFile(UNNAMED_LAZY_OUTPUT).toNotExist();
67+
});
68+
});
69+
});

0 commit comments

Comments
 (0)