|
| 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 | +describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => { |
| 12 | + describe('Option: "tsConfig"', () => { |
| 13 | + it('uses a provided TypeScript configuration file', async () => { |
| 14 | + // Setup a TS file that uses ES2015+ const and then target ES5. |
| 15 | + // The const usage should be downleveled in the output if the TS config is used. |
| 16 | + await harness.writeFile('src/main.ts', 'const a = 5; console.log(a);'); |
| 17 | + await harness.writeFile( |
| 18 | + 'src/tsconfig.option.json', |
| 19 | + JSON.stringify({ |
| 20 | + compilerOptions: { |
| 21 | + target: 'es5', |
| 22 | + }, |
| 23 | + files: ['main.ts'], |
| 24 | + }), |
| 25 | + ); |
| 26 | + |
| 27 | + harness.useTarget('build', { |
| 28 | + ...BASE_OPTIONS, |
| 29 | + tsConfig: 'src/tsconfig.option.json', |
| 30 | + }); |
| 31 | + |
| 32 | + const { result } = await harness.executeOnce(); |
| 33 | + |
| 34 | + expect(result?.success).toBe(true); |
| 35 | + |
| 36 | + harness.expectFile('dist/main.js').content.not.toContain('const'); |
| 37 | + }); |
| 38 | + |
| 39 | + it('throws an exception when TypeScript Configuration file does not exist', async () => { |
| 40 | + harness.useTarget('build', { |
| 41 | + ...BASE_OPTIONS, |
| 42 | + tsConfig: 'src/missing.json', |
| 43 | + }); |
| 44 | + |
| 45 | + const { result, error } = await harness.executeOnce({ outputLogsOnException: false }); |
| 46 | + |
| 47 | + expect(result).toBeUndefined(); |
| 48 | + expect(error).toEqual( |
| 49 | + jasmine.objectContaining({ |
| 50 | + message: jasmine.stringMatching('no such file or directory'), |
| 51 | + }), |
| 52 | + ); |
| 53 | + }); |
| 54 | + }); |
| 55 | +}); |
0 commit comments