@nx/plugin 19.0.0-beta.1 → 19.0.0-beta.10
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/migrations.json +0 -18
- package/package.json +6 -8
- package/src/migrations/update-16-2-0/replace-e2e-executor.d.ts +5 -0
- package/executors.json +0 -10
- package/src/executors/e2e/e2e.impl.d.ts +0 -6
- package/src/executors/e2e/e2e.impl.js +0 -43
- package/src/executors/e2e/schema.d.ts +0 -6
- package/src/executors/e2e/schema.json +0 -220
- package/src/migrations/update-15-0-0/specify-output-capture.d.ts +0 -2
- package/src/migrations/update-15-0-0/specify-output-capture.js +0 -53
- package/src/migrations/update-15-9-0/jest-29-configs.d.ts +0 -3
- package/src/migrations/update-15-9-0/jest-29-configs.js +0 -147
- package/src/migrations/update-15-9-0/jest-29-tests.d.ts +0 -5
- package/src/migrations/update-15-9-0/jest-29-tests.js +0 -61
package/migrations.json
CHANGED
|
@@ -1,23 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"generators": {
|
|
3
|
-
"update-15-0-0": {
|
|
4
|
-
"cli": "nx",
|
|
5
|
-
"version": "15.0.0-beta.0",
|
|
6
|
-
"description": "Migrates executor schema files to v2",
|
|
7
|
-
"factory": "./src/migrations/update-15-0-0/specify-output-capture"
|
|
8
|
-
},
|
|
9
|
-
"update-configs-jest-29": {
|
|
10
|
-
"version": "15.9.0-beta.0",
|
|
11
|
-
"cli": "nx",
|
|
12
|
-
"description": "Update nx plugin jest configs to support jest 29 changes (https://jestjs.io/docs/upgrading-to-jest29)",
|
|
13
|
-
"factory": "./src/migrations/update-15-9-0/jest-29-configs"
|
|
14
|
-
},
|
|
15
|
-
"update-tests-jest-29": {
|
|
16
|
-
"version": "15.9.0-beta.0",
|
|
17
|
-
"cli": "nx",
|
|
18
|
-
"description": "Update nx plugin jest test files to support jest 29 changes (https://jestjs.io/docs/upgrading-to-jest29)",
|
|
19
|
-
"factory": "./src/migrations/update-15-9-0/jest-29-tests"
|
|
20
|
-
},
|
|
21
3
|
"update-remove-cli-prop": {
|
|
22
4
|
"version": "16.0.0-beta.1",
|
|
23
5
|
"cli": "nx",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/plugin",
|
|
3
|
-
"version": "19.0.0-beta.
|
|
3
|
+
"version": "19.0.0-beta.10",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "This plugin is used to create Nx plugins! It contains generators for generating common plugin features like generators, executors, migrations and more.",
|
|
6
6
|
"repository": {
|
|
@@ -22,20 +22,18 @@
|
|
|
22
22
|
},
|
|
23
23
|
"homepage": "https://nx.dev",
|
|
24
24
|
"generators": "./generators.json",
|
|
25
|
-
"executors": "./executors.json",
|
|
26
25
|
"ng-update": {
|
|
27
26
|
"requirements": {},
|
|
28
27
|
"migrations": "./migrations.json"
|
|
29
28
|
},
|
|
30
29
|
"dependencies": {
|
|
31
|
-
"@phenomnomnominal/tsquery": "~5.0.1",
|
|
32
30
|
"fs-extra": "^11.1.0",
|
|
33
31
|
"tslib": "^2.3.0",
|
|
34
|
-
"@nx/devkit": "19.0.0-beta.
|
|
35
|
-
"@nx/jest": "19.0.0-beta.
|
|
36
|
-
"@nx/js": "19.0.0-beta.
|
|
37
|
-
"@nx/eslint": "19.0.0-beta.
|
|
38
|
-
"@nrwl/nx-plugin": "19.0.0-beta.
|
|
32
|
+
"@nx/devkit": "19.0.0-beta.10",
|
|
33
|
+
"@nx/jest": "19.0.0-beta.10",
|
|
34
|
+
"@nx/js": "19.0.0-beta.10",
|
|
35
|
+
"@nx/eslint": "19.0.0-beta.10",
|
|
36
|
+
"@nrwl/nx-plugin": "19.0.0-beta.10"
|
|
39
37
|
},
|
|
40
38
|
"publishConfig": {
|
|
41
39
|
"access": "public"
|
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
import { Tree } from '@nx/devkit';
|
|
2
|
+
import { JestExecutorOptions } from '@nx/jest/src/executors/jest/schema';
|
|
3
|
+
export interface NxPluginE2EExecutorOptions extends JestExecutorOptions {
|
|
4
|
+
target: string;
|
|
5
|
+
jestConfig: string;
|
|
6
|
+
}
|
|
2
7
|
export default function replaceE2EExecutor(tree: Tree): Promise<void>;
|
package/executors.json
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"executors": {
|
|
3
|
-
"e2e": {
|
|
4
|
-
"implementation": "./src/executors/e2e/e2e.impl",
|
|
5
|
-
"schema": "./src/executors/e2e/schema.json",
|
|
6
|
-
"description": "Creates and runs the E2E tests for an Nx Plugin.",
|
|
7
|
-
"x-deprecated": "@nx/plugin:e2e is deprecated and will be removed in Nx v19. Use @nx/jest:jest instead."
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { ExecutorContext } from '@nx/devkit';
|
|
2
|
-
import type { NxPluginE2EExecutorOptions } from './schema';
|
|
3
|
-
export declare function nxPluginE2EExecutor(options: NxPluginE2EExecutorOptions, context: ExecutorContext): AsyncGenerator<{
|
|
4
|
-
success: boolean;
|
|
5
|
-
}>;
|
|
6
|
-
export default nxPluginE2EExecutor;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.nxPluginE2EExecutor = void 0;
|
|
4
|
-
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const jest_impl_1 = require("@nx/jest/src/executors/jest/jest.impl");
|
|
6
|
-
// TODO(v19): remove this
|
|
7
|
-
async function* nxPluginE2EExecutor(options, context) {
|
|
8
|
-
const { target, ...jestOptions } = options;
|
|
9
|
-
devkit_1.output.warn({
|
|
10
|
-
title: `"@nx/plugin:e2e" is deprecated and will be removed in Nx 19`,
|
|
11
|
-
bodyLines: [
|
|
12
|
-
'Use the "@nx/jest:jest" executor instead and set the following:',
|
|
13
|
-
`"dependsOn": ["${target}"]`,
|
|
14
|
-
],
|
|
15
|
-
});
|
|
16
|
-
let success;
|
|
17
|
-
for await (const _ of runBuildTarget(target, context)) {
|
|
18
|
-
try {
|
|
19
|
-
success = await runTests(jestOptions, context);
|
|
20
|
-
}
|
|
21
|
-
catch (e) {
|
|
22
|
-
devkit_1.logger.error(e.message);
|
|
23
|
-
success = false;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return { success };
|
|
27
|
-
}
|
|
28
|
-
exports.nxPluginE2EExecutor = nxPluginE2EExecutor;
|
|
29
|
-
async function* runBuildTarget(buildTarget, context) {
|
|
30
|
-
const { project, target, configuration } = (0, devkit_1.parseTargetString)(buildTarget, context);
|
|
31
|
-
const buildTargetOptions = (0, devkit_1.readTargetOptions)({ project, target, configuration }, context);
|
|
32
|
-
const targetSupportsWatch = Object.keys(buildTargetOptions).includes('watch');
|
|
33
|
-
for await (const output of await (0, devkit_1.runExecutor)({ project, target, configuration }, targetSupportsWatch ? { watch: false } : {}, context)) {
|
|
34
|
-
if (!output.success)
|
|
35
|
-
throw new Error('Could not compile application files.');
|
|
36
|
-
yield output.success;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
async function runTests(jestOptions, context) {
|
|
40
|
-
const { success } = await (0, jest_impl_1.jestExecutor)({ ...jestOptions, watch: false }, context);
|
|
41
|
-
return success;
|
|
42
|
-
}
|
|
43
|
-
exports.default = nxPluginE2EExecutor;
|
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 2,
|
|
3
|
-
"outputCapture": "direct-nodejs",
|
|
4
|
-
"title": "Nx Plugin Playground Target",
|
|
5
|
-
"description": "Creates a playground for a Nx Plugin.",
|
|
6
|
-
"cli": "nx",
|
|
7
|
-
"type": "object",
|
|
8
|
-
"properties": {
|
|
9
|
-
"target": {
|
|
10
|
-
"description": "The build target for the Nx Plugin project.",
|
|
11
|
-
"type": "string",
|
|
12
|
-
"x-priority": "important"
|
|
13
|
-
},
|
|
14
|
-
"jestConfig": {
|
|
15
|
-
"type": "string",
|
|
16
|
-
"description": "Jest config file.",
|
|
17
|
-
"x-completion-type": "file",
|
|
18
|
-
"x-completion-glob": "jest.config@(.js|.ts)",
|
|
19
|
-
"x-priority": "important"
|
|
20
|
-
},
|
|
21
|
-
"tsSpecConfig": {
|
|
22
|
-
"type": "string",
|
|
23
|
-
"description": "The tsconfig file for specs.",
|
|
24
|
-
"x-deprecated": "Use the `tsconfig` property for `ts-jest` in the e2e project `jest.config.js` file. It will be removed in the next major release.",
|
|
25
|
-
"x-completion-type": "file",
|
|
26
|
-
"x-completion-glob": "tsconfig.*.json",
|
|
27
|
-
"x-priority": "important"
|
|
28
|
-
},
|
|
29
|
-
"codeCoverage": {
|
|
30
|
-
"description": "Indicates that test coverage information should be collected and reported in the output. (https://jestjs.io/docs/cli#--coverageboolean)",
|
|
31
|
-
"type": "boolean",
|
|
32
|
-
"aliases": ["coverage"]
|
|
33
|
-
},
|
|
34
|
-
"config": {
|
|
35
|
-
"description": "The path to a Jest config file specifying how to find and execute tests. If no `rootDir` is set in the config, the directory containing the config file is assumed to be the `rootDir` for the project. This can also be a JSON-encoded value which Jest will use as configuration.",
|
|
36
|
-
"type": "string"
|
|
37
|
-
},
|
|
38
|
-
"clearCache": {
|
|
39
|
-
"description": "Deletes the Jest cache directory and then exits without running tests. Will delete Jest's default cache directory. _Note: clearing the cache will reduce performance_.",
|
|
40
|
-
"type": "boolean"
|
|
41
|
-
},
|
|
42
|
-
"detectOpenHandles": {
|
|
43
|
-
"description": "Attempt to collect and print open handles preventing Jest from exiting cleanly (https://jestjs.io/docs/cli#--detectopenhandles)",
|
|
44
|
-
"type": "boolean"
|
|
45
|
-
},
|
|
46
|
-
"logHeapUsage": {
|
|
47
|
-
"description": "Logs the heap usage after every test. Useful to debug memory leaks. Use together with --runInBand and --expose-gc in node.",
|
|
48
|
-
"type": "boolean"
|
|
49
|
-
},
|
|
50
|
-
"detectLeaks": {
|
|
51
|
-
"description": "**EXPERIMENTAL**: Detect memory leaks in tests. After executing a test, it will try to garbage collect the global object used, and fail if it was leaked",
|
|
52
|
-
"type": "boolean"
|
|
53
|
-
},
|
|
54
|
-
"testFile": {
|
|
55
|
-
"description": "The name of the file to test.",
|
|
56
|
-
"type": "string",
|
|
57
|
-
"x-completion-type": "file",
|
|
58
|
-
"x-completion-glob": "**/*.+(spec|test).+(ts|js)"
|
|
59
|
-
},
|
|
60
|
-
"tsConfig": {
|
|
61
|
-
"description": "The name of the Typescript configuration file. Set the tsconfig option in the jest config file. ",
|
|
62
|
-
"type": "string",
|
|
63
|
-
"x-deprecated": "Use the ts-jest configuration options in the jest config file instead."
|
|
64
|
-
},
|
|
65
|
-
"setupFile": {
|
|
66
|
-
"description": "The name of a setup file used by Jest. (use Jest config file https://jestjs.io/docs/en/configuration#setupfilesafterenv-array)",
|
|
67
|
-
"type": "string",
|
|
68
|
-
"x-deprecated": "Use the setupFilesAfterEnv option in the jest config file. https://jestjs.io/docs/en/configuration#setupfilesafterenv-array"
|
|
69
|
-
},
|
|
70
|
-
"bail": {
|
|
71
|
-
"alias": "b",
|
|
72
|
-
"description": "Exit the test suite immediately after `n` number of failing tests. (https://jestjs.io/docs/cli#--bail)",
|
|
73
|
-
"oneOf": [
|
|
74
|
-
{
|
|
75
|
-
"type": "number"
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
"type": "boolean"
|
|
79
|
-
}
|
|
80
|
-
]
|
|
81
|
-
},
|
|
82
|
-
"ci": {
|
|
83
|
-
"description": "Whether to run Jest in continuous integration (CI) mode. This option is on by default in most popular CI environments. It will prevent snapshots from being written unless explicitly requested. (https://jestjs.io/docs/cli#--ci)",
|
|
84
|
-
"type": "boolean"
|
|
85
|
-
},
|
|
86
|
-
"color": {
|
|
87
|
-
"alias": "colors",
|
|
88
|
-
"description": "Forces test results output color highlighting (even if `stdout` is not a TTY). Set to false if you would like to have no colors. (https://jestjs.io/docs/cli#--colors)",
|
|
89
|
-
"type": "boolean"
|
|
90
|
-
},
|
|
91
|
-
"findRelatedTests": {
|
|
92
|
-
"description": "Find and run the tests that cover a comma separated list of source files that were passed in as arguments. (https://jestjs.io/docs/cli#--findrelatedtests-spaceseparatedlistofsourcefiles)",
|
|
93
|
-
"type": "string"
|
|
94
|
-
},
|
|
95
|
-
"json": {
|
|
96
|
-
"description": "Prints the test results in `JSON`. This mode will send all other test output and user messages to `stderr`. (https://jestjs.io/docs/cli#--json)",
|
|
97
|
-
"type": "boolean"
|
|
98
|
-
},
|
|
99
|
-
"maxWorkers": {
|
|
100
|
-
"alias": "w",
|
|
101
|
-
"description": "Specifies the maximum number of workers the worker-pool will spawn for running tests. This defaults to the number of the cores available on your machine. Useful for CI. (its usually best not to override this default) (https://jestjs.io/docs/cli#--maxworkersnumstring)",
|
|
102
|
-
"oneOf": [
|
|
103
|
-
{
|
|
104
|
-
"type": "number"
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
"type": "string"
|
|
108
|
-
}
|
|
109
|
-
]
|
|
110
|
-
},
|
|
111
|
-
"onlyChanged": {
|
|
112
|
-
"alias": "o",
|
|
113
|
-
"description": "Attempts to identify which tests to run based on which files have changed in the current repository. Only works if you're running tests in a `git` or `hg` repository at the moment. (https://jestjs.io/docs/cli#--onlychanged)",
|
|
114
|
-
"type": "boolean"
|
|
115
|
-
},
|
|
116
|
-
"changedSince": {
|
|
117
|
-
"description": "Runs tests related to the changes since the provided branch or commit hash. If the current branch has diverged from the given branch, then only changes made locally will be tested. (https://jestjs.io/docs/cli#--changedsince)",
|
|
118
|
-
"type": "string"
|
|
119
|
-
},
|
|
120
|
-
"outputFile": {
|
|
121
|
-
"description": "Write test results to a file when the `--json` option is also specified. (https://jestjs.io/docs/cli#--outputfilefilename)",
|
|
122
|
-
"type": "string"
|
|
123
|
-
},
|
|
124
|
-
"passWithNoTests": {
|
|
125
|
-
"description": "Will not fail if no tests are found (for example while using `--testPathPattern`.) (https://jestjs.io/docs/cli#--passwithnotests)",
|
|
126
|
-
"type": "boolean"
|
|
127
|
-
},
|
|
128
|
-
"runInBand": {
|
|
129
|
-
"alias": "i",
|
|
130
|
-
"description": "Run all tests serially in the current process (rather than creating a worker pool of child processes that run tests). This is sometimes useful for debugging, but such use cases are pretty rare. Useful for CI. (https://jestjs.io/docs/cli#--runinband)",
|
|
131
|
-
"type": "boolean",
|
|
132
|
-
"default": true
|
|
133
|
-
},
|
|
134
|
-
"showConfig": {
|
|
135
|
-
"description": "Print your Jest config and then exits. (https://jestjs.io/docs/en/cli#--showconfig)",
|
|
136
|
-
"type": "boolean"
|
|
137
|
-
},
|
|
138
|
-
"silent": {
|
|
139
|
-
"description": "Prevent tests from printing messages through the console. (https://jestjs.io/docs/cli#--silent)",
|
|
140
|
-
"type": "boolean"
|
|
141
|
-
},
|
|
142
|
-
"testNamePattern": {
|
|
143
|
-
"alias": "t",
|
|
144
|
-
"description": "Run only tests with a name that matches the regex pattern. (https://jestjs.io/docs/cli#--testnamepatternregex)",
|
|
145
|
-
"type": "string"
|
|
146
|
-
},
|
|
147
|
-
"testPathIgnorePatterns": {
|
|
148
|
-
"description": "An array of regexp pattern strings that is matched against all tests paths before executing the test. Only run those tests with a path that does not match with the provided regexp expressions. (https://jestjs.io/docs/cli#--testpathignorepatternsregexarray)",
|
|
149
|
-
"type": "array",
|
|
150
|
-
"items": {
|
|
151
|
-
"type": "string"
|
|
152
|
-
}
|
|
153
|
-
},
|
|
154
|
-
"testPathPattern": {
|
|
155
|
-
"description": "An array of regexp pattern strings that is matched against all tests paths before executing the test. (https://jestjs.io/docs/cli#--testpathpatternregex)",
|
|
156
|
-
"type": "array",
|
|
157
|
-
"items": {
|
|
158
|
-
"type": "string"
|
|
159
|
-
},
|
|
160
|
-
"default": []
|
|
161
|
-
},
|
|
162
|
-
"colors": {
|
|
163
|
-
"description": "Forces test results output highlighting even if stdout is not a TTY. (https://jestjs.io/docs/cli#--colors)",
|
|
164
|
-
"type": "boolean"
|
|
165
|
-
},
|
|
166
|
-
"reporters": {
|
|
167
|
-
"description": "Run tests with specified reporters. Reporter options are not available via CLI. Example with multiple reporters: `jest --reporters=\"default\" --reporters=\"jest-junit\"`. (https://jestjs.io/docs/cli#--reporters)",
|
|
168
|
-
"type": "array",
|
|
169
|
-
"items": {
|
|
170
|
-
"type": "string"
|
|
171
|
-
}
|
|
172
|
-
},
|
|
173
|
-
"verbose": {
|
|
174
|
-
"description": "Display individual test results with the test suite hierarchy. (https://jestjs.io/docs/cli#--verbose)",
|
|
175
|
-
"type": "boolean"
|
|
176
|
-
},
|
|
177
|
-
"coverageReporters": {
|
|
178
|
-
"description": "A list of reporter names that Jest uses when writing coverage reports. Any istanbul reporter.",
|
|
179
|
-
"type": "array",
|
|
180
|
-
"items": {
|
|
181
|
-
"type": "string"
|
|
182
|
-
}
|
|
183
|
-
},
|
|
184
|
-
"coverageDirectory": {
|
|
185
|
-
"description": "The directory where Jest should output its coverage files.",
|
|
186
|
-
"type": "string"
|
|
187
|
-
},
|
|
188
|
-
"testResultsProcessor": {
|
|
189
|
-
"description": "Node module that implements a custom results processor. (https://jestjs.io/docs/en/configuration#testresultsprocessor-string)",
|
|
190
|
-
"type": "string"
|
|
191
|
-
},
|
|
192
|
-
"updateSnapshot": {
|
|
193
|
-
"alias": "u",
|
|
194
|
-
"description": "Use this flag to re-record snapshots. Can be used together with a test suite pattern or with `--testNamePattern` to re-record snapshot for test matching the pattern. (https://jestjs.io/docs/cli#--updatesnapshot)",
|
|
195
|
-
"type": "boolean"
|
|
196
|
-
},
|
|
197
|
-
"useStderr": {
|
|
198
|
-
"description": "Divert all output to stderr.",
|
|
199
|
-
"type": "boolean"
|
|
200
|
-
},
|
|
201
|
-
"watch": {
|
|
202
|
-
"description": "Watch files for changes and rerun tests related to changed files. If you want to re-run all tests when a file has changed, use the `--watchAll` option. (https://jestjs.io/docs/cli#--watch)",
|
|
203
|
-
"type": "boolean"
|
|
204
|
-
},
|
|
205
|
-
"watchAll": {
|
|
206
|
-
"description": "Watch files for changes and rerun all tests when something changes. If you want to re-run only the tests that depend on the changed files, use the `--watch` option. (https://jestjs.io/docs/cli#--watchall)",
|
|
207
|
-
"type": "boolean"
|
|
208
|
-
},
|
|
209
|
-
"testLocationInResults": {
|
|
210
|
-
"description": "Adds a location field to test results. Used to report location of a test in a reporter. { \"column\": 4, \"line\": 5 } (https://jestjs.io/docs/cli#--testlocationinresults)",
|
|
211
|
-
"type": "boolean"
|
|
212
|
-
},
|
|
213
|
-
"testTimeout": {
|
|
214
|
-
"description": "Default timeout of a test in milliseconds. Default value: `5000`. (https://jestjs.io/docs/cli#--testtimeoutnumber)",
|
|
215
|
-
"type": "number"
|
|
216
|
-
}
|
|
217
|
-
},
|
|
218
|
-
"additionalProperties": false,
|
|
219
|
-
"required": ["target", "jestConfig"]
|
|
220
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const devkit_1 = require("@nx/devkit");
|
|
4
|
-
async function update(tree) {
|
|
5
|
-
for (const [project, { root }] of (0, devkit_1.getProjects)(tree)) {
|
|
6
|
-
const packageJsonPath = (0, devkit_1.joinPathFragments)(root, 'package.json');
|
|
7
|
-
if (!tree.exists(packageJsonPath)) {
|
|
8
|
-
continue;
|
|
9
|
-
}
|
|
10
|
-
const packageJson = (0, devkit_1.readJson)(tree, packageJsonPath);
|
|
11
|
-
if (!packageJson.executors && !packageJson.builders) {
|
|
12
|
-
continue;
|
|
13
|
-
}
|
|
14
|
-
const paths = [packageJson.executors, packageJson.builders].filter(Boolean);
|
|
15
|
-
for (const collectionPathSegment of paths) {
|
|
16
|
-
const collectionPath = (0, devkit_1.joinPathFragments)(root, collectionPathSegment);
|
|
17
|
-
if (!tree.exists(collectionPath)) {
|
|
18
|
-
continue;
|
|
19
|
-
}
|
|
20
|
-
const collectionFile = (0, devkit_1.readJson)(tree, collectionPath);
|
|
21
|
-
const collections = [
|
|
22
|
-
collectionFile.builders,
|
|
23
|
-
collectionFile.executors,
|
|
24
|
-
].filter(Boolean);
|
|
25
|
-
for (const collection of collections) {
|
|
26
|
-
if (!collection) {
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
for (const entry of Object.values(collection)) {
|
|
30
|
-
const schemaPath = (0, devkit_1.joinPathFragments)(root, entry.schema);
|
|
31
|
-
if (tree.exists(schemaPath)) {
|
|
32
|
-
(0, devkit_1.updateJson)(tree, schemaPath, (json) => {
|
|
33
|
-
if (json.version) {
|
|
34
|
-
return json;
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
const newProperties = {
|
|
38
|
-
version: 2,
|
|
39
|
-
};
|
|
40
|
-
if (!json.outputCapture) {
|
|
41
|
-
newProperties.outputCapture = 'direct-nodejs';
|
|
42
|
-
}
|
|
43
|
-
return { ...newProperties, ...json };
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
await (0, devkit_1.formatFiles)(tree);
|
|
52
|
-
}
|
|
53
|
-
exports.default = update;
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.updateConfigsJest29 = void 0;
|
|
4
|
-
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const tsquery_1 = require("@phenomnomnominal/tsquery");
|
|
6
|
-
const ts = require("typescript");
|
|
7
|
-
const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
|
|
8
|
-
const ast_utils_1 = require("@nx/jest/src/utils/ast-utils");
|
|
9
|
-
const find_root_jest_files_1 = require("@nx/jest/src/utils/config/find-root-jest-files");
|
|
10
|
-
// NOTE: this is a copy of the @nrwl/jest v15.8.0 migrations
|
|
11
|
-
async function updateConfigsJest29(tree) {
|
|
12
|
-
const rootPreset = (0, find_root_jest_files_1.findRootJestPreset)(tree);
|
|
13
|
-
const targetsWithJest = new Set();
|
|
14
|
-
// have to use graph so the negative configuration targets are expanded
|
|
15
|
-
const graph = await (0, devkit_1.createProjectGraphAsync)();
|
|
16
|
-
(0, executor_options_utils_1.forEachExecutorOptionsInGraph)(graph, '@nrwl/nx-plugin:e2e', (options, projectName, targetName) => {
|
|
17
|
-
if (options.jestConfig && tree.exists(options.jestConfig)) {
|
|
18
|
-
targetsWithJest.add(targetName);
|
|
19
|
-
// if the default root preset exists or if the project doesn't have a 'preset' configured
|
|
20
|
-
// -> update snapshot config
|
|
21
|
-
if (!rootPreset || !hasPresetConfigured(tree, options.jestConfig)) {
|
|
22
|
-
addSnapshotOptionsToConfig(tree, options.jestConfig, `From within the project directory, run "nx test --update-snapshot"`);
|
|
23
|
-
}
|
|
24
|
-
updateTsJestOptions(tree, options.jestConfig);
|
|
25
|
-
updateNgJestOptions(tree, options.jestConfig);
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
if (rootPreset && tree.exists(rootPreset)) {
|
|
29
|
-
const cmd = `"nx affected --targets=${Array.from(targetsWithJest).join(',')} --update-snapshot"`;
|
|
30
|
-
addSnapshotOptionsToConfig(tree, rootPreset, cmd);
|
|
31
|
-
updateTsJestOptions(tree, rootPreset);
|
|
32
|
-
updateNgJestOptions(tree, rootPreset);
|
|
33
|
-
}
|
|
34
|
-
await (0, devkit_1.formatFiles)(tree);
|
|
35
|
-
devkit_1.logger.info((0, devkit_1.stripIndents) `NX Jest Snapshot format changed in v29.
|
|
36
|
-
By default Nx kept the older style to prevent breaking of existing tests with snapshots.
|
|
37
|
-
It's recommend you update to the latest format.
|
|
38
|
-
You can do this in your project's jest config file.
|
|
39
|
-
Remove the snapshotFormat property and re-run tests with the --update-snapshot flag.
|
|
40
|
-
More info: https://jestjs.io/docs/upgrading-to-jest29#snapshot-format`);
|
|
41
|
-
}
|
|
42
|
-
exports.updateConfigsJest29 = updateConfigsJest29;
|
|
43
|
-
function addSnapshotOptionsToConfig(tree, configPath, updateSnapshotExample) {
|
|
44
|
-
const config = tree.read(configPath, 'utf-8');
|
|
45
|
-
const hasSnapshotOptions = tsquery_1.tsquery.query(config, `${ast_utils_1.TS_QUERY_JEST_CONFIG_PREFIX} > ObjectLiteralExpression PropertyAssignment:has(Identifier[name="snapshotFormat"])`);
|
|
46
|
-
if (hasSnapshotOptions.length > 0) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
const updatedConfig = tsquery_1.tsquery.replace(config, `${ast_utils_1.TS_QUERY_JEST_CONFIG_PREFIX} > ObjectLiteralExpression`, (node) => {
|
|
50
|
-
return `{
|
|
51
|
-
${node.properties.map((p) => getNodeWithComments(config, p)).join(',\n')},
|
|
52
|
-
/* TODO: Update to latest Jest snapshotFormat
|
|
53
|
-
* By default Nx has kept the older style of Jest Snapshot formats
|
|
54
|
-
* to prevent breaking of any existing tests with snapshots.
|
|
55
|
-
* It's recommend you update to the latest format.
|
|
56
|
-
* You can do this by removing snapshotFormat property
|
|
57
|
-
* and running tests with --update-snapshot flag.
|
|
58
|
-
* Example: ${updateSnapshotExample}
|
|
59
|
-
* More info: https://jestjs.io/docs/upgrading-to-jest29#snapshot-format
|
|
60
|
-
*/
|
|
61
|
-
snapshotFormat: { escapeString: true, printBasicPrototype: true }
|
|
62
|
-
}`;
|
|
63
|
-
}, { visitAllChildren: false });
|
|
64
|
-
tree.write(configPath, updatedConfig);
|
|
65
|
-
}
|
|
66
|
-
function hasPresetConfigured(tree, configPath) {
|
|
67
|
-
const contents = tree.read(configPath, 'utf-8');
|
|
68
|
-
return (tsquery_1.tsquery.query(contents, `${ast_utils_1.TS_QUERY_JEST_CONFIG_PREFIX} > ObjectLiteralExpression PropertyAssignment:has(Identifier[name="preset"])`)?.length > 0);
|
|
69
|
-
}
|
|
70
|
-
function updateTsJestOptions(tree, configPath) {
|
|
71
|
-
// query for the globals property, if they don't have one then there's nothing to modify.
|
|
72
|
-
const contents = tree.read(configPath, 'utf-8');
|
|
73
|
-
let tsJestGlobalsConfig;
|
|
74
|
-
const noTsJestGlobals = tsquery_1.tsquery.replace(contents, `${ast_utils_1.TS_QUERY_JEST_CONFIG_PREFIX} > ObjectLiteralExpression PropertyAssignment:has(Identifier[name="globals"])`, (node) => {
|
|
75
|
-
if (tsJestGlobalsConfig) {
|
|
76
|
-
devkit_1.logger.warn((0, devkit_1.stripIndents) `Found more than one "globals" object in the jest config, ${configPath}
|
|
77
|
-
Will use the first one`);
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
tsJestGlobalsConfig = getGlobalTsJestConfig(node);
|
|
81
|
-
return getGlobalConfigWithoutTsJest(node);
|
|
82
|
-
});
|
|
83
|
-
if (!tsJestGlobalsConfig) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
const updatedTsJestTransformer = tsquery_1.tsquery.replace(noTsJestGlobals, `${ast_utils_1.TS_QUERY_JEST_CONFIG_PREFIX}> ObjectLiteralExpression PropertyAssignment:has(Identifier[name="transform"]) PropertyAssignment > :has(StringLiteral[value="ts-jest"], StringLiteral[value="jest-preset-angular"])`, (node) => {
|
|
87
|
-
return `[${node.getText()}, ${tsJestGlobalsConfig}]`;
|
|
88
|
-
});
|
|
89
|
-
tree.write(configPath, updatedTsJestTransformer);
|
|
90
|
-
}
|
|
91
|
-
function updateNgJestOptions(tree, configPath) {
|
|
92
|
-
const contents = tree.read(configPath, 'utf-8');
|
|
93
|
-
let ngJestTeardownConfig;
|
|
94
|
-
const noTeardownConfig = tsquery_1.tsquery.replace(contents, 'BinaryExpression:has(PropertyAccessExpression:has(Identifier[name=ngJest])) PropertyAssignment:has(Identifier[name=teardown])', (node) => {
|
|
95
|
-
ngJestTeardownConfig = node.initializer.getText();
|
|
96
|
-
return ' ';
|
|
97
|
-
});
|
|
98
|
-
if (!ngJestTeardownConfig) {
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
let maybeUpdatedTestEnvOpts = tsquery_1.tsquery.replace(noTeardownConfig, `${ast_utils_1.TS_QUERY_JEST_CONFIG_PREFIX} > ObjectLiteralExpression PropertyAssignment:has(Identifier[name="testEnvironmentOptions"]) ObjectLiteralExpression`, (node) => {
|
|
102
|
-
return `{
|
|
103
|
-
${node.properties
|
|
104
|
-
.map((p) => getNodeWithComments(noTeardownConfig, p))
|
|
105
|
-
.join(',\n')},
|
|
106
|
-
teardown: ${ngJestTeardownConfig}
|
|
107
|
-
}`;
|
|
108
|
-
});
|
|
109
|
-
if (maybeUpdatedTestEnvOpts !== noTeardownConfig) {
|
|
110
|
-
tree.write(configPath, maybeUpdatedTestEnvOpts);
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
// didn't find existing testEnvironmentOptions, so add the new property
|
|
114
|
-
const updatedConfig = tsquery_1.tsquery.replace(maybeUpdatedTestEnvOpts, `${ast_utils_1.TS_QUERY_JEST_CONFIG_PREFIX} > ObjectLiteralExpression`, (node) => {
|
|
115
|
-
return `{
|
|
116
|
-
${node.properties
|
|
117
|
-
.map((p) => getNodeWithComments(maybeUpdatedTestEnvOpts, p))
|
|
118
|
-
.join(',\n')},
|
|
119
|
-
testEnvironmentOptions: { teardown: ${ngJestTeardownConfig} },
|
|
120
|
-
}`;
|
|
121
|
-
}, { visitAllChildren: false });
|
|
122
|
-
tree.write(configPath, updatedConfig);
|
|
123
|
-
}
|
|
124
|
-
function getGlobalTsJestConfig(node) {
|
|
125
|
-
const globalObject = node.initializer;
|
|
126
|
-
const foundConfig = globalObject.properties.find((p) => ts.isPropertyAssignment(p) && p.name.getText().includes('ts-jest'));
|
|
127
|
-
return foundConfig?.initializer?.getText() || '';
|
|
128
|
-
}
|
|
129
|
-
function getGlobalConfigWithoutTsJest(node) {
|
|
130
|
-
const globalObject = node?.initializer;
|
|
131
|
-
const withoutTsJest = globalObject?.properties?.filter((p) => {
|
|
132
|
-
return !(ts.isPropertyAssignment(p) && p.name.getText().includes('ts-jest'));
|
|
133
|
-
});
|
|
134
|
-
const globalConfigs = withoutTsJest.map((c) => c.getText()).join(',\n');
|
|
135
|
-
return `globals: { ${globalConfigs} }`;
|
|
136
|
-
}
|
|
137
|
-
function getNodeWithComments(fullText, node) {
|
|
138
|
-
const commentRanges = ts.getLeadingCommentRanges(fullText, node.getFullStart());
|
|
139
|
-
if (commentRanges?.length > 0) {
|
|
140
|
-
const withComments = `${commentRanges
|
|
141
|
-
.map((r) => fullText.slice(r.pos, r.end))
|
|
142
|
-
.join('\n')}\n${node.getText()}`;
|
|
143
|
-
return withComments;
|
|
144
|
-
}
|
|
145
|
-
return node.getText();
|
|
146
|
-
}
|
|
147
|
-
exports.default = updateConfigsJest29;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { Tree } from '@nx/devkit';
|
|
2
|
-
export declare function updateTestsJest29(tree: Tree): Promise<void>;
|
|
3
|
-
export declare function updateJestMockTypes(tree: Tree, filePath: string): void;
|
|
4
|
-
export declare function updateJestMocked(tree: Tree, filePath: string): void;
|
|
5
|
-
export default updateTestsJest29;
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.updateJestMocked = exports.updateJestMockTypes = exports.updateTestsJest29 = void 0;
|
|
4
|
-
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const ast_utils_1 = require("@nx/jest/src/utils/ast-utils");
|
|
6
|
-
const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
|
|
7
|
-
const tsquery_1 = require("@phenomnomnominal/tsquery");
|
|
8
|
-
// NOTE: this is a copy of the @nrwl/jest v15.8.0 migrations
|
|
9
|
-
async function updateTestsJest29(tree) {
|
|
10
|
-
const graph = await (0, devkit_1.createProjectGraphAsync)();
|
|
11
|
-
(0, executor_options_utils_1.forEachExecutorOptionsInGraph)(graph, '@nrwl/nx-plugin:e2e', (options, projectName) => {
|
|
12
|
-
const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, projectName);
|
|
13
|
-
(0, devkit_1.visitNotIgnoredFiles)(tree, projectConfig.sourceRoot || projectConfig.root, (file) => {
|
|
14
|
-
if (!ast_utils_1.TEST_FILE_PATTERN.test(file)) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
updateJestMockTypes(tree, file);
|
|
18
|
-
updateJestMocked(tree, file);
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
await (0, devkit_1.formatFiles)(tree);
|
|
22
|
-
}
|
|
23
|
-
exports.updateTestsJest29 = updateTestsJest29;
|
|
24
|
-
function updateJestMockTypes(tree, filePath) {
|
|
25
|
-
const contents = tree.read(filePath, 'utf-8');
|
|
26
|
-
const updatedContent = tsquery_1.tsquery.replace(contents, ':matches(ImportDeclaration, VariableStatement):has(Identifier[name="MaybeMockedDeep"], Identifier[name="MaybeMocked"]):has(StringLiteral[value="jest-mock"])', (node) => {
|
|
27
|
-
const text = node.getText();
|
|
28
|
-
return (text
|
|
29
|
-
// MaybeMockedDeep and MaybeMocked now are exported as Mocked and MockedShallow
|
|
30
|
-
.replace('MaybeMockedDeep', 'Mocked')
|
|
31
|
-
.replace('MaybeMocked', 'MockedShallow'));
|
|
32
|
-
});
|
|
33
|
-
tree.write(filePath, updatedContent);
|
|
34
|
-
}
|
|
35
|
-
exports.updateJestMockTypes = updateJestMockTypes;
|
|
36
|
-
function updateJestMocked(tree, filePath) {
|
|
37
|
-
const contents = tree.read(filePath, 'utf-8');
|
|
38
|
-
const jestGlobalNodes = tsquery_1.tsquery.query(contents, ':matches(ImportDeclaration, VariableStatement):has(Identifier[name="jest"]):has(StringLiteral[value="@jest/globals"])');
|
|
39
|
-
// this only applies if using jest from @jest/globals
|
|
40
|
-
if (jestGlobalNodes.length === 0) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
const updatedJestMockTypes = tsquery_1.tsquery.replace(contents, 'CallExpression:has(Identifier[name="jest"]):has(Identifier[name="mocked"])', (node) => {
|
|
44
|
-
if (node.arguments.length === 2 &&
|
|
45
|
-
node.getText().startsWith('jest.mocked(')) {
|
|
46
|
-
const text = node.getText();
|
|
47
|
-
// jest.mocked(someObject, true); => jest.mocked(someObject);
|
|
48
|
-
if (node.arguments[1].getText() === 'true') {
|
|
49
|
-
return text.replace(/,\s*true/g, '');
|
|
50
|
-
}
|
|
51
|
-
// jest.mocked(someObject, false); => jest.mocked(someObject, {shallow: true});
|
|
52
|
-
// opt into the new behavior unless explicitly opting out
|
|
53
|
-
if (node.arguments[1].getText() === 'false') {
|
|
54
|
-
return text.replace('false', '{shallow: true}');
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
tree.write(filePath, updatedJestMockTypes);
|
|
59
|
-
}
|
|
60
|
-
exports.updateJestMocked = updateJestMocked;
|
|
61
|
-
exports.default = updateTestsJest29;
|