|
| 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