|
1 | 1 | import { writeFile } from '../../utils/fs';
|
2 |
| -import { execAndWaitForOutputToMatch, killAllProcesses } from '../../utils/process'; |
| 2 | +import { ng } from '../../utils/process'; |
3 | 3 | import { updateJsonFile } from '../../utils/project';
|
4 | 4 |
|
5 | 5 | export default async function () {
|
| 6 | + await writeFile('src/app/app.component.spec.ts', ` |
| 7 | + it('show fail', () => { |
| 8 | + expect(undefined).toBeTruthy(); |
| 9 | + }); |
| 10 | + `); |
| 11 | + |
6 | 12 | await updateJsonFile('angular.json', configJson => {
|
7 | 13 | const appArchitect = configJson.projects['test-project'].architect;
|
8 | 14 | appArchitect.test.options.sourceMap = {
|
9 | 15 | scripts: true,
|
10 | 16 | };
|
11 | 17 | });
|
12 | 18 |
|
13 |
| - await writeFile('src/app/app.component.spec.ts', ` |
14 |
| - it('show fail', () => { |
15 |
| - expect(undefined).toBeTruthy(); |
16 |
| - }); |
17 |
| - `); |
| 19 | + // when sourcemaps are 'on' the stacktrace will point to the spec.ts file. |
| 20 | + try { |
| 21 | + await ng('test', '--watch', 'false'); |
| 22 | + throw new Error('ng test should have failed.'); |
| 23 | + } catch (error) { |
| 24 | + if (!error.message.includes('app.component.spec.ts')) { |
| 25 | + throw error; |
| 26 | + }; |
| 27 | + } |
18 | 28 |
|
19 |
| - // when sourcemaps are not working the stacktrace won't point to the spec.ts file. |
| 29 | + await updateJsonFile('angular.json', configJson => { |
| 30 | + const appArchitect = configJson.projects['test-project'].architect; |
| 31 | + appArchitect.test.options.sourceMap = true; |
| 32 | + }); |
| 33 | + |
| 34 | + // when sourcemaps are 'on' the stacktrace will point to the spec.ts file. |
20 | 35 | try {
|
21 |
| - await execAndWaitForOutputToMatch( |
22 |
| - 'ng', |
23 |
| - ['test', '--watch', 'false'], |
24 |
| - /app\.component\.spec\.ts/, |
25 |
| - ); |
26 |
| - } finally { |
27 |
| - killAllProcesses(); |
| 36 | + await ng('test', '--watch', 'false'); |
| 37 | + throw new Error('ng test should have failed.'); |
| 38 | + } catch (error) { |
| 39 | + if (!error.message.includes('app.component.spec.ts')) { |
| 40 | + throw error; |
| 41 | + }; |
| 42 | + } |
| 43 | + |
| 44 | + await updateJsonFile('angular.json', configJson => { |
| 45 | + const appArchitect = configJson.projects['test-project'].architect; |
| 46 | + appArchitect.test.options.sourceMap = false; |
| 47 | + }); |
| 48 | + |
| 49 | + // when sourcemaps are 'off' the stacktrace won't point to the spec.ts file. |
| 50 | + try { |
| 51 | + await ng('test', '--watch', 'false'); |
| 52 | + throw new Error('ng test should have failed.'); |
| 53 | + } catch (error) { |
| 54 | + if (!error.message.includes('main.js')) { |
| 55 | + throw error; |
| 56 | + }; |
28 | 57 | }
|
29 | 58 | }
|
0 commit comments