@nx/jest 23.0.0-beta.2 → 23.0.0-beta.20
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/{index.d.ts → dist/index.d.ts} +0 -5
- package/{index.js → dist/index.js} +1 -6
- package/dist/internal.d.ts +2 -0
- package/dist/internal.js +13 -0
- package/{plugin.d.ts → dist/plugin.d.ts} +0 -1
- package/dist/plugins/resolver.d.ts +1 -0
- package/{plugins → dist/plugins}/resolver.js +1 -1
- package/{preset → dist/preset}/index.d.ts +0 -1
- package/{preset → dist/preset}/jest-preset.d.ts +0 -1
- package/{preset → dist/preset}/jest-preset.js +1 -0
- package/{preset.d.ts → dist/preset.d.ts} +0 -1
- package/{src → dist/src}/executors/jest/jest.impl.d.ts +0 -1
- package/{src → dist/src}/executors/jest/jest.impl.js +4 -2
- package/{src → dist/src}/executors/jest/schema.json +1 -0
- package/{src → dist/src}/executors/jest/summary.d.ts +0 -1
- package/{src → dist/src}/generators/configuration/configuration.d.ts +0 -1
- package/{src → dist/src}/generators/configuration/configuration.js +22 -8
- package/{src → dist/src}/generators/configuration/lib/check-for-test-target.d.ts +0 -1
- package/{src → dist/src}/generators/configuration/lib/create-files.d.ts +0 -1
- package/{src → dist/src}/generators/configuration/lib/create-files.js +2 -2
- package/{src → dist/src}/generators/configuration/lib/create-jest-config.d.ts +0 -1
- package/{src → dist/src}/generators/configuration/lib/create-jest-config.js +2 -2
- package/{src → dist/src}/generators/configuration/lib/ensure-dependencies.d.ts +0 -1
- package/{src → dist/src}/generators/configuration/lib/update-tsconfig.d.ts +0 -1
- package/{src → dist/src}/generators/configuration/lib/update-tsconfig.js +2 -2
- package/{src → dist/src}/generators/configuration/lib/update-vscode-recommended-extensions.d.ts +0 -1
- package/{src → dist/src}/generators/configuration/lib/update-workspace.d.ts +0 -1
- package/{src → dist/src}/generators/convert-to-inferred/convert-to-inferred.d.ts +0 -1
- package/{src → dist/src}/generators/convert-to-inferred/convert-to-inferred.js +13 -14
- package/{src → dist/src}/generators/init/init.d.ts +0 -1
- package/{src → dist/src}/generators/init/init.js +60 -21
- package/{src → dist/src}/migrations/update-20-0-0/replace-getJestProjects-with-getJestProjectsAsync.d.ts +0 -1
- package/{src/migrations/update-21-0-0 → dist/src/migrations/update-20-0-0}/replace-getJestProjects-with-getJestProjectsAsync.js +2 -2
- package/dist/src/migrations/update-20-0-0/replace-getJestProjects-with-getJestProjectsAsync.md +25 -0
- package/{src → dist/src}/migrations/update-21-0-0/remove-tsconfig-option-from-jest-executor.d.ts +0 -1
- package/dist/src/migrations/update-21-0-0/remove-tsconfig-option-from-jest-executor.js +97 -0
- package/dist/src/migrations/update-21-0-0/remove-tsconfig-option-from-jest-executor.md +102 -0
- package/{src → dist/src}/migrations/update-21-0-0/replace-getJestProjects-with-getJestProjectsAsync.d.ts +0 -1
- package/{src/migrations/update-20-0-0 → dist/src/migrations/update-21-0-0}/replace-getJestProjects-with-getJestProjectsAsync.js +2 -2
- package/dist/src/migrations/update-21-0-0/replace-getJestProjects-with-getJestProjectsAsync.md +25 -0
- package/{src → dist/src}/migrations/update-21-3-0/rename-test-path-pattern.d.ts +0 -1
- package/{src → dist/src}/migrations/update-21-3-0/rename-test-path-pattern.js +27 -11
- package/dist/src/migrations/update-21-3-0/rename-test-path-pattern.md +147 -0
- package/{src → dist/src}/migrations/update-21-3-0/replace-removed-matcher-aliases.d.ts +0 -1
- package/dist/src/migrations/update-21-3-0/replace-removed-matcher-aliases.md +51 -0
- package/{src → dist/src}/migrations/update-22-2-0/convert-jest-config-to-cjs.d.ts +0 -1
- package/dist/src/migrations/update-22-2-0/convert-jest-config-to-cjs.md +33 -0
- package/dist/src/migrations/update-23-0-0/rewrite-internal-subpath-imports.d.ts +3 -0
- package/dist/src/migrations/update-23-0-0/rewrite-internal-subpath-imports.js +201 -0
- package/dist/src/migrations/update-23-0-0/rewrite-jest-project-generator.d.ts +3 -0
- package/dist/src/migrations/update-23-0-0/rewrite-jest-project-generator.js +121 -0
- package/dist/src/migrations/update-23-0-0/update-snapshot-guide-link.d.ts +2 -0
- package/dist/src/migrations/update-23-0-0/update-snapshot-guide-link.js +28 -0
- package/dist/src/migrations/update-23-0-0/update-snapshot-guide-link.md +21 -0
- package/{src → dist/src}/plugins/plugin.d.ts +0 -1
- package/{src → dist/src}/plugins/plugin.js +18 -25
- package/{src → dist/src}/utils/ast-utils.d.ts +0 -1
- package/{src → dist/src}/utils/config/config-file.d.ts +0 -1
- package/{src → dist/src}/utils/config/functions.d.ts +0 -1
- package/{src → dist/src}/utils/config/functions.js +7 -7
- package/{src → dist/src}/utils/config/get-jest-projects.d.ts +0 -1
- package/{src → dist/src}/utils/config/get-jest-projects.js +2 -2
- package/{src → dist/src}/utils/config/update-config.d.ts +0 -1
- package/dist/src/utils/deprecation.d.ts +3 -0
- package/dist/src/utils/deprecation.js +15 -0
- package/{src → dist/src}/utils/version-utils.d.ts +0 -1
- package/{src → dist/src}/utils/versions.d.ts +0 -1
- package/{src → dist/src}/utils/versions.js +11 -5
- package/executors.json +3 -3
- package/generators.json +6 -6
- package/migrations.json +45 -7
- package/package.json +65 -10
- package/index.d.ts.map +0 -1
- package/plugin.d.ts.map +0 -1
- package/plugins/resolver.d.ts +0 -2
- package/plugins/resolver.d.ts.map +0 -1
- package/preset/index.d.ts.map +0 -1
- package/preset/jest-preset.d.ts.map +0 -1
- package/preset.d.ts.map +0 -1
- package/src/executors/jest/jest.impl.d.ts.map +0 -1
- package/src/executors/jest/summary.d.ts.map +0 -1
- package/src/generators/configuration/configuration.d.ts.map +0 -1
- package/src/generators/configuration/lib/check-for-test-target.d.ts.map +0 -1
- package/src/generators/configuration/lib/create-files.d.ts.map +0 -1
- package/src/generators/configuration/lib/create-jest-config.d.ts.map +0 -1
- package/src/generators/configuration/lib/ensure-dependencies.d.ts.map +0 -1
- package/src/generators/configuration/lib/update-tsconfig.d.ts.map +0 -1
- package/src/generators/configuration/lib/update-vscode-recommended-extensions.d.ts.map +0 -1
- package/src/generators/configuration/lib/update-workspace.d.ts.map +0 -1
- package/src/generators/convert-to-inferred/convert-to-inferred.d.ts.map +0 -1
- package/src/generators/init/init.d.ts.map +0 -1
- package/src/migrations/update-20-0-0/replace-getJestProjects-with-getJestProjectsAsync.d.ts.map +0 -1
- package/src/migrations/update-21-0-0/remove-tsconfig-option-from-jest-executor.d.ts.map +0 -1
- package/src/migrations/update-21-0-0/remove-tsconfig-option-from-jest-executor.js +0 -65
- package/src/migrations/update-21-0-0/replace-getJestProjects-with-getJestProjectsAsync.d.ts.map +0 -1
- package/src/migrations/update-21-3-0/rename-test-path-pattern.d.ts.map +0 -1
- package/src/migrations/update-21-3-0/replace-removed-matcher-aliases.d.ts.map +0 -1
- package/src/migrations/update-22-2-0/convert-jest-config-to-cjs.d.ts.map +0 -1
- package/src/plugins/plugin.d.ts.map +0 -1
- package/src/utils/ast-utils.d.ts.map +0 -1
- package/src/utils/config/config-file.d.ts.map +0 -1
- package/src/utils/config/functions.d.ts.map +0 -1
- package/src/utils/config/get-jest-projects.d.ts.map +0 -1
- package/src/utils/config/update-config.d.ts.map +0 -1
- package/src/utils/version-utils.d.ts.map +0 -1
- package/src/utils/versions.d.ts.map +0 -1
- /package/{LICENSE → dist/LICENSE} +0 -0
- /package/{PLUGIN.md → dist/PLUGIN.md} +0 -0
- /package/{plugin.js → dist/plugin.js} +0 -0
- /package/{preset → dist/preset}/index.js +0 -0
- /package/{preset.js → dist/preset.js} +0 -0
- /package/{src → dist/src}/executors/jest/schema.d.ts +0 -0
- /package/{src → dist/src}/executors/jest/summary.js +0 -0
- /package/{src → dist/src}/generators/configuration/files/common/src/test-setup.ts__tmpl__ +0 -0
- /package/{src → dist/src}/generators/configuration/files/common/tsconfig.spec.json__tmpl__ +0 -0
- /package/{src → dist/src}/generators/configuration/files/jest-config-non-ts-solution/jest.config.ts__tmpl__ +0 -0
- /package/{src → dist/src}/generators/configuration/files/jest-config-ts-solution/jest.config.ts__tmpl__ +0 -0
- /package/{src → dist/src}/generators/configuration/files-angular/jest.config.ts__tmpl__ +0 -0
- /package/{src → dist/src}/generators/configuration/files-angular/src/test-setup.ts__tmpl__ +0 -0
- /package/{src → dist/src}/generators/configuration/files-angular/tsconfig.spec.json__tmpl__ +0 -0
- /package/{src → dist/src}/generators/configuration/lib/check-for-test-target.js +0 -0
- /package/{src → dist/src}/generators/configuration/lib/ensure-dependencies.js +0 -0
- /package/{src → dist/src}/generators/configuration/lib/update-vscode-recommended-extensions.js +0 -0
- /package/{src → dist/src}/generators/configuration/lib/update-workspace.js +0 -0
- /package/{src → dist/src}/generators/configuration/schema.d.ts +0 -0
- /package/{src → dist/src}/generators/configuration/schema.json +0 -0
- /package/{src → dist/src}/generators/convert-to-inferred/schema.json +0 -0
- /package/{src → dist/src}/generators/init/schema.d.ts +0 -0
- /package/{src → dist/src}/generators/init/schema.json +0 -0
- /package/{src → dist/src}/migrations/update-21-3-0/replace-removed-matcher-aliases.js +0 -0
- /package/{src → dist/src}/migrations/update-22-2-0/convert-jest-config-to-cjs.js +0 -0
- /package/{src → dist/src}/utils/ast-utils.js +0 -0
- /package/{src → dist/src}/utils/config/config-file.js +0 -0
- /package/{src → dist/src}/utils/config/update-config.js +0 -0
- /package/{src → dist/src}/utils/version-utils.js +0 -0
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import { configurationGenerator } from './src/generators/configuration/configuration';
|
|
2
2
|
export { configurationGenerator };
|
|
3
|
-
/**
|
|
4
|
-
* @deprecated Use `configurationGenerator` instead. It will be removed in Nx v22.
|
|
5
|
-
*/
|
|
6
|
-
export declare const jestProjectGenerator: typeof configurationGenerator;
|
|
7
3
|
export { addPropertyToJestConfig, removePropertyFromJestConfig, } from './src/utils/config/update-config';
|
|
8
4
|
export { jestConfigObjectAst } from './src/utils/config/functions';
|
|
9
5
|
export { jestInitGenerator } from './src/generators/init/init';
|
|
10
6
|
export { getJestProjectsAsync } from './src/utils/config/get-jest-projects';
|
|
11
7
|
export { findJestConfig } from './src/utils/config/config-file';
|
|
12
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.findJestConfig = exports.getJestProjectsAsync = exports.jestInitGenerator = exports.jestConfigObjectAst = exports.removePropertyFromJestConfig = exports.addPropertyToJestConfig = exports.
|
|
3
|
+
exports.findJestConfig = exports.getJestProjectsAsync = exports.jestInitGenerator = exports.jestConfigObjectAst = exports.removePropertyFromJestConfig = exports.addPropertyToJestConfig = 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
|
-
// Exported for backwards compatibility in case a plugin is using the old name.
|
|
7
|
-
/**
|
|
8
|
-
* @deprecated Use `configurationGenerator` instead. It will be removed in Nx v22.
|
|
9
|
-
*/
|
|
10
|
-
exports.jestProjectGenerator = configuration_1.configurationGenerator;
|
|
11
6
|
var update_config_1 = require("./src/utils/config/update-config");
|
|
12
7
|
Object.defineProperty(exports, "addPropertyToJestConfig", { enumerable: true, get: function () { return update_config_1.addPropertyToJestConfig; } });
|
|
13
8
|
Object.defineProperty(exports, "removePropertyFromJestConfig", { enumerable: true, get: function () { return update_config_1.removePropertyFromJestConfig; } });
|
package/dist/internal.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Semi-private surface for first-party Nx packages.
|
|
3
|
+
//
|
|
4
|
+
// External plugins should NOT import from here — this entry is curated for
|
|
5
|
+
// internal consumers and may change without semver protection. Mirrors
|
|
6
|
+
// `@nx/devkit/internal`.
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.findRootJestPreset = exports.getInstalledJestMajorVersion = exports.versions = void 0;
|
|
9
|
+
var versions_1 = require("./src/utils/versions");
|
|
10
|
+
Object.defineProperty(exports, "versions", { enumerable: true, get: function () { return versions_1.versions; } });
|
|
11
|
+
Object.defineProperty(exports, "getInstalledJestMajorVersion", { enumerable: true, get: function () { return versions_1.getInstalledJestMajorVersion; } });
|
|
12
|
+
var config_file_1 = require("./src/utils/config/config-file");
|
|
13
|
+
Object.defineProperty(exports, "findRootJestPreset", { enumerable: true, get: function () { return config_file_1.findRootJestPreset; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -19,7 +19,7 @@ function getCompilerSetup(rootDir) {
|
|
|
19
19
|
const config = ts.parseJsonConfigFileContent(readResult.config, ts.sys, (0, path_1.dirname)(tsConfigPath));
|
|
20
20
|
const compilerOptions = config.options;
|
|
21
21
|
if (!compilerOptions.baseUrl) {
|
|
22
|
-
const { resolvePathsBaseUrl
|
|
22
|
+
const { resolvePathsBaseUrl } = require('@nx/js');
|
|
23
23
|
compilerOptions.baseUrl = resolvePathsBaseUrl(tsConfigPath);
|
|
24
24
|
}
|
|
25
25
|
const host = ts.createCompilerHost(compilerOptions, true);
|
|
@@ -25,6 +25,7 @@ exports.nxPreset = {
|
|
|
25
25
|
],
|
|
26
26
|
},
|
|
27
27
|
testEnvironment: 'jsdom',
|
|
28
|
+
modulePathIgnorePatterns: ['<rootDir>/dist/', '<rootDir>/out-tsc/'],
|
|
28
29
|
/**
|
|
29
30
|
* manually set the exports names to load in common js, to mimic the behaviors of jest 27
|
|
30
31
|
* before jest didn't fully support package exports and would load in common js code (typically via main field). now jest 28+ will load in the browser esm code, but jest esm support is not fully supported.
|
|
@@ -8,4 +8,3 @@ export declare function jestExecutor(options: JestExecutorOptions, context: Exec
|
|
|
8
8
|
export declare function parseJestConfig(options: JestExecutorOptions, context: ExecutorContext, multiProjects?: boolean): Promise<Config.Argv>;
|
|
9
9
|
export default jestExecutor;
|
|
10
10
|
export declare function batchJest(taskGraph: TaskGraph, inputs: Record<string, JestExecutorOptions>, overrides: JestExecutorOptions, context: ExecutorContext): Promise<BatchResults>;
|
|
11
|
-
//# sourceMappingURL=jest.impl.d.ts.map
|
|
@@ -10,11 +10,14 @@ const reporters_1 = require("@jest/reporters");
|
|
|
10
10
|
const test_result_1 = require("@jest/test-result");
|
|
11
11
|
const path = tslib_1.__importStar(require("path"));
|
|
12
12
|
const path_1 = require("path");
|
|
13
|
+
const schema_json_1 = tslib_1.__importDefault(require("./schema.json"));
|
|
13
14
|
const devkit_1 = require("@nx/devkit");
|
|
14
15
|
const summary_1 = require("./summary");
|
|
15
16
|
const fs_1 = require("fs");
|
|
17
|
+
const deprecation_1 = require("../../utils/deprecation");
|
|
16
18
|
process.env.NODE_ENV ??= 'test';
|
|
17
19
|
async function jestExecutor(options, context) {
|
|
20
|
+
(0, deprecation_1.warnJestExecutorDeprecation)();
|
|
18
21
|
// Jest registers ts-node with module CJS https://github.com/SimenB/jest/blob/v29.6.4/packages/jest-config/src/readConfigFileAndSetRootDir.ts#L117-L119
|
|
19
22
|
// We want to support of ESM via 'module':'nodenext', we need to override the resolution until Jest supports it.
|
|
20
23
|
const existingValue = process.env['TS_NODE_COMPILER_OPTIONS'];
|
|
@@ -42,8 +45,7 @@ async function parseJestConfig(options, context, multiProjects = false) {
|
|
|
42
45
|
let jestConfig;
|
|
43
46
|
// support passing extra args to jest cli supporting 3rd party plugins
|
|
44
47
|
// like 'jest-runner-groups' --group arg
|
|
45
|
-
const
|
|
46
|
-
const extraArgs = getExtraArgs(options, schema);
|
|
48
|
+
const extraArgs = getExtraArgs(options, schema_json_1.default);
|
|
47
49
|
const config = {
|
|
48
50
|
...extraArgs,
|
|
49
51
|
$0: undefined,
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
"description": "Jest target options for Build Facade.",
|
|
6
6
|
"cli": "nx",
|
|
7
7
|
"type": "object",
|
|
8
|
+
"x-deprecated": "The `@nx/jest:jest` executor is deprecated and will be removed in Nx v24. Run `nx g @nx/jest:convert-to-inferred` to migrate to the `@nx/jest/plugin` inferred plugin. See https://nx.dev/docs/guides/tasks--caching/convert-to-inferred for details.",
|
|
8
9
|
"presets": [
|
|
9
10
|
{
|
|
10
11
|
"name": "Pass Without Tests",
|
|
@@ -3,4 +3,3 @@ import { JestProjectSchema } from './schema';
|
|
|
3
3
|
export declare function configurationGenerator(tree: Tree, schema: JestProjectSchema): Promise<GeneratorCallback>;
|
|
4
4
|
export declare function configurationGeneratorInternal(tree: Tree, schema: JestProjectSchema): Promise<GeneratorCallback>;
|
|
5
5
|
export default configurationGenerator;
|
|
6
|
-
//# sourceMappingURL=configuration.d.ts.map
|
|
@@ -3,10 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.configurationGenerator = configurationGenerator;
|
|
4
4
|
exports.configurationGeneratorInternal = configurationGeneratorInternal;
|
|
5
5
|
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
6
7
|
const js_1 = require("@nx/js");
|
|
7
|
-
const
|
|
8
|
+
const internal_2 = require("@nx/js/internal");
|
|
8
9
|
const config_file_1 = require("../../utils/config/config-file");
|
|
9
10
|
const init_1 = require("../init/init");
|
|
11
|
+
const deprecation_1 = require("../../utils/deprecation");
|
|
10
12
|
const check_for_test_target_1 = require("./lib/check-for-test-target");
|
|
11
13
|
const create_files_1 = require("./lib/create-files");
|
|
12
14
|
const create_jest_config_1 = require("./lib/create-jest-config");
|
|
@@ -50,7 +52,7 @@ function normalizeOptions(tree, options) {
|
|
|
50
52
|
...options,
|
|
51
53
|
keepExistingVersions: options.keepExistingVersions ?? true,
|
|
52
54
|
rootProject: project.root === '.' || project.root === '',
|
|
53
|
-
isTsSolutionSetup: (0,
|
|
55
|
+
isTsSolutionSetup: (0, internal_2.isUsingTsSolutionSetup)(tree),
|
|
54
56
|
};
|
|
55
57
|
}
|
|
56
58
|
function configurationGenerator(tree, schema) {
|
|
@@ -88,18 +90,20 @@ async function configurationGeneratorInternal(tree, schema) {
|
|
|
88
90
|
}
|
|
89
91
|
});
|
|
90
92
|
if (!hasPlugin || options.addExplicitTargets) {
|
|
93
|
+
(0, deprecation_1.warnJestExecutorGenerating)();
|
|
91
94
|
(0, update_workspace_1.updateWorkspace)(tree, options);
|
|
92
95
|
}
|
|
93
96
|
if (options.isTsSolutionSetup) {
|
|
94
97
|
ignoreTestOutput(tree);
|
|
95
98
|
// in the TS solution setup, the test target depends on the build outputs
|
|
96
99
|
// so we need to setup the task pipeline accordingly
|
|
97
|
-
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
98
|
-
nxJson.targetDefaults
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
100
|
+
const nxJson = (0, devkit_1.readNxJson)(tree) ?? {};
|
|
101
|
+
const existing = findExistingTestDefault(nxJson.targetDefaults, options.targetName);
|
|
102
|
+
const dependsOn = Array.from(new Set([...(existing?.dependsOn ?? []), '^build']));
|
|
103
|
+
(0, internal_1.upsertTargetDefault)(tree, nxJson, {
|
|
104
|
+
target: options.targetName,
|
|
105
|
+
dependsOn,
|
|
106
|
+
});
|
|
103
107
|
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
104
108
|
}
|
|
105
109
|
if (!schema.skipFormat) {
|
|
@@ -107,6 +111,16 @@ async function configurationGeneratorInternal(tree, schema) {
|
|
|
107
111
|
}
|
|
108
112
|
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
109
113
|
}
|
|
114
|
+
function findExistingTestDefault(td, targetName) {
|
|
115
|
+
if (!td)
|
|
116
|
+
return undefined;
|
|
117
|
+
if (Array.isArray(td)) {
|
|
118
|
+
return td.find((e) => e.target === targetName &&
|
|
119
|
+
e.projects === undefined &&
|
|
120
|
+
e.plugin === undefined);
|
|
121
|
+
}
|
|
122
|
+
return td[targetName];
|
|
123
|
+
}
|
|
110
124
|
function ignoreTestOutput(tree) {
|
|
111
125
|
if (!tree.exists('.gitignore')) {
|
|
112
126
|
devkit_1.logger.warn(`Couldn't find a root .gitignore file to update.`);
|
|
@@ -2,4 +2,3 @@ import { Tree } from '@nx/devkit';
|
|
|
2
2
|
import type { JestPresetExtension } from '../../../utils/config/config-file';
|
|
3
3
|
import { NormalizedJestProjectSchema } from '../schema';
|
|
4
4
|
export declare function createFiles(tree: Tree, options: NormalizedJestProjectSchema, presetExt: JestPresetExtension): void;
|
|
5
|
-
//# sourceMappingURL=create-files.d.ts.map
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createFiles = createFiles;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const
|
|
5
|
+
const internal_1 = require("@nx/js/internal");
|
|
6
6
|
const path_1 = require("path");
|
|
7
7
|
const versions_1 = require("../../../utils/versions");
|
|
8
8
|
function createFiles(tree, options, presetExt) {
|
|
@@ -33,7 +33,7 @@ function createFiles(tree, options, presetExt) {
|
|
|
33
33
|
transformerOptions = "{ tsconfig: '<rootDir>/tsconfig.spec.json' }";
|
|
34
34
|
}
|
|
35
35
|
if (options.compiler === 'swc' && options.isTsSolutionSetup) {
|
|
36
|
-
(0,
|
|
36
|
+
(0, internal_1.addSwcTestConfig)(tree, projectConfig.root, 'es6', options.supportTsx);
|
|
37
37
|
}
|
|
38
38
|
const projectRoot = options.rootProject
|
|
39
39
|
? options.project
|
|
@@ -2,4 +2,3 @@ import { type Tree } from '@nx/devkit';
|
|
|
2
2
|
import { type JestPresetExtension } from '../../../utils/config/config-file';
|
|
3
3
|
import type { NormalizedJestProjectSchema } from '../schema';
|
|
4
4
|
export declare function createJestConfig(tree: Tree, options: Partial<NormalizedJestProjectSchema>, presetExt: JestPresetExtension): Promise<void>;
|
|
5
|
-
//# sourceMappingURL=create-jest-config.d.ts.map
|
|
@@ -4,7 +4,7 @@ exports.createJestConfig = createJestConfig;
|
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const project_configuration_utils_1 = require("nx/src/project-graph/utils/project-configuration-utils");
|
|
6
6
|
const config_file_1 = require("../../../utils/config/config-file");
|
|
7
|
-
const
|
|
7
|
+
const internal_1 = require("@nx/js/internal");
|
|
8
8
|
async function createJestConfig(tree, options, presetExt) {
|
|
9
9
|
if (!tree.exists(`jest.preset.${presetExt}`)) {
|
|
10
10
|
if (presetExt === 'mjs') {
|
|
@@ -58,7 +58,7 @@ module.exports = { ...nxPreset };`);
|
|
|
58
58
|
// Jest target has already been updated
|
|
59
59
|
return;
|
|
60
60
|
}
|
|
61
|
-
const jestProjectConfig = `jest.config.${(0,
|
|
61
|
+
const jestProjectConfig = `jest.config.${(0, internal_1.getProjectType)(tree, rootProjectConfig.root, rootProjectConfig.projectType) === 'application'
|
|
62
62
|
? 'app'
|
|
63
63
|
: 'lib'}.${options.js ? 'js' : 'ts'}`;
|
|
64
64
|
tree.rename(rootJestPath, jestProjectConfig);
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import { type Tree } from '@nx/devkit';
|
|
2
2
|
import type { NormalizedJestProjectSchema } from '../schema';
|
|
3
3
|
export declare function ensureDependencies(tree: Tree, options: Partial<NormalizedJestProjectSchema>): import("@nx/devkit").GeneratorCallback;
|
|
4
|
-
//# sourceMappingURL=ensure-dependencies.d.ts.map
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.updateTsConfig = updateTsConfig;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const
|
|
5
|
+
const internal_1 = require("@nx/js/internal");
|
|
6
6
|
function updateTsConfig(host, options) {
|
|
7
7
|
const { root, projectType: _projectType } = (0, devkit_1.readProjectConfiguration)(host, options.project);
|
|
8
8
|
if (!host.exists((0, devkit_1.joinPathFragments)(root, 'tsconfig.json'))) {
|
|
@@ -25,7 +25,7 @@ function updateTsConfig(host, options) {
|
|
|
25
25
|
}
|
|
26
26
|
return json;
|
|
27
27
|
});
|
|
28
|
-
const projectType = (0,
|
|
28
|
+
const projectType = (0, internal_1.getProjectType)(host, root, _projectType);
|
|
29
29
|
// fall-back runtime tsconfig file path in case the user didn't provide one
|
|
30
30
|
let runtimeTsconfigPath = (0, devkit_1.joinPathFragments)(root, projectType === 'application' ? 'tsconfig.app.json' : 'tsconfig.lib.json');
|
|
31
31
|
if (options.runtimeTsconfigFileName) {
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.convertToInferred = convertToInferred;
|
|
4
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
4
5
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const executor_to_plugin_migrator_1 = require("@nx/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator");
|
|
6
|
-
const plugin_migration_utils_1 = require("@nx/devkit/src/generators/plugin-migrations/plugin-migration-utils");
|
|
7
6
|
const jest_config_1 = require("jest-config");
|
|
8
7
|
const node_path_1 = require("node:path");
|
|
9
8
|
const plugin_1 = require("../../plugins/plugin");
|
|
@@ -11,7 +10,7 @@ const config_file_1 = require("../../utils/config/config-file");
|
|
|
11
10
|
const versions_1 = require("../../utils/versions");
|
|
12
11
|
async function convertToInferred(tree, options) {
|
|
13
12
|
const projectGraph = await (0, devkit_1.createProjectGraphAsync)();
|
|
14
|
-
const migratedProjects = await (0,
|
|
13
|
+
const migratedProjects = await (0, internal_1.migrateProjectExecutorsToPlugin)(tree, projectGraph, '@nx/jest/plugin', plugin_1.createNodesV2, { targetName: 'test' }, [
|
|
15
14
|
{
|
|
16
15
|
executors: ['@nx/jest:jest', '@nrwl/jest:jest'],
|
|
17
16
|
postTargetTransformer,
|
|
@@ -19,7 +18,7 @@ async function convertToInferred(tree, options) {
|
|
|
19
18
|
},
|
|
20
19
|
], options.project);
|
|
21
20
|
if (migratedProjects.size === 0) {
|
|
22
|
-
throw new
|
|
21
|
+
throw new internal_1.NoTargetsToMigrateError();
|
|
23
22
|
}
|
|
24
23
|
if (!options.skipFormat) {
|
|
25
24
|
await (0, devkit_1.formatFiles)(tree);
|
|
@@ -49,7 +48,7 @@ async function postTargetTransformer(target, tree, projectDetails, inferredTarge
|
|
|
49
48
|
}
|
|
50
49
|
}
|
|
51
50
|
if (target.outputs) {
|
|
52
|
-
(0,
|
|
51
|
+
(0, internal_1.processTargetOutputs)(target, [], inferredTarget, {
|
|
53
52
|
projectName: projectDetails.projectName,
|
|
54
53
|
projectRoot: projectDetails.root,
|
|
55
54
|
});
|
|
@@ -68,11 +67,11 @@ async function updateOptionsObject(tree, targetOptions, projectRoot, workspaceRo
|
|
|
68
67
|
async function updateConfigurationObject(tree, targetOptions, projectRoot, workspaceRoot, defaultJestConfigPath) {
|
|
69
68
|
const jestConfigPath = targetOptions.jestConfig ?? defaultJestConfigPath;
|
|
70
69
|
if (targetOptions.jestConfig) {
|
|
71
|
-
targetOptions.config = (0,
|
|
70
|
+
targetOptions.config = (0, internal_1.toProjectRelativePath)(targetOptions.jestConfig, projectRoot);
|
|
72
71
|
delete targetOptions.jestConfig;
|
|
73
72
|
}
|
|
74
73
|
else if (targetOptions.config) {
|
|
75
|
-
targetOptions.config = (0,
|
|
74
|
+
targetOptions.config = (0, internal_1.toProjectRelativePath)(targetOptions.config, projectRoot);
|
|
76
75
|
}
|
|
77
76
|
await updateOptions(tree, targetOptions, projectRoot, workspaceRoot, jestConfigPath);
|
|
78
77
|
}
|
|
@@ -127,7 +126,7 @@ async function updateOptions(tree, targetOptions, projectRoot, workspaceRoot, je
|
|
|
127
126
|
// the executor accepts a comma-separated string, while jest accepts a space-separated string
|
|
128
127
|
const parsedSourceFiles = targetOptions.findRelatedTests
|
|
129
128
|
.split(',')
|
|
130
|
-
.map((s) => (0,
|
|
129
|
+
.map((s) => (0, internal_1.toProjectRelativePath)(s.trim(), projectRoot))
|
|
131
130
|
.join(' ');
|
|
132
131
|
targetOptions.args = [`--findRelatedTests ${parsedSourceFiles}`];
|
|
133
132
|
delete targetOptions.findRelatedTests;
|
|
@@ -151,11 +150,11 @@ async function updateOptions(tree, targetOptions, projectRoot, workspaceRoot, je
|
|
|
151
150
|
}
|
|
152
151
|
if ('outputFile' in targetOptions) {
|
|
153
152
|
// update the output file to be relative to the project root
|
|
154
|
-
targetOptions.outputFile = (0,
|
|
153
|
+
targetOptions.outputFile = (0, internal_1.toProjectRelativePath)(targetOptions.outputFile, projectRoot);
|
|
155
154
|
}
|
|
156
155
|
if ('coverageDirectory' in targetOptions) {
|
|
157
156
|
// update the coverage directory to be relative to the project root
|
|
158
|
-
targetOptions.coverageDirectory = (0,
|
|
157
|
+
targetOptions.coverageDirectory = (0, internal_1.toProjectRelativePath)(targetOptions.coverageDirectory, projectRoot);
|
|
159
158
|
}
|
|
160
159
|
}
|
|
161
160
|
async function processSetupFiles(setupFile, setupFilesAfterEnv, projectRoot, workspaceRoot, jestConfigPath) {
|
|
@@ -167,11 +166,11 @@ async function processSetupFiles(setupFile, setupFilesAfterEnv, projectRoot, wor
|
|
|
167
166
|
if (jestConfigPath) {
|
|
168
167
|
const jestConfig = await (0, jest_config_1.readConfig)({ setupFilesAfterEnv }, (0, node_path_1.join)(workspaceRoot, jestConfigPath));
|
|
169
168
|
if (jestConfig.projectConfig.setupFilesAfterEnv) {
|
|
170
|
-
configSetupFilesAfterEnv.push(...jestConfig.projectConfig.setupFilesAfterEnv.map((file) => (0,
|
|
169
|
+
configSetupFilesAfterEnv.push(...jestConfig.projectConfig.setupFilesAfterEnv.map((file) => (0, internal_1.toProjectRelativePath)(file, projectRoot)));
|
|
171
170
|
}
|
|
172
171
|
}
|
|
173
172
|
if (!configSetupFilesAfterEnv.length) {
|
|
174
|
-
return [(0,
|
|
173
|
+
return [(0, internal_1.toProjectRelativePath)(setupFile, projectRoot)];
|
|
175
174
|
}
|
|
176
175
|
if (isSetupFileInConfig(configSetupFilesAfterEnv, setupFile, projectRoot, workspaceRoot)) {
|
|
177
176
|
// the setupFile is already included in the setupFilesAfterEnv
|
|
@@ -179,7 +178,7 @@ async function processSetupFiles(setupFile, setupFilesAfterEnv, projectRoot, wor
|
|
|
179
178
|
}
|
|
180
179
|
return [
|
|
181
180
|
...configSetupFilesAfterEnv,
|
|
182
|
-
(0,
|
|
181
|
+
(0, internal_1.toProjectRelativePath)(setupFile, projectRoot),
|
|
183
182
|
];
|
|
184
183
|
}
|
|
185
184
|
function isSetupFileInConfig(setupFilesAfterEnv, setupFile, projectRoot, workspaceRoot) {
|
|
@@ -187,7 +186,7 @@ function isSetupFileInConfig(setupFilesAfterEnv, setupFile, projectRoot, workspa
|
|
|
187
186
|
? node_path_1.posix.join(workspaceRoot, projectRoot, f.slice('<rootDir>'.length))
|
|
188
187
|
: node_path_1.posix.join(workspaceRoot, projectRoot, f);
|
|
189
188
|
const normalizedSetupFiles = new Set(setupFilesAfterEnv.map(normalizePath));
|
|
190
|
-
return normalizedSetupFiles.has(normalizePath((0,
|
|
189
|
+
return normalizedSetupFiles.has(normalizePath((0, internal_1.toProjectRelativePath)(setupFile, projectRoot)));
|
|
191
190
|
}
|
|
192
191
|
function toProjectRelativeRegexPath(path, projectRoot) {
|
|
193
192
|
if (projectRoot === '.') {
|
|
@@ -3,4 +3,3 @@ import type { JestInitSchema } from './schema';
|
|
|
3
3
|
export declare function jestInitGenerator(tree: Tree, options: JestInitSchema): Promise<GeneratorCallback>;
|
|
4
4
|
export declare function jestInitGeneratorInternal(tree: Tree, options: JestInitSchema): Promise<GeneratorCallback>;
|
|
5
5
|
export default jestInitGenerator;
|
|
6
|
-
//# sourceMappingURL=init.d.ts.map
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.jestInitGenerator = jestInitGenerator;
|
|
4
4
|
exports.jestInitGeneratorInternal = jestInitGeneratorInternal;
|
|
5
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
5
6
|
const devkit_1 = require("@nx/devkit");
|
|
6
|
-
const add_plugin_1 = require("@nx/devkit/src/utils/add-plugin");
|
|
7
7
|
const plugin_1 = require("../../plugins/plugin");
|
|
8
8
|
const config_file_1 = require("../../utils/config/config-file");
|
|
9
9
|
const versions_1 = require("../../utils/versions");
|
|
@@ -28,27 +28,66 @@ function updateProductionFileSet(tree) {
|
|
|
28
28
|
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
29
29
|
}
|
|
30
30
|
function addJestTargetDefaults(tree, presetExt) {
|
|
31
|
-
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
32
|
-
nxJson.targetDefaults ??= {};
|
|
33
|
-
nxJson.targetDefaults['@nx/jest:jest'] ??= {};
|
|
31
|
+
const nxJson = (0, devkit_1.readNxJson)(tree) ?? {};
|
|
34
32
|
const productionFileSet = nxJson.namedInputs?.production;
|
|
35
|
-
nxJson.targetDefaults
|
|
33
|
+
const existingEntries = findExistingJestDefaults(nxJson.targetDefaults);
|
|
34
|
+
if (existingEntries.length === 0) {
|
|
35
|
+
const patch = createJestDefaultPatch(undefined, productionFileSet, presetExt);
|
|
36
|
+
if (Object.keys(patch).length > 0) {
|
|
37
|
+
(0, internal_1.upsertTargetDefault)(tree, nxJson, {
|
|
38
|
+
executor: '@nx/jest:jest',
|
|
39
|
+
...patch,
|
|
40
|
+
});
|
|
41
|
+
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
42
|
+
}
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
let didUpdate = false;
|
|
46
|
+
for (const existing of existingEntries) {
|
|
47
|
+
const patch = createJestDefaultPatch(existing, productionFileSet, presetExt);
|
|
48
|
+
if (Object.keys(patch).length === 0) {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
(0, internal_1.upsertTargetDefault)(tree, nxJson, {
|
|
52
|
+
target: existing.target,
|
|
53
|
+
executor: existing.executor,
|
|
54
|
+
projects: existing.projects,
|
|
55
|
+
plugin: existing.plugin,
|
|
56
|
+
...patch,
|
|
57
|
+
});
|
|
58
|
+
didUpdate = true;
|
|
59
|
+
}
|
|
60
|
+
if (didUpdate) {
|
|
61
|
+
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function createJestDefaultPatch(existing, productionFileSet, presetExt) {
|
|
65
|
+
const patch = {};
|
|
66
|
+
if (existing?.cache === undefined)
|
|
67
|
+
patch.cache = true;
|
|
36
68
|
// Test targets depend on all their project's sources + production sources of dependencies
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
69
|
+
if (existing?.inputs === undefined) {
|
|
70
|
+
patch.inputs = [
|
|
71
|
+
'default',
|
|
72
|
+
productionFileSet ? '^production' : '^default',
|
|
73
|
+
`{workspaceRoot}/jest.preset.${presetExt}`,
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
if (existing?.options === undefined) {
|
|
77
|
+
patch.options = { passWithNoTests: true };
|
|
78
|
+
}
|
|
79
|
+
if (existing?.configurations === undefined) {
|
|
80
|
+
patch.configurations = {
|
|
81
|
+
ci: {
|
|
82
|
+
ci: true,
|
|
83
|
+
codeCoverage: true,
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
return patch;
|
|
88
|
+
}
|
|
89
|
+
function findExistingJestDefaults(td) {
|
|
90
|
+
return (0, internal_1.normalizeTargetDefaults)(td).filter((e) => e.executor === '@nx/jest:jest');
|
|
52
91
|
}
|
|
53
92
|
function updateDependencies(tree, options) {
|
|
54
93
|
const { jestVersion, nxVersion } = (0, versions_1.versions)(tree);
|
|
@@ -73,7 +112,7 @@ async function jestInitGeneratorInternal(tree, options) {
|
|
|
73
112
|
if (!tree.exists(`jest.preset.${presetExt}`)) {
|
|
74
113
|
updateProductionFileSet(tree);
|
|
75
114
|
if (options.addPlugin) {
|
|
76
|
-
await (0,
|
|
115
|
+
await (0, internal_1.addPlugin)(tree, await (0, devkit_1.createProjectGraphAsync)(), '@nx/jest/plugin', plugin_1.createNodesV2, {
|
|
77
116
|
targetName: ['test', 'jest:test', 'jest-test'],
|
|
78
117
|
}, options.updatePackageScripts);
|
|
79
118
|
}
|
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.default = update;
|
|
7
7
|
const devkit_1 = require("@nx/devkit");
|
|
8
|
-
const
|
|
8
|
+
const internal_1 = require("@nx/js/internal");
|
|
9
9
|
let tsModule;
|
|
10
10
|
async function update(tree) {
|
|
11
11
|
if (!tsModule) {
|
|
12
|
-
tsModule = (0,
|
|
12
|
+
tsModule = (0, internal_1.ensureTypescript)();
|
|
13
13
|
}
|
|
14
14
|
const jestConfigPaths = await (0, devkit_1.globAsync)(tree, [
|
|
15
15
|
'**/jest.config.{cjs,mjs,js,cts,mts,ts}',
|
package/dist/src/migrations/update-20-0-0/replace-getJestProjects-with-getJestProjectsAsync.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#### Replace Usage of `getJestProjects` with `getJestProjectsAsync`
|
|
2
|
+
|
|
3
|
+
Replaces the usage of the deprecated `getJestProjects` function with the `getJestProjectsAsync` function.
|
|
4
|
+
|
|
5
|
+
#### Sample Code Changes
|
|
6
|
+
|
|
7
|
+
##### Before
|
|
8
|
+
|
|
9
|
+
```ts title="jest.config.ts"
|
|
10
|
+
import { getJestProjects } from '@nx/jest';
|
|
11
|
+
|
|
12
|
+
export default {
|
|
13
|
+
projects: getJestProjects(),
|
|
14
|
+
};
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
##### After
|
|
18
|
+
|
|
19
|
+
```ts title="jest.config.ts"
|
|
20
|
+
import { getJestProjectsAsync } from '@nx/jest';
|
|
21
|
+
|
|
22
|
+
export default async () => ({
|
|
23
|
+
projects: await getJestProjectsAsync(),
|
|
24
|
+
});
|
|
25
|
+
```
|