-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
update-jest-config.ts
34 lines (30 loc) · 1.07 KB
/
update-jest-config.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
import { updateJestConfigContent } from '../../../utils/jest-utils';
import { NormalizedSchema } from '../schema';
import { offsetFromRoot, Tree, updateJson } from '@nrwl/devkit';
export function updateSpecConfig(host: Tree, options: NormalizedSchema) {
if (options.unitTestRunner === 'none') {
return;
}
updateJson(host, `${options.appProjectRoot}/tsconfig.spec.json`, (json) => {
const offset = offsetFromRoot(options.appProjectRoot);
json.files = [
`${offset}node_modules/@nrwl/react/typings/cssmodule.d.ts`,
`${offset}node_modules/@nrwl/react/typings/image.d.ts`,
];
if (options.style === 'styled-jsx') {
json.files.unshift(
`${offset}node_modules/@nrwl/react/typings/styled-jsx.d.ts`
);
}
return json;
});
if (options.unitTestRunner !== 'jest') {
return;
}
const configPath = `${options.appProjectRoot}/jest.config.${
options.js ? 'js' : 'ts'
}`;
const originalContent = host.read(configPath, 'utf-8');
const content = updateJestConfigContent(originalContent);
host.write(configPath, content);
}