@nx/jest 23.0.0-beta.24 → 23.0.0-beta.25
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 -7
- package/package.json +6 -6
- package/dist/src/migrations/update-20-0-0/replace-getJestProjects-with-getJestProjectsAsync.d.ts +0 -2
- package/dist/src/migrations/update-20-0-0/replace-getJestProjects-with-getJestProjectsAsync.js +0 -86
- package/dist/src/migrations/update-20-0-0/replace-getJestProjects-with-getJestProjectsAsync.md +0 -25
package/migrations.json
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"generators": {
|
|
3
|
-
"replace-getJestProjects-with-getJestProjectsAsync": {
|
|
4
|
-
"cli": "nx",
|
|
5
|
-
"version": "20.0.0-beta.5",
|
|
6
|
-
"description": "Replace usage of `getJestProjects` with `getJestProjectsAsync`.",
|
|
7
|
-
"implementation": "./dist/src/migrations/update-20-0-0/replace-getJestProjects-with-getJestProjectsAsync",
|
|
8
|
-
"documentation": "./dist/src/migrations/update-20-0-0/replace-getJestProjects-with-getJestProjectsAsync.md"
|
|
9
|
-
},
|
|
10
3
|
"replace-getJestProjects-with-getJestProjectsAsync-v21": {
|
|
11
4
|
"cli": "nx",
|
|
12
5
|
"version": "21.0.0-beta.9",
|
package/package.json
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/jest",
|
|
3
|
-
"version": "23.0.0-beta.
|
|
3
|
+
"version": "23.0.0-beta.25",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist",
|
|
8
8
|
"!dist/tsconfig.tsbuildinfo",
|
|
9
|
-
"!dist/spec",
|
|
10
9
|
"migrations.json",
|
|
11
10
|
"executors.json",
|
|
12
11
|
"generators.json"
|
|
@@ -57,7 +56,8 @@
|
|
|
57
56
|
"executors": "./executors.json",
|
|
58
57
|
"ng-update": {
|
|
59
58
|
"requirements": {},
|
|
60
|
-
"migrations": "./migrations.json"
|
|
59
|
+
"migrations": "./migrations.json",
|
|
60
|
+
"supportsOptionalUpdates": true
|
|
61
61
|
},
|
|
62
62
|
"exports": {
|
|
63
63
|
".": {
|
|
@@ -116,11 +116,11 @@
|
|
|
116
116
|
"semver": "^7.6.3",
|
|
117
117
|
"tslib": "^2.3.0",
|
|
118
118
|
"yargs-parser": "21.1.1",
|
|
119
|
-
"@nx/devkit": "23.0.0-beta.
|
|
120
|
-
"@nx/js": "23.0.0-beta.
|
|
119
|
+
"@nx/devkit": "23.0.0-beta.25",
|
|
120
|
+
"@nx/js": "23.0.0-beta.25"
|
|
121
121
|
},
|
|
122
122
|
"devDependencies": {
|
|
123
|
-
"nx": "23.0.0-beta.
|
|
123
|
+
"nx": "23.0.0-beta.25"
|
|
124
124
|
},
|
|
125
125
|
"publishConfig": {
|
|
126
126
|
"access": "public"
|
package/dist/src/migrations/update-20-0-0/replace-getJestProjects-with-getJestProjectsAsync.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// go through the jest.config files
|
|
3
|
-
// see if it imports from @nx/jest and if it uses getJestProjects
|
|
4
|
-
// replace getJestProjects with getJestProjectsAsync
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.default = update;
|
|
7
|
-
const devkit_1 = require("@nx/devkit");
|
|
8
|
-
const internal_1 = require("@nx/js/internal");
|
|
9
|
-
let tsModule;
|
|
10
|
-
async function update(tree) {
|
|
11
|
-
if (!tsModule) {
|
|
12
|
-
tsModule = (0, internal_1.ensureTypescript)();
|
|
13
|
-
}
|
|
14
|
-
const jestConfigPaths = await (0, devkit_1.globAsync)(tree, [
|
|
15
|
-
'**/jest.config.{cjs,mjs,js,cts,mts,ts}',
|
|
16
|
-
]);
|
|
17
|
-
jestConfigPaths.forEach((jestConfigPath) => {
|
|
18
|
-
const oldContent = tree.read(jestConfigPath).toString();
|
|
19
|
-
if (oldContent?.includes('projects: getJestProjects()')) {
|
|
20
|
-
let sourceFile = tsModule.createSourceFile(jestConfigPath, oldContent, tsModule.ScriptTarget.Latest, true);
|
|
21
|
-
// find `require('@nx/jest')` or `import { getJestProjects } from '@nx/jest`
|
|
22
|
-
const requireStatement = sourceFile.statements.find((statement) => tsModule.isVariableStatement(statement) &&
|
|
23
|
-
statement.declarationList.declarations.some((declaration) => tsModule.isCallExpression(declaration.initializer) &&
|
|
24
|
-
tsModule.isIdentifier(declaration.initializer.expression) &&
|
|
25
|
-
declaration.initializer.expression.escapedText === 'require' &&
|
|
26
|
-
tsModule.isStringLiteral(declaration.initializer.arguments[0]) &&
|
|
27
|
-
declaration.initializer.arguments[0].text === '@nx/jest'));
|
|
28
|
-
const importStatement = sourceFile.statements.find((statement) => tsModule.isImportDeclaration(statement) &&
|
|
29
|
-
statement.moduleSpecifier.getText() === `'@nx/jest'`);
|
|
30
|
-
if (requireStatement || importStatement) {
|
|
31
|
-
// find `module.exports` statement with `projects: getJestProjects()`
|
|
32
|
-
const moduleExports = sourceFile.statements.find((statement) => tsModule.isExpressionStatement(statement) &&
|
|
33
|
-
tsModule.isBinaryExpression(statement.expression) &&
|
|
34
|
-
tsModule.isPropertyAccessExpression(statement.expression.left) &&
|
|
35
|
-
tsModule.isObjectLiteralExpression(statement.expression.right) &&
|
|
36
|
-
statement.expression.operatorToken.kind ===
|
|
37
|
-
tsModule.SyntaxKind.EqualsToken &&
|
|
38
|
-
tsModule.isIdentifier(statement.expression.left.expression) &&
|
|
39
|
-
statement.expression.left.expression.escapedText === 'module' &&
|
|
40
|
-
tsModule.isIdentifier(statement.expression.left.name) &&
|
|
41
|
-
statement.expression.left.name.escapedText === 'exports' &&
|
|
42
|
-
statement.expression.right.properties.some((property) => tsModule.isPropertyAssignment(property) &&
|
|
43
|
-
tsModule.isIdentifier(property.name) &&
|
|
44
|
-
property.name.escapedText === 'projects' &&
|
|
45
|
-
tsModule.isCallExpression(property.initializer) &&
|
|
46
|
-
tsModule.isIdentifier(property.initializer.expression) &&
|
|
47
|
-
property.initializer.expression.escapedText ===
|
|
48
|
-
'getJestProjects'));
|
|
49
|
-
if (moduleExports) {
|
|
50
|
-
// replace getJestProjects with getJestProjectsAsync in export statement
|
|
51
|
-
const rightExpression = moduleExports.expression.right.getText();
|
|
52
|
-
const newExpression = rightExpression.replace('getJestProjects()', 'await getJestProjectsAsync()');
|
|
53
|
-
const newStatement = `module.exports = async () => (${newExpression});`;
|
|
54
|
-
let newContent = oldContent.replace(moduleExports.getText(), newStatement);
|
|
55
|
-
// replace getJestProjects with getJestProjectsAsync in import statement
|
|
56
|
-
newContent = newContent.replace('getJestProjects', 'getJestProjectsAsync');
|
|
57
|
-
tree.write(jestConfigPath, newContent);
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
// find `export default` statement with `projects: getJestProjects()`
|
|
61
|
-
const exportAssignment = sourceFile.statements.find((statement) => tsModule.isExportAssignment(statement));
|
|
62
|
-
const defaultExport = exportAssignment?.expression &&
|
|
63
|
-
tsModule.isObjectLiteralExpression(exportAssignment?.expression)
|
|
64
|
-
? exportAssignment?.expression
|
|
65
|
-
: null;
|
|
66
|
-
const projectProperty = defaultExport?.properties.find((property) => tsModule.isPropertyAssignment(property) &&
|
|
67
|
-
property.name.getText() === 'projects' &&
|
|
68
|
-
tsModule.isCallExpression(property.initializer) &&
|
|
69
|
-
tsModule.isIdentifier(property.initializer.expression) &&
|
|
70
|
-
property.initializer.expression.escapedText === 'getJestProjects');
|
|
71
|
-
if (projectProperty) {
|
|
72
|
-
// replace getJestProjects with getJestProjectsAsync in export statement
|
|
73
|
-
const newExpression = defaultExport
|
|
74
|
-
.getText()
|
|
75
|
-
.replace('getJestProjects()', 'await getJestProjectsAsync()');
|
|
76
|
-
const newStatement = `export default async () => (${newExpression});`;
|
|
77
|
-
let newContent = oldContent.replace(exportAssignment.getText(), newStatement);
|
|
78
|
-
// replace getJestProjects with getJestProjectsAsync in import statement
|
|
79
|
-
newContent = newContent.replace('getJestProjects', 'getJestProjectsAsync');
|
|
80
|
-
tree.write(jestConfigPath, newContent);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
}
|
package/dist/src/migrations/update-20-0-0/replace-getJestProjects-with-getJestProjectsAsync.md
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
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
|
-
```
|