@nx/jest 17.0.5 → 17.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +4 -9
- package/generators.json +2 -2
- package/index.d.ts +1 -1
- package/index.js +1 -2
- package/migrations.json +0 -14
- package/package.json +4 -6
- package/src/generators/configuration/configuration.d.ts +0 -1
- package/src/generators/configuration/configuration.js +7 -42
- package/src/generators/configuration/files/jest.config.ts__tmpl__ +1 -1
- package/src/generators/configuration/files-angular/jest.config.ts__tmpl__ +1 -1
- package/src/generators/configuration/lib/create-files.d.ts +1 -1
- package/src/generators/configuration/lib/create-files.js +1 -2
- package/src/generators/configuration/lib/update-jestconfig.js +1 -6
- package/src/generators/configuration/lib/update-workspace.js +8 -1
- package/src/generators/configuration/schema.d.ts +0 -8
- package/src/generators/configuration/schema.json +1 -1
- package/src/generators/init/init.d.ts +3 -4
- package/src/generators/init/init.js +130 -66
- package/src/generators/init/schema.d.ts +8 -5
- package/src/generators/init/schema.json +20 -13
- package/src/utils/config/find-root-jest-files.js +0 -3
- package/src/utils/config/get-jest-projects.d.ts +1 -16
- package/src/utils/config/get-jest-projects.js +3 -98
- package/src/utils/versions.d.ts +1 -1
- package/src/utils/versions.js +1 -1
- package/plugin.d.ts +0 -1
- package/plugin.js +0 -6
- package/src/generators/configuration/lib/create-jest-config.d.ts +0 -3
- package/src/generators/configuration/lib/create-jest-config.js +0 -102
- package/src/generators/configuration/lib/ensure-dependencies.d.ts +0 -3
- package/src/generators/configuration/lib/ensure-dependencies.js +0 -34
- package/src/generators/configuration/lib/update-vscode-recommended-extensions.d.ts +0 -2
- package/src/generators/configuration/lib/update-vscode-recommended-extensions.js +0 -18
- package/src/migrations/update-17-1-0/move-options-to-target-defaults.d.ts +0 -2
- package/src/migrations/update-17-1-0/move-options-to-target-defaults.js +0 -117
- package/src/plugins/plugin.d.ts +0 -6
- package/src/plugins/plugin.js +0 -130
- package/src/utils/config/is-preset-cjs.d.ts +0 -2
- package/src/utils/config/is-preset-cjs.js +0 -15
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
<p style="text-align: center;">
|
|
2
|
-
<picture>
|
|
3
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-dark.svg">
|
|
4
|
-
<img alt="Nx - Smart Monorepos · Fast CI" src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-light.svg" width="100%">
|
|
5
|
-
</picture>
|
|
6
|
-
</p>
|
|
1
|
+
<p style="text-align: center;"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx.png" width="600" alt="Nx - Smart, Fast and Extensible Build System"></p>
|
|
7
2
|
|
|
8
3
|
<div style="text-align: center;">
|
|
9
4
|
|
|
@@ -20,9 +15,9 @@
|
|
|
20
15
|
|
|
21
16
|
<hr>
|
|
22
17
|
|
|
23
|
-
# Nx: Smart
|
|
18
|
+
# Nx: Smart, Fast and Extensible Build System
|
|
24
19
|
|
|
25
|
-
Nx is a build system with
|
|
20
|
+
Nx is a next generation build system with first class monorepo support and powerful integrations.
|
|
26
21
|
|
|
27
22
|
This package is a [Jest plugin for Nx](https://nx.dev/jest/overview).
|
|
28
23
|
|
|
@@ -64,5 +59,5 @@ npx nx@latest init
|
|
|
64
59
|
- [Blog Posts About Nx](https://blog.nrwl.io/nx/home)
|
|
65
60
|
|
|
66
61
|
<p style="text-align: center;"><a href="https://nx.dev/#learning-materials" target="_blank" rel="noreferrer"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-courses-and-videos.svg"
|
|
67
|
-
width="100%" alt="Nx - Smart
|
|
62
|
+
width="100%" alt="Nx - Smart, Fast and Extensible Build System"></a></p>
|
|
68
63
|
|
package/generators.json
CHANGED
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
"version": "0.1",
|
|
4
4
|
"generators": {
|
|
5
5
|
"init": {
|
|
6
|
-
"factory": "./src/generators/init/init#
|
|
6
|
+
"factory": "./src/generators/init/init#jestInitGenerator",
|
|
7
7
|
"schema": "./src/generators/init/schema.json",
|
|
8
8
|
"description": "Initialize the `@nrwl/jest` plugin.",
|
|
9
9
|
"aliases": ["ng-add"],
|
|
10
10
|
"hidden": true
|
|
11
11
|
},
|
|
12
12
|
"configuration": {
|
|
13
|
-
"factory": "./src/generators/configuration/configuration
|
|
13
|
+
"factory": "./src/generators/configuration/configuration",
|
|
14
14
|
"schema": "./src/generators/configuration/schema.json",
|
|
15
15
|
"description": "Add Jest configuration to a project.",
|
|
16
16
|
"hidden": true
|
package/index.d.ts
CHANGED
|
@@ -5,4 +5,4 @@ export declare const jestProjectGenerator: typeof configurationGenerator;
|
|
|
5
5
|
export { addPropertyToJestConfig, removePropertyFromJestConfig, } from './src/utils/config/update-config';
|
|
6
6
|
export { jestConfigObjectAst } from './src/utils/config/functions';
|
|
7
7
|
export { jestInitGenerator } from './src/generators/init/init';
|
|
8
|
-
export { getJestProjects,
|
|
8
|
+
export { getJestProjects, getNestedJestProjects, } from './src/utils/config/get-jest-projects';
|
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getNestedJestProjects = exports.
|
|
3
|
+
exports.getNestedJestProjects = exports.getJestProjects = exports.jestInitGenerator = exports.jestConfigObjectAst = exports.removePropertyFromJestConfig = exports.addPropertyToJestConfig = exports.jestProjectGenerator = exports.configurationGenerator = void 0;
|
|
4
4
|
const configuration_1 = require("./src/generators/configuration/configuration");
|
|
5
5
|
Object.defineProperty(exports, "configurationGenerator", { enumerable: true, get: function () { return configuration_1.configurationGenerator; } });
|
|
6
6
|
// Exported for backwards compatibility in case a plugin is using the old name.
|
|
@@ -15,5 +15,4 @@ var init_1 = require("./src/generators/init/init");
|
|
|
15
15
|
Object.defineProperty(exports, "jestInitGenerator", { enumerable: true, get: function () { return init_1.jestInitGenerator; } });
|
|
16
16
|
var get_jest_projects_1 = require("./src/utils/config/get-jest-projects");
|
|
17
17
|
Object.defineProperty(exports, "getJestProjects", { enumerable: true, get: function () { return get_jest_projects_1.getJestProjects; } });
|
|
18
|
-
Object.defineProperty(exports, "getJestProjectsAsync", { enumerable: true, get: function () { return get_jest_projects_1.getJestProjectsAsync; } });
|
|
19
18
|
Object.defineProperty(exports, "getNestedJestProjects", { enumerable: true, get: function () { return get_jest_projects_1.getNestedJestProjects; } });
|
package/migrations.json
CHANGED
|
@@ -29,11 +29,6 @@
|
|
|
29
29
|
"version": "16.5.0-beta.2",
|
|
30
30
|
"description": "Add test-setup.ts to ignored files in production input",
|
|
31
31
|
"implementation": "./src/migrations/update-16-5-0/add-test-setup-to-inputs-ignore"
|
|
32
|
-
},
|
|
33
|
-
"move-options-to-target-defaults": {
|
|
34
|
-
"version": "17.1.0-beta.2",
|
|
35
|
-
"description": "Move jest executor options to nx.json targetDefaults",
|
|
36
|
-
"implementation": "./src/migrations/update-17-1-0/move-options-to-target-defaults"
|
|
37
32
|
}
|
|
38
33
|
},
|
|
39
34
|
"packageJsonUpdates": {
|
|
@@ -91,15 +86,6 @@
|
|
|
91
86
|
"alwaysAddToPackageJson": false
|
|
92
87
|
}
|
|
93
88
|
}
|
|
94
|
-
},
|
|
95
|
-
"17.2.0": {
|
|
96
|
-
"version": "17.2.0-beta.2",
|
|
97
|
-
"packages": {
|
|
98
|
-
"@types/node": {
|
|
99
|
-
"version": "18.16.9",
|
|
100
|
-
"alwaysAddToPackageJson": false
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
89
|
}
|
|
104
90
|
}
|
|
105
91
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/jest",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "v17.0.6",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The Nx Plugin for Jest contains executors and generators allowing your workspace to use the powerful Jest testing capabilities.",
|
|
6
6
|
"repository": {
|
|
@@ -36,19 +36,17 @@
|
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@jest/reporters": "^29.4.1",
|
|
38
38
|
"@jest/test-result": "^29.4.1",
|
|
39
|
-
"@nx/devkit": "17.0.5",
|
|
40
|
-
"@nx/js": "17.0.5",
|
|
41
39
|
"@phenomnomnominal/tsquery": "~5.0.1",
|
|
42
40
|
"chalk": "^4.1.0",
|
|
43
41
|
"identity-obj-proxy": "3.0.0",
|
|
44
42
|
"jest-config": "^29.4.1",
|
|
45
43
|
"jest-resolve": "^29.4.1",
|
|
46
44
|
"jest-util": "^29.4.1",
|
|
47
|
-
"minimatch": "9.0.3",
|
|
48
45
|
"resolve.exports": "1.1.0",
|
|
49
46
|
"tslib": "^2.3.0",
|
|
50
|
-
"
|
|
51
|
-
"@
|
|
47
|
+
"@nx/devkit": "v17.0.6",
|
|
48
|
+
"@nx/js": "v17.0.6",
|
|
49
|
+
"@nrwl/jest": "v17.0.6"
|
|
52
50
|
},
|
|
53
51
|
"publishConfig": {
|
|
54
52
|
"access": "public"
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { JestProjectSchema } from './schema';
|
|
2
2
|
import { Tree, GeneratorCallback } from '@nx/devkit';
|
|
3
3
|
export declare function configurationGenerator(tree: Tree, schema: JestProjectSchema): Promise<GeneratorCallback>;
|
|
4
|
-
export declare function configurationGeneratorInternal(tree: Tree, schema: JestProjectSchema): Promise<GeneratorCallback>;
|
|
5
4
|
export default configurationGenerator;
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.configurationGenerator = void 0;
|
|
4
4
|
const init_1 = require("../init/init");
|
|
5
5
|
const check_for_test_target_1 = require("./lib/check-for-test-target");
|
|
6
6
|
const create_files_1 = require("./lib/create-files");
|
|
7
|
-
const create_jest_config_1 = require("./lib/create-jest-config");
|
|
8
|
-
const ensure_dependencies_1 = require("./lib/ensure-dependencies");
|
|
9
7
|
const update_tsconfig_1 = require("./lib/update-tsconfig");
|
|
10
|
-
const update_vscode_recommended_extensions_1 = require("./lib/update-vscode-recommended-extensions");
|
|
11
8
|
const update_workspace_1 = require("./lib/update-workspace");
|
|
12
9
|
const devkit_1 = require("@nx/devkit");
|
|
13
|
-
const js_1 = require("@nx/js");
|
|
14
|
-
const is_preset_cjs_1 = require("../../utils/config/is-preset-cjs");
|
|
15
10
|
const schemaDefaults = {
|
|
16
11
|
setupFile: 'none',
|
|
17
12
|
babelJest: false,
|
|
@@ -24,11 +19,6 @@ function normalizeOptions(tree, options) {
|
|
|
24
19
|
if (!options.testEnvironment) {
|
|
25
20
|
options.testEnvironment = 'jsdom';
|
|
26
21
|
}
|
|
27
|
-
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
28
|
-
const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' &&
|
|
29
|
-
nxJson.useInferencePlugins !== false;
|
|
30
|
-
options.addPlugin ??= addPlugin;
|
|
31
|
-
options.targetName ??= 'test';
|
|
32
22
|
if (!options.hasOwnProperty('supportTsx')) {
|
|
33
23
|
options.supportTsx = false;
|
|
34
24
|
}
|
|
@@ -49,42 +39,17 @@ function normalizeOptions(tree, options) {
|
|
|
49
39
|
rootProject: project.root === '.' || project.root === '',
|
|
50
40
|
};
|
|
51
41
|
}
|
|
52
|
-
function configurationGenerator(tree, schema) {
|
|
53
|
-
return configurationGeneratorInternal(tree, { addPlugin: false, ...schema });
|
|
54
|
-
}
|
|
55
|
-
exports.configurationGenerator = configurationGenerator;
|
|
56
|
-
async function configurationGeneratorInternal(tree, schema) {
|
|
42
|
+
async function configurationGenerator(tree, schema) {
|
|
57
43
|
const options = normalizeOptions(tree, schema);
|
|
58
|
-
const
|
|
59
|
-
tasks.push(await (0, js_1.initGenerator)(tree, { ...schema, skipFormat: true }));
|
|
60
|
-
tasks.push(await (0, init_1.jestInitGenerator)(tree, { ...options, skipFormat: true }));
|
|
61
|
-
if (!schema.skipPackageJson) {
|
|
62
|
-
tasks.push((0, ensure_dependencies_1.ensureDependencies)(tree, options));
|
|
63
|
-
}
|
|
64
|
-
const presetExt = (0, is_preset_cjs_1.isPresetCjs)(tree) ? 'cjs' : 'js';
|
|
65
|
-
await (0, create_jest_config_1.createJestConfig)(tree, options, presetExt);
|
|
44
|
+
const installTask = await (0, init_1.default)(tree, options);
|
|
66
45
|
(0, check_for_test_target_1.checkForTestTarget)(tree, options);
|
|
67
|
-
(0, create_files_1.createFiles)(tree, options
|
|
46
|
+
(0, create_files_1.createFiles)(tree, options);
|
|
68
47
|
(0, update_tsconfig_1.updateTsConfig)(tree, options);
|
|
69
|
-
(0,
|
|
70
|
-
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
71
|
-
const hasPlugin = nxJson.plugins?.some((p) => {
|
|
72
|
-
if (typeof p === 'string') {
|
|
73
|
-
return p === '@nx/jest/plugin' && options.targetName === 'test';
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
return (p.plugin === '@nx/jest/plugin' &&
|
|
77
|
-
(p.options?.targetName ?? 'test') ===
|
|
78
|
-
options.targetName);
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
if (!hasPlugin || options.addExplicitTargets) {
|
|
82
|
-
(0, update_workspace_1.updateWorkspace)(tree, options);
|
|
83
|
-
}
|
|
48
|
+
(0, update_workspace_1.updateWorkspace)(tree, options);
|
|
84
49
|
if (!schema.skipFormat) {
|
|
85
50
|
await (0, devkit_1.formatFiles)(tree);
|
|
86
51
|
}
|
|
87
|
-
return
|
|
52
|
+
return installTask;
|
|
88
53
|
}
|
|
89
|
-
exports.
|
|
54
|
+
exports.configurationGenerator = configurationGenerator;
|
|
90
55
|
exports.default = configurationGenerator;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable */
|
|
2
2
|
<% if(js){ %>module.exports =<% } else{ %>export default<% } %> {
|
|
3
3
|
displayName: '<%= project %>',
|
|
4
|
-
preset: '<%= offsetFromRoot %>jest.preset
|
|
4
|
+
preset: '<%= offsetFromRoot %>jest.preset.js',<% if(setupFile !== 'none') { %>
|
|
5
5
|
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],<% } %><% if(testEnvironment) { %>
|
|
6
6
|
testEnvironment: '<%= testEnvironment %>',<% } %><% if(skipSerializers){ %>
|
|
7
7
|
transform: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable */
|
|
2
2
|
<% if(js){ %>module.exports =<% } else{ %>export default<% } %> {
|
|
3
3
|
displayName: '<%= project %>',
|
|
4
|
-
preset: '<%= offsetFromRoot %>jest.preset
|
|
4
|
+
preset: '<%= offsetFromRoot %>jest.preset.js',
|
|
5
5
|
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],<% if(testEnvironment) { %>
|
|
6
6
|
testEnvironment: '<%= testEnvironment %>',<% } %>
|
|
7
7
|
coverageDirectory: '<%= offsetFromRoot %>coverage/<%= projectRoot %>',
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Tree } from '@nx/devkit';
|
|
2
2
|
import { NormalizedJestProjectSchema } from '../schema';
|
|
3
|
-
export declare function createFiles(tree: Tree, options: NormalizedJestProjectSchema
|
|
3
|
+
export declare function createFiles(tree: Tree, options: NormalizedJestProjectSchema): void;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createFiles = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const path_1 = require("path");
|
|
6
|
-
function createFiles(tree, options
|
|
6
|
+
function createFiles(tree, options) {
|
|
7
7
|
const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
8
8
|
const filesFolder = options.setupFile === 'angular' ? '../files-angular' : '../files';
|
|
9
9
|
let transformer;
|
|
@@ -35,7 +35,6 @@ function createFiles(tree, options, presetExt) {
|
|
|
35
35
|
rootProject: options.rootProject,
|
|
36
36
|
projectRoot: options.rootProject ? options.project : projectConfig.root,
|
|
37
37
|
offsetFromRoot: (0, devkit_1.offsetFromRoot)(projectConfig.root),
|
|
38
|
-
presetExt,
|
|
39
38
|
});
|
|
40
39
|
if (options.setupFile === 'none') {
|
|
41
40
|
tree.delete((0, path_1.join)(projectConfig.root, './src/test-setup.ts'));
|
|
@@ -6,12 +6,7 @@ const update_config_1 = require("../../../utils/config/update-config");
|
|
|
6
6
|
const devkit_1 = require("@nx/devkit");
|
|
7
7
|
function isUsingUtilityFunction(host) {
|
|
8
8
|
const rootConfig = (0, find_root_jest_files_1.findRootJestConfig)(host);
|
|
9
|
-
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
const rootConfigContent = host.read(rootConfig, 'utf-8');
|
|
13
|
-
return (rootConfigContent.includes('getJestProjects()') ||
|
|
14
|
-
rootConfigContent.includes('getJestProjectsAsync()'));
|
|
9
|
+
return (rootConfig && host.read(rootConfig).toString().includes('getJestProjects()'));
|
|
15
10
|
}
|
|
16
11
|
function updateJestConfig(host, options) {
|
|
17
12
|
if (isUsingUtilityFunction(host)) {
|
|
@@ -7,7 +7,7 @@ function updateWorkspace(tree, options) {
|
|
|
7
7
|
if (!projectConfig.targets) {
|
|
8
8
|
projectConfig.targets = {};
|
|
9
9
|
}
|
|
10
|
-
projectConfig.targets
|
|
10
|
+
projectConfig.targets.test = {
|
|
11
11
|
executor: '@nx/jest:jest',
|
|
12
12
|
outputs: [
|
|
13
13
|
options.rootProject
|
|
@@ -16,6 +16,13 @@ function updateWorkspace(tree, options) {
|
|
|
16
16
|
],
|
|
17
17
|
options: {
|
|
18
18
|
jestConfig: (0, devkit_1.joinPathFragments)((0, devkit_1.normalizePath)(projectConfig.root), `jest.config.${options.js ? 'js' : 'ts'}`),
|
|
19
|
+
passWithNoTests: true,
|
|
20
|
+
},
|
|
21
|
+
configurations: {
|
|
22
|
+
ci: {
|
|
23
|
+
ci: true,
|
|
24
|
+
codeCoverage: true,
|
|
25
|
+
},
|
|
19
26
|
},
|
|
20
27
|
};
|
|
21
28
|
(0, devkit_1.updateProjectConfiguration)(tree, options.project, projectConfig);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export interface JestProjectSchema {
|
|
2
2
|
project: string;
|
|
3
|
-
targetName?: string;
|
|
4
3
|
supportTsx?: boolean;
|
|
5
4
|
/**
|
|
6
5
|
* @deprecated use setupFile instead
|
|
@@ -14,16 +13,9 @@ export interface JestProjectSchema {
|
|
|
14
13
|
*/
|
|
15
14
|
babelJest?: boolean;
|
|
16
15
|
skipFormat?: boolean;
|
|
17
|
-
|
|
18
|
-
addPlugin?: boolean;
|
|
19
16
|
compiler?: 'tsc' | 'babel' | 'swc';
|
|
20
17
|
skipPackageJson?: boolean;
|
|
21
18
|
js?: boolean;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* @internal
|
|
25
|
-
*/
|
|
26
|
-
addExplicitTargets?: boolean;
|
|
27
19
|
}
|
|
28
20
|
|
|
29
21
|
export type NormalizedJestProjectSchema = JestProjectSchema & {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
export declare function jestInitGenerator(tree: Tree,
|
|
4
|
-
export declare function jestInitGeneratorInternal(tree: Tree, options: JestInitSchema): Promise<GeneratorCallback>;
|
|
1
|
+
import { GeneratorCallback, Tree } from '@nx/devkit';
|
|
2
|
+
import { JestInitSchema } from './schema';
|
|
3
|
+
export declare function jestInitGenerator(tree: Tree, schema: JestInitSchema): Promise<GeneratorCallback>;
|
|
5
4
|
export default jestInitGenerator;
|
|
@@ -1,27 +1,79 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.jestInitGenerator = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const js_1 = require("@nx/js");
|
|
6
|
+
const find_root_jest_files_1 = require("../../utils/config/find-root-jest-files");
|
|
7
7
|
const versions_1 = require("../../utils/versions");
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
8
|
+
const schemaDefaults = {
|
|
9
|
+
compiler: 'tsc',
|
|
10
|
+
js: false,
|
|
11
|
+
rootProject: false,
|
|
12
|
+
testEnvironment: 'jsdom',
|
|
13
|
+
};
|
|
14
|
+
function generateGlobalConfig(tree, isJS) {
|
|
15
|
+
const contents = isJS
|
|
16
|
+
? (0, devkit_1.stripIndents) `
|
|
17
|
+
const { getJestProjects } = require('@nx/jest');
|
|
18
|
+
|
|
19
|
+
module.exports = {
|
|
20
|
+
projects: getJestProjects()
|
|
21
|
+
};`
|
|
22
|
+
: (0, devkit_1.stripIndents) `
|
|
23
|
+
import { getJestProjects } from '@nx/jest';
|
|
24
|
+
|
|
25
|
+
export default {
|
|
26
|
+
projects: getJestProjects()
|
|
27
|
+
};`;
|
|
28
|
+
tree.write(`jest.config.${isJS ? 'js' : 'ts'}`, contents);
|
|
29
|
+
}
|
|
30
|
+
function createJestConfig(tree, options) {
|
|
31
|
+
if (!tree.exists('jest.preset.js')) {
|
|
32
|
+
// preset is always js file.
|
|
33
|
+
tree.write(`jest.preset.js`, `
|
|
34
|
+
const nxPreset = require('@nx/jest/preset').default;
|
|
35
|
+
|
|
36
|
+
module.exports = { ...nxPreset }`);
|
|
37
|
+
addTestInputs(tree);
|
|
38
|
+
}
|
|
39
|
+
if (options.rootProject) {
|
|
40
|
+
// we don't want any config to be made because the `configurationGenerator` will do it.
|
|
41
|
+
// will copy the template config file
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const rootJestPath = (0, find_root_jest_files_1.findRootJestConfig)(tree);
|
|
45
|
+
if (!rootJestPath) {
|
|
46
|
+
// if there's not root jest config, we will create one and return
|
|
47
|
+
// this can happen when:
|
|
48
|
+
// - root jest config was renamed => in which case there is migration needed
|
|
49
|
+
// - root project didn't have jest setup => again, no migration is needed
|
|
50
|
+
generateGlobalConfig(tree, options.js);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (tree.exists(rootJestPath)) {
|
|
54
|
+
// moving from root project config to monorepo-style config
|
|
55
|
+
const projects = (0, devkit_1.getProjects)(tree);
|
|
56
|
+
const projectNames = Array.from(projects.keys());
|
|
57
|
+
const rootProject = projectNames.find((projectName) => projects.get(projectName)?.root === '.');
|
|
58
|
+
// root project might have been removed,
|
|
59
|
+
// if it's missing there's nothing to migrate
|
|
60
|
+
if (rootProject) {
|
|
61
|
+
const rootProjectConfig = projects.get(rootProject);
|
|
62
|
+
const jestTarget = Object.values(rootProjectConfig.targets || {}).find((t) => t?.executor === '@nx/jest:jest' || t?.executor === '@nrwl/jest:jest');
|
|
63
|
+
const isProjectConfig = jestTarget?.options?.jestConfig === rootJestPath;
|
|
64
|
+
// if root project doesn't have jest target, there's nothing to migrate
|
|
65
|
+
if (isProjectConfig) {
|
|
66
|
+
const jestProjectConfig = `jest.config.${rootProjectConfig.projectType === 'application' ? 'app' : 'lib'}.${options.js ? 'js' : 'ts'}`;
|
|
67
|
+
tree.rename(rootJestPath, jestProjectConfig);
|
|
68
|
+
jestTarget.options.jestConfig = jestProjectConfig;
|
|
69
|
+
(0, devkit_1.updateProjectConfiguration)(tree, rootProject, rootProjectConfig);
|
|
70
|
+
}
|
|
71
|
+
// generate new global config as it was move to project config or is missing
|
|
72
|
+
generateGlobalConfig(tree, options.js);
|
|
73
|
+
}
|
|
21
74
|
}
|
|
22
|
-
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
23
75
|
}
|
|
24
|
-
function
|
|
76
|
+
function addTestInputs(tree) {
|
|
25
77
|
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
26
78
|
const productionFileSet = nxJson.namedInputs?.production;
|
|
27
79
|
if (productionFileSet) {
|
|
@@ -39,68 +91,80 @@ function updateProductionFileSet(tree, presetExt) {
|
|
|
39
91
|
// Dedupe and set
|
|
40
92
|
nxJson.namedInputs.production = Array.from(new Set(productionFileSet));
|
|
41
93
|
}
|
|
42
|
-
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
43
|
-
}
|
|
44
|
-
function addJestTargetDefaults(tree, presetEnv) {
|
|
45
|
-
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
46
|
-
nxJson.targetDefaults ??= {};
|
|
47
|
-
nxJson.targetDefaults['@nx/jest:jest'] ??= {};
|
|
48
|
-
const productionFileSet = nxJson.namedInputs?.production;
|
|
49
|
-
nxJson.targetDefaults['@nx/jest:jest'].cache ??= true;
|
|
50
94
|
// Test targets depend on all their project's sources + production sources of dependencies
|
|
51
|
-
nxJson.targetDefaults
|
|
95
|
+
nxJson.targetDefaults ??= {};
|
|
96
|
+
nxJson.targetDefaults.test ??= {};
|
|
97
|
+
nxJson.targetDefaults.test.inputs ??= [
|
|
52
98
|
'default',
|
|
53
99
|
productionFileSet ? '^production' : '^default',
|
|
54
|
-
`{workspaceRoot}/jest.preset.${presetEnv}`,
|
|
55
100
|
];
|
|
56
|
-
nxJson.targetDefaults
|
|
57
|
-
passWithNoTests: true,
|
|
58
|
-
};
|
|
59
|
-
nxJson.targetDefaults['@nx/jest:jest'].configurations ??= {
|
|
60
|
-
ci: {
|
|
61
|
-
ci: true,
|
|
62
|
-
codeCoverage: true,
|
|
63
|
-
},
|
|
64
|
-
};
|
|
101
|
+
nxJson.targetDefaults.test.inputs.push('{workspaceRoot}/jest.preset.js');
|
|
65
102
|
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
66
103
|
}
|
|
67
104
|
function updateDependencies(tree, options) {
|
|
68
|
-
|
|
105
|
+
const dependencies = {
|
|
106
|
+
tslib: versions_1.tslibVersion,
|
|
107
|
+
};
|
|
108
|
+
const devDeps = {
|
|
69
109
|
'@nx/jest': versions_1.nxVersion,
|
|
70
110
|
jest: versions_1.jestVersion,
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
111
|
+
// because the default jest-preset uses ts-jest,
|
|
112
|
+
// jest will throw an error if it's not installed
|
|
113
|
+
// even if not using it in overriding transformers
|
|
114
|
+
'ts-jest': versions_1.tsJestVersion,
|
|
115
|
+
};
|
|
116
|
+
if (options.testEnvironment !== 'none') {
|
|
117
|
+
devDeps[`jest-environment-${options.testEnvironment}`] = versions_1.jestVersion;
|
|
118
|
+
}
|
|
119
|
+
if (!options.js) {
|
|
120
|
+
devDeps['ts-node'] = versions_1.tsNodeVersion;
|
|
121
|
+
devDeps['@types/jest'] = versions_1.jestTypesVersion;
|
|
122
|
+
devDeps['@types/node'] = versions_1.typesNodeVersion;
|
|
123
|
+
}
|
|
124
|
+
if (options.compiler === 'babel' || options.babelJest) {
|
|
125
|
+
devDeps['babel-jest'] = versions_1.babelJestVersion;
|
|
126
|
+
// in some cases @nx/js will not already be present i.e. node only projects
|
|
127
|
+
devDeps['@nx/js'] = versions_1.nxVersion;
|
|
128
|
+
}
|
|
129
|
+
else if (options.compiler === 'swc') {
|
|
130
|
+
devDeps['@swc/jest'] = versions_1.swcJestVersion;
|
|
131
|
+
}
|
|
132
|
+
return (0, devkit_1.addDependenciesToPackageJson)(tree, dependencies, devDeps);
|
|
75
133
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' &&
|
|
80
|
-
nxJson.useInferencePlugins !== false;
|
|
81
|
-
options.addPlugin ??= addPluginDefault;
|
|
82
|
-
const presetExt = (0, is_preset_cjs_1.isPresetCjs)(tree) ? 'cjs' : 'js';
|
|
83
|
-
if (!tree.exists('jest.preset.js') && !tree.exists('jest.preset.cjs')) {
|
|
84
|
-
updateProductionFileSet(tree, presetExt);
|
|
85
|
-
if (options.addPlugin) {
|
|
86
|
-
addPlugin(tree);
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
addJestTargetDefaults(tree, presetExt);
|
|
90
|
-
}
|
|
134
|
+
function updateExtensions(host) {
|
|
135
|
+
if (!host.exists('.vscode/extensions.json')) {
|
|
136
|
+
return;
|
|
91
137
|
}
|
|
138
|
+
(0, devkit_1.updateJson)(host, '.vscode/extensions.json', (json) => {
|
|
139
|
+
json.recommendations = json.recommendations || [];
|
|
140
|
+
const extension = 'firsttris.vscode-jest-runner';
|
|
141
|
+
if (!json.recommendations.includes(extension)) {
|
|
142
|
+
json.recommendations.push(extension);
|
|
143
|
+
}
|
|
144
|
+
return json;
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
async function jestInitGenerator(tree, schema) {
|
|
148
|
+
const options = normalizeOptions(schema);
|
|
92
149
|
const tasks = [];
|
|
150
|
+
tasks.push(await (0, js_1.initGenerator)(tree, {
|
|
151
|
+
...schema,
|
|
152
|
+
skipFormat: true,
|
|
153
|
+
}));
|
|
154
|
+
createJestConfig(tree, options);
|
|
93
155
|
if (!options.skipPackageJson) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if (options.updatePackageScripts) {
|
|
98
|
-
await (0, update_package_scripts_1.updatePackageScripts)(tree, plugin_1.createNodes);
|
|
99
|
-
}
|
|
100
|
-
if (!options.skipFormat) {
|
|
101
|
-
await (0, devkit_1.formatFiles)(tree);
|
|
156
|
+
(0, devkit_1.removeDependenciesFromPackageJson)(tree, ['@nx/jest'], []);
|
|
157
|
+
const installTask = updateDependencies(tree, options);
|
|
158
|
+
tasks.push(installTask);
|
|
102
159
|
}
|
|
160
|
+
updateExtensions(tree);
|
|
103
161
|
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
104
162
|
}
|
|
105
|
-
exports.
|
|
163
|
+
exports.jestInitGenerator = jestInitGenerator;
|
|
164
|
+
function normalizeOptions(options) {
|
|
165
|
+
return {
|
|
166
|
+
...schemaDefaults,
|
|
167
|
+
...options,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
106
170
|
exports.default = jestInitGenerator;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
export interface JestInitSchema {
|
|
2
|
-
|
|
2
|
+
compiler?: 'tsc' | 'babel' | 'swc';
|
|
3
|
+
js?: boolean;
|
|
3
4
|
skipPackageJson?: boolean;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
testEnvironment?: 'node' | 'jsdom' | 'none';
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated
|
|
8
|
+
*/
|
|
9
|
+
babelJest?: boolean;
|
|
10
|
+
rootProject?: boolean;
|
|
8
11
|
}
|