-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
add-jest.ts
48 lines (41 loc) · 1.15 KB
/
add-jest.ts
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
import { joinPathFragments, readJson, Tree, updateJson } from '@nrwl/devkit';
import { jestProjectGenerator } from '@nrwl/jest';
import { NormalizedSchema } from './normalize-options';
export async function addJest(host: Tree, options: NormalizedSchema) {
if (options.unitTestRunner !== 'jest') {
return () => {};
}
const jestTask = await jestProjectGenerator(host, {
...options,
project: options.projectName,
supportTsx: true,
skipSerializers: true,
setupFile: 'none',
compiler: 'babel',
});
const tsConfigSpecJson = readJson(
host,
joinPathFragments(options.appProjectRoot, 'tsconfig.spec.json')
);
updateJson(
host,
joinPathFragments(options.appProjectRoot, 'tsconfig.json'),
(json) => {
json.compilerOptions ??= {};
json.compilerOptions.types ??= [];
json.compilerOptions.types.push(
...(tsConfigSpecJson?.compilerOptions?.types ?? [])
);
return json;
}
);
updateJson(
host,
joinPathFragments(options.appProjectRoot, 'tsconfig.spec.json'),
(json) => {
json.compilerOptions.jsx = 'react';
return json;
}
);
return jestTask;
}