-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Expand file tree
/
Copy pathtest-sourcemap.ts
More file actions
54 lines (50 loc) · 1.7 KB
/
test-sourcemap.ts
File metadata and controls
54 lines (50 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import assert from 'node:assert';
import { writeFile } from '../../utils/fs';
import { ng } from '../../utils/process';
import { assertIsError } from '../../utils/utils';
import { updateJsonFile } from '../../utils/project';
import { getGlobalVariable } from '../../utils/env';
export default async function () {
const isWebpack = !getGlobalVariable('argv')['esbuild'];
await writeFile(
'src/app/app.spec.ts',
`
it('should fail', () => {
expect(undefined).toBeTruthy();
});
`,
);
// when sourcemaps are 'on' the stacktrace will point to the spec.ts file.
await updateJsonFile('angular.json', (configJson) => {
const appArchitect = configJson.projects['test-project'].architect;
if (isWebpack) {
appArchitect['test'].options.sourceMap = true;
} else {
appArchitect['build'].configurations.development.sourceMap = true;
}
});
try {
await ng('test', '--no-watch');
throw new Error('ng test should have failed.');
} catch (error) {
assertIsError(error);
assert.match(error.message, /\(src\/app\/app\.spec\.ts:3:27/);
assert.doesNotMatch(error.message, /webpack/);
}
// when sourcemaps are 'off' the stacktrace won't point to the spec.ts file.
await updateJsonFile('angular.json', (configJson) => {
const appArchitect = configJson.projects['test-project'].architect;
if (isWebpack) {
appArchitect['test'].options.sourceMap = false;
} else {
appArchitect['build'].configurations.development.sourceMap = false;
}
});
try {
await ng('test', '--no-watch');
throw new Error('ng test should have failed.');
} catch (error) {
assertIsError(error);
assert.match(error.message, /main\.js/);
}
}