@nx/jest 23.0.0-beta.21 → 23.0.0-beta.23
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/dist/src/executors/jest/jest.impl.js +0 -10
- package/dist/src/executors/jest/schema.d.ts +0 -7
- package/dist/src/executors/jest/schema.json +0 -5
- package/dist/src/generators/configuration/configuration.js +2 -5
- package/dist/src/generators/configuration/lib/ensure-dependencies.js +1 -1
- package/dist/src/generators/configuration/schema.d.ts +0 -4
- package/dist/src/generators/configuration/schema.json +0 -6
- package/dist/src/generators/convert-to-inferred/convert-to-inferred.js +2 -0
- package/dist/src/generators/init/init.js +3 -5
- package/dist/src/generators/init/schema.json +1 -1
- package/dist/src/migrations/update-23-0-0/migrate-jest-configuration-skip-setup-file.d.ts +2 -0
- package/dist/src/migrations/update-23-0-0/migrate-jest-configuration-skip-setup-file.js +62 -0
- package/dist/src/migrations/update-23-0-0/migrate-jest-configuration-skip-setup-file.md +91 -0
- package/dist/src/migrations/update-23-0-0/migrate-jest-executor-setup-file.d.ts +2 -0
- package/dist/src/migrations/update-23-0-0/migrate-jest-executor-setup-file.js +476 -0
- package/dist/src/migrations/update-23-0-0/migrate-jest-executor-setup-file.md +169 -0
- package/dist/src/plugins/plugin.d.ts +3 -3
- package/dist/src/utils/assert-supported-jest-version.d.ts +2 -0
- package/dist/src/utils/assert-supported-jest-version.js +11 -0
- package/dist/src/utils/versions.d.ts +13 -2
- package/dist/src/utils/versions.js +26 -46
- package/migrations.json +29 -8
- package/package.json +16 -4
- package/dist/src/utils/version-utils.d.ts +0 -2
- package/dist/src/utils/version-utils.js +0 -18
|
@@ -42,7 +42,6 @@ function getExtraArgs(options, schema) {
|
|
|
42
42
|
return extraArgs;
|
|
43
43
|
}
|
|
44
44
|
async function parseJestConfig(options, context, multiProjects = false) {
|
|
45
|
-
let jestConfig;
|
|
46
45
|
// support passing extra args to jest cli supporting 3rd party plugins
|
|
47
46
|
// like 'jest-runner-groups' --group arg
|
|
48
47
|
const extraArgs = getExtraArgs(options, schema_json_1.default);
|
|
@@ -84,15 +83,6 @@ async function parseJestConfig(options, context, multiProjects = false) {
|
|
|
84
83
|
};
|
|
85
84
|
if (!multiProjects) {
|
|
86
85
|
options.jestConfig = path.resolve(context.root, options.jestConfig);
|
|
87
|
-
jestConfig = (await (0, jest_config_1.readConfig)(config, options.jestConfig)).projectConfig;
|
|
88
|
-
}
|
|
89
|
-
// for backwards compatibility
|
|
90
|
-
if (options.setupFile && !multiProjects) {
|
|
91
|
-
const setupFilesAfterEnvSet = new Set([
|
|
92
|
-
...(jestConfig.setupFilesAfterEnv ?? []),
|
|
93
|
-
path.resolve(context.root, options.setupFile),
|
|
94
|
-
]);
|
|
95
|
-
config.setupFilesAfterEnv = Array.from(setupFilesAfterEnvSet);
|
|
96
86
|
}
|
|
97
87
|
if (options.testFile) {
|
|
98
88
|
config._.push(options.testFile);
|
|
@@ -37,11 +37,4 @@ export interface JestExecutorOptions {
|
|
|
37
37
|
watchAll?: boolean;
|
|
38
38
|
testLocationInResults?: boolean;
|
|
39
39
|
testTimeout?: number;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* @deprecated Use the `setupFilesAfterEnv` option in the Jest configuration
|
|
43
|
-
* file instead. See https://jestjs.io/docs/configuration#setupfilesafterenv-array.
|
|
44
|
-
* It will be removed in Nx v22.
|
|
45
|
-
*/
|
|
46
|
-
setupFile?: string;
|
|
47
40
|
}
|
|
@@ -66,11 +66,6 @@
|
|
|
66
66
|
"x-completion-type": "file",
|
|
67
67
|
"x-completion-glob": "tsconfig.*.json"
|
|
68
68
|
},
|
|
69
|
-
"setupFile": {
|
|
70
|
-
"description": "The name of a setup file used by Jest.",
|
|
71
|
-
"type": "string",
|
|
72
|
-
"x-deprecated": "Use the `setupFilesAfterEnv` option in the Jest configuration file instead. See https://jestjs.io/docs/configuration#setupfilesafterenv-array. It will be removed in Nx v22."
|
|
73
|
-
},
|
|
74
69
|
"bail": {
|
|
75
70
|
"alias": "b",
|
|
76
71
|
"description": "Exit the test suite immediately after `n` number of failing tests. (https://jestjs.io/docs/cli#--bail)",
|
|
@@ -8,6 +8,7 @@ const js_1 = require("@nx/js");
|
|
|
8
8
|
const internal_2 = require("@nx/js/internal");
|
|
9
9
|
const config_file_1 = require("../../utils/config/config-file");
|
|
10
10
|
const init_1 = require("../init/init");
|
|
11
|
+
const assert_supported_jest_version_1 = require("../../utils/assert-supported-jest-version");
|
|
11
12
|
const deprecation_1 = require("../../utils/deprecation");
|
|
12
13
|
const check_for_test_target_1 = require("./lib/check-for-test-target");
|
|
13
14
|
const create_files_1 = require("./lib/create-files");
|
|
@@ -20,7 +21,6 @@ const schemaDefaults = {
|
|
|
20
21
|
setupFile: 'none',
|
|
21
22
|
babelJest: false,
|
|
22
23
|
supportTsx: false,
|
|
23
|
-
skipSetupFile: false,
|
|
24
24
|
skipSerializers: false,
|
|
25
25
|
testEnvironment: 'jsdom',
|
|
26
26
|
};
|
|
@@ -42,10 +42,6 @@ function normalizeOptions(tree, options) {
|
|
|
42
42
|
['swc', 'babel'].includes(options.compiler)) {
|
|
43
43
|
options.skipSerializers = true;
|
|
44
44
|
}
|
|
45
|
-
if (options.skipSetupFile) {
|
|
46
|
-
// setupFile is always 'none'
|
|
47
|
-
options.setupFile = schemaDefaults.setupFile;
|
|
48
|
-
}
|
|
49
45
|
const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
50
46
|
return {
|
|
51
47
|
...schemaDefaults,
|
|
@@ -59,6 +55,7 @@ function configurationGenerator(tree, schema) {
|
|
|
59
55
|
return configurationGeneratorInternal(tree, { addPlugin: false, ...schema });
|
|
60
56
|
}
|
|
61
57
|
async function configurationGeneratorInternal(tree, schema) {
|
|
58
|
+
(0, assert_supported_jest_version_1.assertSupportedJestVersion)(tree);
|
|
62
59
|
const options = normalizeOptions(tree, schema);
|
|
63
60
|
// we'll only add the vscode recommended extension if the jest preset does
|
|
64
61
|
// not exist, which most likely means this is a first run, in the cases it's
|
|
@@ -32,5 +32,5 @@ function ensureDependencies(tree, options) {
|
|
|
32
32
|
else if (options.compiler === 'swc') {
|
|
33
33
|
devDeps['@swc/jest'] = swcJestVersion;
|
|
34
34
|
}
|
|
35
|
-
return (0, devkit_1.addDependenciesToPackageJson)(tree, dependencies, devDeps, undefined, options.keepExistingVersions);
|
|
35
|
+
return (0, devkit_1.addDependenciesToPackageJson)(tree, dependencies, devDeps, undefined, options.keepExistingVersions ?? true);
|
|
36
36
|
}
|
|
@@ -26,10 +26,6 @@ export interface JestProjectSchema {
|
|
|
26
26
|
* @deprecated Use the `compiler` option instead. It will be removed in Nx v22.
|
|
27
27
|
*/
|
|
28
28
|
babelJest?: boolean;
|
|
29
|
-
/**
|
|
30
|
-
* @deprecated Use the `setupFile` option instead. It will be removed in Nx v22.
|
|
31
|
-
*/
|
|
32
|
-
skipSetupFile?: boolean;
|
|
33
29
|
keepExistingVersions?: boolean;
|
|
34
30
|
}
|
|
35
31
|
|
|
@@ -14,12 +14,6 @@
|
|
|
14
14
|
},
|
|
15
15
|
"x-priority": "important"
|
|
16
16
|
},
|
|
17
|
-
"skipSetupFile": {
|
|
18
|
-
"type": "boolean",
|
|
19
|
-
"description": "Skips the setup file required for angular.",
|
|
20
|
-
"default": false,
|
|
21
|
-
"x-deprecated": "Use the `setupFile` option instead. It will be removed in Nx v22."
|
|
22
|
-
},
|
|
23
17
|
"setupFile": {
|
|
24
18
|
"type": "string",
|
|
25
19
|
"enum": ["none", "angular", "web-components"],
|
|
@@ -7,8 +7,10 @@ const jest_config_1 = require("jest-config");
|
|
|
7
7
|
const node_path_1 = require("node:path");
|
|
8
8
|
const plugin_1 = require("../../plugins/plugin");
|
|
9
9
|
const config_file_1 = require("../../utils/config/config-file");
|
|
10
|
+
const assert_supported_jest_version_1 = require("../../utils/assert-supported-jest-version");
|
|
10
11
|
const versions_1 = require("../../utils/versions");
|
|
11
12
|
async function convertToInferred(tree, options) {
|
|
13
|
+
(0, assert_supported_jest_version_1.assertSupportedJestVersion)(tree);
|
|
12
14
|
const projectGraph = await (0, devkit_1.createProjectGraphAsync)();
|
|
13
15
|
const migratedProjects = await (0, internal_1.migrateProjectExecutorsToPlugin)(tree, projectGraph, '@nx/jest/plugin', plugin_1.createNodesV2, { targetName: 'test' }, [
|
|
14
16
|
{
|
|
@@ -6,6 +6,7 @@ const internal_1 = require("@nx/devkit/internal");
|
|
|
6
6
|
const devkit_1 = require("@nx/devkit");
|
|
7
7
|
const plugin_1 = require("../../plugins/plugin");
|
|
8
8
|
const config_file_1 = require("../../utils/config/config-file");
|
|
9
|
+
const assert_supported_jest_version_1 = require("../../utils/assert-supported-jest-version");
|
|
9
10
|
const versions_1 = require("../../utils/versions");
|
|
10
11
|
function updateProductionFileSet(tree) {
|
|
11
12
|
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
@@ -94,16 +95,13 @@ function updateDependencies(tree, options) {
|
|
|
94
95
|
return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
|
|
95
96
|
'@nx/jest': nxVersion,
|
|
96
97
|
jest: jestVersion,
|
|
97
|
-
}, undefined, options.keepExistingVersions);
|
|
98
|
+
}, undefined, options.keepExistingVersions ?? true);
|
|
98
99
|
}
|
|
99
100
|
function jestInitGenerator(tree, options) {
|
|
100
101
|
return jestInitGeneratorInternal(tree, { addPlugin: false, ...options });
|
|
101
102
|
}
|
|
102
103
|
async function jestInitGeneratorInternal(tree, options) {
|
|
103
|
-
|
|
104
|
-
if (installedJestVersion) {
|
|
105
|
-
(0, versions_1.validateInstalledJestVersion)(tree);
|
|
106
|
-
}
|
|
104
|
+
(0, assert_supported_jest_version_1.assertSupportedJestVersion)(tree);
|
|
107
105
|
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
108
106
|
const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' &&
|
|
109
107
|
nxJson.useInferencePlugins !== false;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = default_1;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const GENERATOR_NAME = '@nx/jest:configuration';
|
|
6
|
+
const PACKAGE = '@nx/jest';
|
|
7
|
+
const GENERATOR = 'configuration';
|
|
8
|
+
const SKIP_SETUP_FILE = 'skipSetupFile';
|
|
9
|
+
const SETUP_FILE = 'setupFile';
|
|
10
|
+
// Migrate the deprecated `skipSetupFile` option of `@nx/jest:configuration`
|
|
11
|
+
// generator defaults. `skipSetupFile: true` was equivalent to setting
|
|
12
|
+
// `setupFile: 'none'`, so rewrite to that. `skipSetupFile: false` was a no-op
|
|
13
|
+
// — drop it. Run on both `nx.json` `generators` and per-project
|
|
14
|
+
// `project.json` `generators`, in both flat (`@nx/jest:configuration`) and
|
|
15
|
+
// nested (`@nx/jest` → `configuration`) forms.
|
|
16
|
+
async function default_1(tree) {
|
|
17
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
18
|
+
if (nxJson?.generators && transformGenerators(nxJson.generators)) {
|
|
19
|
+
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
20
|
+
}
|
|
21
|
+
for (const [projectName, projectConfig] of (0, devkit_1.getProjects)(tree)) {
|
|
22
|
+
if (projectConfig.generators &&
|
|
23
|
+
transformGenerators(projectConfig.generators)) {
|
|
24
|
+
(0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfig);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
28
|
+
}
|
|
29
|
+
function transformGenerators(generators) {
|
|
30
|
+
let changed = false;
|
|
31
|
+
if (transformDefaults(generators[GENERATOR_NAME])) {
|
|
32
|
+
if (Object.keys(generators[GENERATOR_NAME]).length === 0) {
|
|
33
|
+
delete generators[GENERATOR_NAME];
|
|
34
|
+
}
|
|
35
|
+
changed = true;
|
|
36
|
+
}
|
|
37
|
+
const nested = generators[PACKAGE];
|
|
38
|
+
if (nested &&
|
|
39
|
+
typeof nested === 'object' &&
|
|
40
|
+
transformDefaults(nested[GENERATOR])) {
|
|
41
|
+
if (nested[GENERATOR] && Object.keys(nested[GENERATOR]).length === 0) {
|
|
42
|
+
delete nested[GENERATOR];
|
|
43
|
+
}
|
|
44
|
+
if (Object.keys(nested).length === 0) {
|
|
45
|
+
delete generators[PACKAGE];
|
|
46
|
+
}
|
|
47
|
+
changed = true;
|
|
48
|
+
}
|
|
49
|
+
return changed;
|
|
50
|
+
}
|
|
51
|
+
function transformDefaults(defaults) {
|
|
52
|
+
if (!defaults || typeof defaults !== 'object')
|
|
53
|
+
return false;
|
|
54
|
+
if (!(SKIP_SETUP_FILE in defaults))
|
|
55
|
+
return false;
|
|
56
|
+
if (defaults[SKIP_SETUP_FILE] === true &&
|
|
57
|
+
defaults[SETUP_FILE] === undefined) {
|
|
58
|
+
defaults[SETUP_FILE] = 'none';
|
|
59
|
+
}
|
|
60
|
+
delete defaults[SKIP_SETUP_FILE];
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
#### Migrate `skipSetupFile` Generator Default to `setupFile`
|
|
2
|
+
|
|
3
|
+
Migrates the previously deprecated `skipSetupFile` option of the `@nx/jest:configuration` generator. When set as a default in `nx.json` `generators` or per-project `project.json` `generators`, it is rewritten as follows:
|
|
4
|
+
|
|
5
|
+
- `skipSetupFile: true` becomes `setupFile: 'none'` (preserving the original behavior of skipping the setup file). Existing `setupFile` values are left untouched.
|
|
6
|
+
- `skipSetupFile: false` is dropped (it was a no-op).
|
|
7
|
+
|
|
8
|
+
Both flat (`@nx/jest:configuration`) and nested (`@nx/jest` → `configuration`) forms are handled.
|
|
9
|
+
|
|
10
|
+
#### Examples
|
|
11
|
+
|
|
12
|
+
Rewrite a `nx.json` generator default:
|
|
13
|
+
|
|
14
|
+
##### Before
|
|
15
|
+
|
|
16
|
+
```json title="nx.json" {4}
|
|
17
|
+
{
|
|
18
|
+
"generators": {
|
|
19
|
+
"@nx/jest:configuration": {
|
|
20
|
+
"skipSetupFile": true
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
##### After
|
|
27
|
+
|
|
28
|
+
```json title="nx.json"
|
|
29
|
+
{
|
|
30
|
+
"generators": {
|
|
31
|
+
"@nx/jest:configuration": {
|
|
32
|
+
"setupFile": "none"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Drop the option when set to `false`:
|
|
39
|
+
|
|
40
|
+
##### Before
|
|
41
|
+
|
|
42
|
+
```json title="nx.json" {4}
|
|
43
|
+
{
|
|
44
|
+
"generators": {
|
|
45
|
+
"@nx/jest:configuration": {
|
|
46
|
+
"skipSetupFile": false,
|
|
47
|
+
"testEnvironment": "jsdom"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
##### After
|
|
54
|
+
|
|
55
|
+
```json title="nx.json"
|
|
56
|
+
{
|
|
57
|
+
"generators": {
|
|
58
|
+
"@nx/jest:configuration": {
|
|
59
|
+
"testEnvironment": "jsdom"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Rewrite a per-project generator default:
|
|
66
|
+
|
|
67
|
+
##### Before
|
|
68
|
+
|
|
69
|
+
```json title="apps/myapp/project.json" {4}
|
|
70
|
+
{
|
|
71
|
+
"generators": {
|
|
72
|
+
"@nx/jest:configuration": {
|
|
73
|
+
"skipSetupFile": true
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
##### After
|
|
80
|
+
|
|
81
|
+
```json title="apps/myapp/project.json"
|
|
82
|
+
{
|
|
83
|
+
"generators": {
|
|
84
|
+
"@nx/jest:configuration": {
|
|
85
|
+
"setupFile": "none"
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
The nested form (`@nx/jest` → `configuration`) is handled the same way.
|