|
9 | 9 | import { buildApplication } from '../../index';
|
10 | 10 | import { APPLICATION_BUILDER_INFO, BASE_OPTIONS, describeBuilder } from '../setup';
|
11 | 11 |
|
| 12 | +const testsVariants: [suitName: string, baseUrl: string | undefined][] = [ |
| 13 | + ['When "baseUrl" is set to "./"', './'], |
| 14 | + [`When "baseUrl" is not set`, undefined], |
| 15 | + [`When "baseUrl" is set to non root path`, './project/foo'], |
| 16 | +]; |
| 17 | + |
12 | 18 | describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
|
13 |
| - describe('Option: "polyfills"', () => { |
14 |
| - it('uses a provided TypeScript file', async () => { |
15 |
| - harness.useTarget('build', { |
16 |
| - ...BASE_OPTIONS, |
17 |
| - polyfills: ['src/polyfills.ts'], |
| 19 | + for (const [suitName, baseUrl] of testsVariants) { |
| 20 | + describe(suitName, () => { |
| 21 | + beforeEach(async () => { |
| 22 | + await harness.modifyFile('tsconfig.json', (content) => { |
| 23 | + const tsconfig = JSON.parse(content); |
| 24 | + tsconfig.compilerOptions.baseUrl = baseUrl; |
| 25 | + |
| 26 | + return JSON.stringify(tsconfig); |
| 27 | + }); |
18 | 28 | });
|
19 | 29 |
|
20 |
| - const { result } = await harness.executeOnce(); |
21 |
| - |
22 |
| - expect(result?.success).toBe(true); |
| 30 | + it('uses a provided TypeScript file', async () => { |
| 31 | + harness.useTarget('build', { |
| 32 | + ...BASE_OPTIONS, |
| 33 | + polyfills: ['src/polyfills.ts'], |
| 34 | + }); |
23 | 35 |
|
24 |
| - harness.expectFile('dist/polyfills.js').toExist(); |
25 |
| - }); |
| 36 | + const { result } = await harness.executeOnce(); |
26 | 37 |
|
27 |
| - it('uses a provided JavaScript file', async () => { |
28 |
| - await harness.writeFile('src/polyfills.js', `console.log('main');`); |
| 38 | + expect(result?.success).toBe(true); |
29 | 39 |
|
30 |
| - harness.useTarget('build', { |
31 |
| - ...BASE_OPTIONS, |
32 |
| - polyfills: ['src/polyfills.js'], |
| 40 | + harness.expectFile('dist/polyfills.js').toExist(); |
33 | 41 | });
|
34 | 42 |
|
35 |
| - const { result } = await harness.executeOnce(); |
| 43 | + it('uses a provided JavaScript file', async () => { |
| 44 | + await harness.writeFile('src/polyfills.js', `console.log('main');`); |
36 | 45 |
|
37 |
| - expect(result?.success).toBe(true); |
| 46 | + harness.useTarget('build', { |
| 47 | + ...BASE_OPTIONS, |
| 48 | + polyfills: ['src/polyfills.js'], |
| 49 | + }); |
38 | 50 |
|
39 |
| - harness.expectFile('dist/polyfills.js').content.toContain(`console.log("main")`); |
40 |
| - }); |
| 51 | + const { result } = await harness.executeOnce(); |
41 | 52 |
|
42 |
| - it('fails and shows an error when file does not exist', async () => { |
43 |
| - harness.useTarget('build', { |
44 |
| - ...BASE_OPTIONS, |
45 |
| - polyfills: ['src/missing.ts'], |
| 53 | + expect(result?.success).toBe(true); |
| 54 | + |
| 55 | + harness.expectFile('dist/polyfills.js').content.toContain(`console.log("main")`); |
46 | 56 | });
|
47 | 57 |
|
48 |
| - const { result, logs } = await harness.executeOnce({ outputLogsOnFailure: false }); |
| 58 | + it('fails and shows an error when file does not exist', async () => { |
| 59 | + harness.useTarget('build', { |
| 60 | + ...BASE_OPTIONS, |
| 61 | + polyfills: ['src/missing.ts'], |
| 62 | + }); |
49 | 63 |
|
50 |
| - expect(result?.success).toBe(false); |
51 |
| - expect(logs).toContain( |
52 |
| - jasmine.objectContaining({ message: jasmine.stringMatching('Could not resolve') }), |
53 |
| - ); |
| 64 | + const { result, logs } = await harness.executeOnce({ outputLogsOnFailure: false }); |
54 | 65 |
|
55 |
| - harness.expectFile('dist/polyfills.js').toNotExist(); |
56 |
| - }); |
| 66 | + expect(result?.success).toBe(false); |
| 67 | + expect(logs).toContain( |
| 68 | + jasmine.objectContaining({ message: jasmine.stringMatching('Could not resolve') }), |
| 69 | + ); |
57 | 70 |
|
58 |
| - it('resolves module specifiers in array', async () => { |
59 |
| - harness.useTarget('build', { |
60 |
| - ...BASE_OPTIONS, |
61 |
| - polyfills: ['zone.js', 'zone.js/testing'], |
| 71 | + harness.expectFile('dist/polyfills.js').toNotExist(); |
62 | 72 | });
|
63 | 73 |
|
64 |
| - const { result } = await harness.executeOnce(); |
65 |
| - expect(result?.success).toBeTrue(); |
66 |
| - harness.expectFile('dist/polyfills.js').toExist(); |
| 74 | + it('resolves module specifiers in array', async () => { |
| 75 | + harness.useTarget('build', { |
| 76 | + ...BASE_OPTIONS, |
| 77 | + polyfills: ['zone.js', 'zone.js/testing'], |
| 78 | + }); |
| 79 | + |
| 80 | + const { result } = await harness.executeOnce(); |
| 81 | + expect(result?.success).toBeTrue(); |
| 82 | + harness.expectFile('dist/polyfills.js').toExist(); |
| 83 | + }); |
67 | 84 | });
|
68 |
| - }); |
| 85 | + } |
69 | 86 | });
|
0 commit comments