|
| 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 | +describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => { |
| 13 | + describe('Option: "define"', () => { |
| 14 | + it('should replace a value in application code when specified as a number', async () => { |
| 15 | + harness.useTarget('build', { |
| 16 | + ...BASE_OPTIONS, |
| 17 | + define: { |
| 18 | + 'AN_INTEGER': '42', |
| 19 | + }, |
| 20 | + }); |
| 21 | + |
| 22 | + await harness.writeFile('./src/types.d.ts', 'declare const AN_INTEGER: number;'); |
| 23 | + await harness.writeFile('src/main.ts', 'console.log(AN_INTEGER);'); |
| 24 | + |
| 25 | + const { result } = await harness.executeOnce(); |
| 26 | + expect(result?.success).toBe(true); |
| 27 | + harness.expectFile('dist/browser/main.js').content.not.toContain('AN_INTEGER'); |
| 28 | + harness.expectFile('dist/browser/main.js').content.toContain('(42)'); |
| 29 | + }); |
| 30 | + |
| 31 | + it('should replace a value in application code when specified as a string', async () => { |
| 32 | + harness.useTarget('build', { |
| 33 | + ...BASE_OPTIONS, |
| 34 | + define: { |
| 35 | + 'A_STRING': '"42"', |
| 36 | + }, |
| 37 | + }); |
| 38 | + |
| 39 | + await harness.writeFile('./src/types.d.ts', 'declare const A_STRING: string;'); |
| 40 | + await harness.writeFile('src/main.ts', 'console.log(A_STRING);'); |
| 41 | + |
| 42 | + const { result } = await harness.executeOnce(); |
| 43 | + expect(result?.success).toBe(true); |
| 44 | + harness.expectFile('dist/browser/main.js').content.not.toContain('A_STRING'); |
| 45 | + harness.expectFile('dist/browser/main.js').content.toContain('("42")'); |
| 46 | + }); |
| 47 | + |
| 48 | + it('should replace a value in application code when specified as a boolean', async () => { |
| 49 | + harness.useTarget('build', { |
| 50 | + ...BASE_OPTIONS, |
| 51 | + define: { |
| 52 | + 'A_BOOLEAN': 'true', |
| 53 | + }, |
| 54 | + }); |
| 55 | + |
| 56 | + await harness.writeFile('./src/types.d.ts', 'declare const A_BOOLEAN: boolean;'); |
| 57 | + await harness.writeFile('src/main.ts', 'console.log(A_BOOLEAN);'); |
| 58 | + |
| 59 | + const { result } = await harness.executeOnce(); |
| 60 | + expect(result?.success).toBe(true); |
| 61 | + harness.expectFile('dist/browser/main.js').content.not.toContain('A_BOOLEAN'); |
| 62 | + harness.expectFile('dist/browser/main.js').content.toContain('(true)'); |
| 63 | + }); |
| 64 | + }); |
| 65 | +}); |
0 commit comments