UNPKG

1.62 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.updateJestConfig = void 0;
4const path = require("path");
5/**
6 * Updates the project name and coverage folder in the jest.config.js if it exists
7 *
8 * (assume relative paths have been updated previously)
9 *
10 * @param schema The options provided to the schematic
11 */
12function updateJestConfig(tree, schema, project) {
13 const jestConfigPath = path.join(schema.relativeToRootDestination, 'jest.config.ts');
14 if (tree.exists(jestConfigPath)) {
15 const oldContent = tree.read(jestConfigPath, 'utf-8');
16 const findName = new RegExp(`'${schema.projectName}'`, 'g');
17 const findDir = new RegExp(project.root, 'g');
18 const newContent = oldContent
19 .replace(findName, `'${schema.newProjectName}'`)
20 .replace(findDir, schema.relativeToRootDestination);
21 tree.write(jestConfigPath, newContent);
22 }
23 // update root jest.config.ts
24 const rootJestConfigPath = '/jest.config.ts';
25 if (!tree.exists(rootJestConfigPath)) {
26 return;
27 }
28 const findProject = `'<rootDir>/${project.root}'`;
29 const oldRootJestConfigContent = tree.read(rootJestConfigPath, 'utf-8');
30 const usingJestProjects = oldRootJestConfigContent.includes('getJestProjects()');
31 const newRootJestConfigContent = oldRootJestConfigContent.replace(findProject, usingJestProjects ? `` : `'<rootDir>/${schema.relativeToRootDestination}'`);
32 tree.write(rootJestConfigPath, newRootJestConfigContent);
33}
34exports.updateJestConfig = updateJestConfig;
35//# sourceMappingURL=update-jest-config.js.map
\No newline at end of file