UNPKG

1.77 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const tslib_1 = require("tslib");
4const devkit_1 = require("@nrwl/devkit");
5const path_1 = require("path");
6const executor_options_utils_1 = require("@nrwl/workspace/src/utilities/executor-options-utils");
7const update_config_1 = require("../../utils/config/update-config");
8function updateJestConfig(tree) {
9 (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nrwl/jest:jest', (options, project) => {
10 if (!options.jestConfig) {
11 return;
12 }
13 const jestConfigPath = options.jestConfig;
14 const jestConfig = require((0, path_1.join)(tree.root, jestConfigPath));
15 const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, project);
16 const testEnvironment = jestConfig.testEnvironment;
17 if (testEnvironment || !checkIfNodeProject(projectConfig)) {
18 return;
19 }
20 try {
21 (0, update_config_1.addPropertyToJestConfig)(tree, jestConfigPath, 'testEnvironment', 'node');
22 }
23 catch (_a) {
24 devkit_1.logger.error((0, devkit_1.stripIndents) `Unable to update jest.config.js for project ${project}.`);
25 }
26 });
27}
28function update(tree) {
29 return tslib_1.__awaiter(this, void 0, void 0, function* () {
30 updateJestConfig(tree);
31 yield (0, devkit_1.formatFiles)(tree);
32 });
33}
34exports.default = update;
35function checkIfNodeProject(config) {
36 return Object.entries(config.targets).some(([targetName, targetConfig]) => { var _a, _b; return (_b = (_a = targetConfig.executor) === null || _a === void 0 ? void 0 : _a.includes) === null || _b === void 0 ? void 0 : _b.call(_a, 'node'); });
37}
38//# sourceMappingURL=add-test-environment-for-node.js.map
\No newline at end of file