|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright Google LLC 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 | + |
| 9 | +import { buildApplication } from '../../index'; |
| 10 | +import { APPLICATION_BUILDER_INFO, BASE_OPTIONS, describeBuilder } from '../setup'; |
| 11 | + |
| 12 | +const MAIN_OUTPUT = 'dist/main.js'; |
| 13 | +const NAMED_LAZY_OUTPUT = 'dist/lazy-module-7QZXF7K7.js'; |
| 14 | +const UNNAMED_LAZY_OUTPUT = 'dist/chunk-OW5RYMPM.js'; |
| 15 | + |
| 16 | +describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => { |
| 17 | + describe('Option: "namedChunks"', () => { |
| 18 | + beforeEach(async () => { |
| 19 | + // Setup a lazy loaded chunk |
| 20 | + await harness.writeFiles({ |
| 21 | + 'src/lazy-module.ts': 'export const value = 42;', |
| 22 | + 'src/main.ts': `import('./lazy-module');`, |
| 23 | + }); |
| 24 | + }); |
| 25 | + |
| 26 | + it('generates named files in output when true', async () => { |
| 27 | + harness.useTarget('build', { |
| 28 | + ...BASE_OPTIONS, |
| 29 | + namedChunks: true, |
| 30 | + }); |
| 31 | + |
| 32 | + const { result } = await harness.executeOnce(); |
| 33 | + |
| 34 | + expect(result?.success).toBe(true); |
| 35 | + |
| 36 | + harness.expectFile(MAIN_OUTPUT).toExist(); |
| 37 | + harness.expectFile(NAMED_LAZY_OUTPUT).toExist(); |
| 38 | + harness.expectFile(UNNAMED_LAZY_OUTPUT).toNotExist(); |
| 39 | + }); |
| 40 | + |
| 41 | + it('does not generate named files in output when false', async () => { |
| 42 | + harness.useTarget('build', { |
| 43 | + ...BASE_OPTIONS, |
| 44 | + namedChunks: false, |
| 45 | + }); |
| 46 | + |
| 47 | + const { result } = await harness.executeOnce(); |
| 48 | + |
| 49 | + expect(result?.success).toBe(true); |
| 50 | + |
| 51 | + harness.expectFile(MAIN_OUTPUT).toExist(); |
| 52 | + harness.expectFile(NAMED_LAZY_OUTPUT).toNotExist(); |
| 53 | + harness.expectFile(UNNAMED_LAZY_OUTPUT).toExist(); |
| 54 | + }); |
| 55 | + |
| 56 | + it('does not generates named files in output when not present', async () => { |
| 57 | + harness.useTarget('build', { |
| 58 | + ...BASE_OPTIONS, |
| 59 | + }); |
| 60 | + |
| 61 | + const { result } = await harness.executeOnce(); |
| 62 | + |
| 63 | + expect(result?.success).toBe(true); |
| 64 | + |
| 65 | + harness.expectFile(MAIN_OUTPUT).toExist(); |
| 66 | + harness.expectFile(NAMED_LAZY_OUTPUT).toNotExist(); |
| 67 | + harness.expectFile(UNNAMED_LAZY_OUTPUT).toExist(); |
| 68 | + }); |
| 69 | + }); |
| 70 | +}); |
0 commit comments