forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.ts
More file actions
29 lines (26 loc) · 953 Bytes
/
jest.ts
File metadata and controls
29 lines (26 loc) · 953 Bytes
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
import { silentNpm } from './process';
import { updateJsonFile } from './project';
/** Updates the `test` builder in the current workspace to use Jest with the given options. */
export async function applyJestBuilder(
options: {} = {
polyfills: [],
tsConfig: 'tsconfig.spec.json',
},
): Promise<void> {
await silentNpm('install', 'jest@30.2.0', 'jest-environment-jsdom@30.2.0', '--save-dev');
await updateJsonFile('angular.json', (json) => {
const projects = Object.values(json['projects']);
if (projects.length !== 1) {
throw new Error(
`Expected exactly one project but found ${projects.length} projects named ${Object.keys(
json['projects'],
).join(', ')}`,
);
}
const project = projects[0]! as any;
// Update to Jest builder.
const test = project['architect']['test'];
test['builder'] = '@angular-devkit/build-angular:jest';
test['options'] = options;
});
}