@nx/jest 23.0.0-beta.14 → 23.0.0-beta.16
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/{preset → dist/preset}/index.d.ts +0 -1
- package/{preset → dist/preset}/jest-preset.d.ts +0 -1
- 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 +2 -2
- 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/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-jest-config.d.ts +0 -1
- 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-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/init/init.d.ts +0 -1
- package/{src → dist/src}/migrations/update-20-0-0/replace-getJestProjects-with-getJestProjectsAsync.d.ts +0 -1
- package/{src → dist/src}/migrations/update-21-0-0/remove-tsconfig-option-from-jest-executor.d.ts +0 -1
- package/{src → dist/src}/migrations/update-21-0-0/replace-getJestProjects-with-getJestProjectsAsync.d.ts +0 -1
- 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/replace-removed-matcher-aliases.d.ts +0 -1
- package/{src → dist/src}/migrations/update-22-2-0/convert-jest-config-to-cjs.d.ts +0 -1
- 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 +186 -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/{src → dist/src}/migrations/update-23-0-0/update-snapshot-guide-link.d.ts +0 -1
- package/{src → dist/src}/plugins/plugin.d.ts +0 -1
- 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/get-jest-projects.d.ts +0 -1
- package/{src → dist/src}/utils/config/update-config.d.ts +0 -1
- package/{src → dist/src}/utils/deprecation.d.ts +0 -1
- 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 +2 -1
- package/executors.json +3 -3
- package/generators.json +6 -6
- package/migrations.json +18 -8
- package/package.json +63 -8
- 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/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/migrations/update-23-0-0/update-snapshot-guide-link.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/deprecation.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/{plugins → dist/plugins}/resolver.js +0 -0
- /package/{preset → dist/preset}/index.js +0 -0
- /package/{preset → dist/preset}/jest-preset.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/schema.json +0 -0
- /package/{src → dist/src}/executors/jest/summary.js +0 -0
- /package/{src → dist/src}/generators/configuration/configuration.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/create-files.js +0 -0
- /package/{src → dist/src}/generators/configuration/lib/create-jest-config.js +0 -0
- /package/{src → dist/src}/generators/configuration/lib/ensure-dependencies.js +0 -0
- /package/{src → dist/src}/generators/configuration/lib/update-tsconfig.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/convert-to-inferred.js +0 -0
- /package/{src → dist/src}/generators/convert-to-inferred/schema.json +0 -0
- /package/{src → dist/src}/generators/init/init.js +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-20-0-0/replace-getJestProjects-with-getJestProjectsAsync.js +0 -0
- /package/{src → dist/src}/migrations/update-21-0-0/remove-tsconfig-option-from-jest-executor.js +0 -0
- /package/{src → dist/src}/migrations/update-21-0-0/replace-getJestProjects-with-getJestProjectsAsync.js +0 -0
- /package/{src → dist/src}/migrations/update-21-3-0/rename-test-path-pattern.js +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}/migrations/update-23-0-0/update-snapshot-guide-link.js +0 -0
- /package/{src → dist/src}/plugins/plugin.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/functions.js +0 -0
- /package/{src → dist/src}/utils/config/get-jest-projects.js +0 -0
- /package/{src → dist/src}/utils/config/update-config.js +0 -0
- /package/{src → dist/src}/utils/deprecation.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 {};
|
|
@@ -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,6 +10,7 @@ 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");
|
|
@@ -44,8 +45,7 @@ async function parseJestConfig(options, context, multiProjects = false) {
|
|
|
44
45
|
let jestConfig;
|
|
45
46
|
// support passing extra args to jest cli supporting 3rd party plugins
|
|
46
47
|
// like 'jest-runner-groups' --group arg
|
|
47
|
-
const
|
|
48
|
-
const extraArgs = getExtraArgs(options, schema);
|
|
48
|
+
const extraArgs = getExtraArgs(options, schema_json_1.default);
|
|
49
49
|
const config = {
|
|
50
50
|
...extraArgs,
|
|
51
51
|
$0: undefined,
|
|
@@ -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
|
|
@@ -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,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
|
|
@@ -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
|
|
@@ -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
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = rewriteInternalSubpathImports;
|
|
4
|
+
exports.rewriteSubpathImports = rewriteSubpathImports;
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const TS_EXTENSIONS = ['.ts', '.tsx', '.cts', '.mts'];
|
|
7
|
+
const FROM_PREFIX = '@nx/jest/src/';
|
|
8
|
+
const TO_PUBLIC = '@nx/jest';
|
|
9
|
+
const TO_INTERNAL = '@nx/jest/internal';
|
|
10
|
+
// Symbols exported from `@nx/jest`'s public entry (packages/jest/index.ts).
|
|
11
|
+
// A named import/export of one of these from `@nx/jest/src/*` is routed to
|
|
12
|
+
// the public `@nx/jest` entry; everything else goes to `@nx/jest/internal`.
|
|
13
|
+
const PUBLIC_SYMBOLS = new Set([
|
|
14
|
+
'configurationGenerator',
|
|
15
|
+
'jestInitGenerator',
|
|
16
|
+
'addPropertyToJestConfig',
|
|
17
|
+
'removePropertyFromJestConfig',
|
|
18
|
+
'jestConfigObjectAst',
|
|
19
|
+
'getJestProjectsAsync',
|
|
20
|
+
'findJestConfig',
|
|
21
|
+
]);
|
|
22
|
+
// Methods on `jest` and `vi` that take a module specifier as their first arg.
|
|
23
|
+
const MOCK_HELPER_METHODS = new Set([
|
|
24
|
+
'mock',
|
|
25
|
+
'unmock',
|
|
26
|
+
'doMock',
|
|
27
|
+
'dontMock',
|
|
28
|
+
'requireActual',
|
|
29
|
+
'requireMock',
|
|
30
|
+
'importActual',
|
|
31
|
+
'importMock',
|
|
32
|
+
]);
|
|
33
|
+
let ts;
|
|
34
|
+
async function rewriteInternalSubpathImports(tree) {
|
|
35
|
+
let touchedCount = 0;
|
|
36
|
+
(0, devkit_1.visitNotIgnoredFiles)(tree, '.', (filePath) => {
|
|
37
|
+
if (!TS_EXTENSIONS.some((ext) => filePath.endsWith(ext))) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const original = tree.read(filePath, 'utf-8');
|
|
41
|
+
if (!original || !original.includes(FROM_PREFIX)) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const updated = rewriteSubpathImports(original);
|
|
45
|
+
if (updated !== original) {
|
|
46
|
+
tree.write(filePath, updated);
|
|
47
|
+
touchedCount += 1;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
if (touchedCount > 0) {
|
|
51
|
+
devkit_1.logger.info(`Rewrote @nx/jest/src/* imports in ${touchedCount} file(s) ` +
|
|
52
|
+
`(public symbols to @nx/jest, internals to @nx/jest/internal).`);
|
|
53
|
+
}
|
|
54
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
55
|
+
}
|
|
56
|
+
function rewriteSubpathImports(source) {
|
|
57
|
+
ts ??= (0, devkit_1.ensurePackage)('typescript', '*');
|
|
58
|
+
const sourceFile = ts.createSourceFile('tmp.ts', source, ts.ScriptTarget.Latest,
|
|
59
|
+
/* setParentNodes */ true, ts.ScriptKind.TSX);
|
|
60
|
+
const changes = [];
|
|
61
|
+
for (const stmt of sourceFile.statements) {
|
|
62
|
+
if (ts.isImportDeclaration(stmt)) {
|
|
63
|
+
collectImportRewrite(sourceFile, stmt, changes);
|
|
64
|
+
}
|
|
65
|
+
else if (ts.isExportDeclaration(stmt)) {
|
|
66
|
+
collectExportRewrite(sourceFile, stmt, changes);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
collectCallExpressionRewrites(sourceFile, changes);
|
|
70
|
+
return changes.length > 0 ? (0, devkit_1.applyChangesToString)(source, changes) : source;
|
|
71
|
+
}
|
|
72
|
+
function isSubpathSpecifier(node) {
|
|
73
|
+
return ts.isStringLiteral(node) && node.text.startsWith(FROM_PREFIX);
|
|
74
|
+
}
|
|
75
|
+
function collectImportRewrite(sourceFile, stmt, changes) {
|
|
76
|
+
if (!isSubpathSpecifier(stmt.moduleSpecifier)) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const clause = stmt.importClause;
|
|
80
|
+
// Pure named imports (`import { a, b } from '...'`) can be split by symbol.
|
|
81
|
+
// A default or namespace import grabs the whole module, so it can't be
|
|
82
|
+
// split — route it wholesale to the internal entry.
|
|
83
|
+
if (clause &&
|
|
84
|
+
!clause.name &&
|
|
85
|
+
clause.namedBindings &&
|
|
86
|
+
ts.isNamedImports(clause.namedBindings)) {
|
|
87
|
+
rewriteNamedDeclaration(sourceFile, stmt, stmt.moduleSpecifier, clause.isTypeOnly, clause.namedBindings.elements, 'import', changes);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
replaceSpecifier(sourceFile, stmt.moduleSpecifier, TO_INTERNAL, changes);
|
|
91
|
+
}
|
|
92
|
+
function collectExportRewrite(sourceFile, stmt, changes) {
|
|
93
|
+
if (!stmt.moduleSpecifier || !isSubpathSpecifier(stmt.moduleSpecifier)) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
// `export { a, b } from '...'` can be split; `export * from '...'` cannot.
|
|
97
|
+
if (stmt.exportClause && ts.isNamedExports(stmt.exportClause)) {
|
|
98
|
+
rewriteNamedDeclaration(sourceFile, stmt, stmt.moduleSpecifier, stmt.isTypeOnly, stmt.exportClause.elements, 'export', changes);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
replaceSpecifier(sourceFile, stmt.moduleSpecifier, TO_INTERNAL, changes);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Partition the named bindings of an import/export declaration into the ones
|
|
105
|
+
* that resolve to `@nx/jest`'s public entry and the ones that don't. If both
|
|
106
|
+
* groups are non-empty, the single declaration is split into two.
|
|
107
|
+
*/
|
|
108
|
+
function rewriteNamedDeclaration(sourceFile, decl, specifier, isTypeOnly, elements, keyword, changes) {
|
|
109
|
+
const publicEls = [];
|
|
110
|
+
const internalEls = [];
|
|
111
|
+
for (const el of elements) {
|
|
112
|
+
// `propertyName` is the original name in `orig as alias`; fall back to
|
|
113
|
+
// `name` for the plain `orig` form.
|
|
114
|
+
const importedName = (el.propertyName ?? el.name).text;
|
|
115
|
+
(PUBLIC_SYMBOLS.has(importedName) ? publicEls : internalEls).push(el);
|
|
116
|
+
}
|
|
117
|
+
if (publicEls.length === 0) {
|
|
118
|
+
replaceSpecifier(sourceFile, specifier, TO_INTERNAL, changes);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (internalEls.length === 0) {
|
|
122
|
+
replaceSpecifier(sourceFile, specifier, TO_PUBLIC, changes);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
// Mixed — replace the whole declaration with one statement per target.
|
|
126
|
+
const quote = sourceFile.text.charAt(specifier.getStart(sourceFile));
|
|
127
|
+
const start = decl.getStart(sourceFile);
|
|
128
|
+
const end = decl.getEnd();
|
|
129
|
+
const semicolon = sourceFile.text.charAt(end - 1) === ';' ? ';' : '';
|
|
130
|
+
const prefix = isTypeOnly ? `${keyword} type` : keyword;
|
|
131
|
+
const render = (els, target) => `${prefix} { ${els
|
|
132
|
+
.map((el) => el.getText(sourceFile))
|
|
133
|
+
.join(', ')} } from ${quote}${target}${quote}${semicolon}`;
|
|
134
|
+
changes.push({ type: devkit_1.ChangeType.Delete, start, length: end - start }, {
|
|
135
|
+
type: devkit_1.ChangeType.Insert,
|
|
136
|
+
index: start,
|
|
137
|
+
text: `${render(publicEls, TO_PUBLIC)}\n${render(internalEls, TO_INTERNAL)}`,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
function collectCallExpressionRewrites(sourceFile, changes) {
|
|
141
|
+
const visit = (node) => {
|
|
142
|
+
if (ts.isCallExpression(node) &&
|
|
143
|
+
shouldRewriteCallExpression(node) &&
|
|
144
|
+
node.arguments.length >= 1 &&
|
|
145
|
+
isSubpathSpecifier(node.arguments[0])) {
|
|
146
|
+
// `require(...)`, dynamic `import(...)` and `jest.mock(...)` reference
|
|
147
|
+
// the module as a whole and can't be symbol-split, so they go to the
|
|
148
|
+
// internal entry.
|
|
149
|
+
replaceSpecifier(sourceFile, node.arguments[0], TO_INTERNAL, changes);
|
|
150
|
+
}
|
|
151
|
+
ts.forEachChild(node, visit);
|
|
152
|
+
};
|
|
153
|
+
visit(sourceFile);
|
|
154
|
+
}
|
|
155
|
+
function shouldRewriteCallExpression(call) {
|
|
156
|
+
const callee = call.expression;
|
|
157
|
+
// `require('...')`
|
|
158
|
+
if (ts.isIdentifier(callee) && callee.text === 'require')
|
|
159
|
+
return true;
|
|
160
|
+
// dynamic `import('...')` (runtime form parses as a CallExpression whose
|
|
161
|
+
// callee is the `import` keyword). The type-position form
|
|
162
|
+
// (`typeof import('...')`) is an `ImportTypeNode`, not a CallExpression, so
|
|
163
|
+
// we don't touch it.
|
|
164
|
+
if (callee.kind === ts.SyntaxKind.ImportKeyword)
|
|
165
|
+
return true;
|
|
166
|
+
// `jest.mock(...)` / `vi.mock(...)` and friends.
|
|
167
|
+
if (ts.isPropertyAccessExpression(callee)) {
|
|
168
|
+
const obj = callee.expression;
|
|
169
|
+
if (ts.isIdentifier(obj) &&
|
|
170
|
+
(obj.text === 'jest' || obj.text === 'vi') &&
|
|
171
|
+
MOCK_HELPER_METHODS.has(callee.name.text)) {
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
function replaceSpecifier(sourceFile, literal, target, changes) {
|
|
178
|
+
const start = literal.getStart(sourceFile);
|
|
179
|
+
const end = literal.getEnd();
|
|
180
|
+
const quote = sourceFile.text.charAt(start);
|
|
181
|
+
changes.push({ type: devkit_1.ChangeType.Delete, start, length: end - start }, {
|
|
182
|
+
type: devkit_1.ChangeType.Insert,
|
|
183
|
+
index: start,
|
|
184
|
+
text: `${quote}${target}${quote}`,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = rewriteJestProjectGenerator;
|
|
4
|
+
exports.rewriteJestProjectGeneratorUsage = rewriteJestProjectGeneratorUsage;
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const TS_EXTENSIONS = ['.ts', '.tsx', '.cts', '.mts'];
|
|
7
|
+
const PACKAGE = '@nx/jest';
|
|
8
|
+
const OLD_NAME = 'jestProjectGenerator';
|
|
9
|
+
const NEW_NAME = 'configurationGenerator';
|
|
10
|
+
let ts;
|
|
11
|
+
async function rewriteJestProjectGenerator(tree) {
|
|
12
|
+
let touchedCount = 0;
|
|
13
|
+
(0, devkit_1.visitNotIgnoredFiles)(tree, '.', (filePath) => {
|
|
14
|
+
if (!TS_EXTENSIONS.some((ext) => filePath.endsWith(ext))) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const original = tree.read(filePath, 'utf-8');
|
|
18
|
+
if (!original ||
|
|
19
|
+
!original.includes(OLD_NAME) ||
|
|
20
|
+
!original.includes(PACKAGE)) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const updated = rewriteJestProjectGeneratorUsage(original);
|
|
24
|
+
if (updated !== original) {
|
|
25
|
+
tree.write(filePath, updated);
|
|
26
|
+
touchedCount += 1;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
if (touchedCount > 0) {
|
|
30
|
+
devkit_1.logger.info(`Replaced the deprecated \`${OLD_NAME}\` with \`${NEW_NAME}\` in ${touchedCount} file(s).`);
|
|
31
|
+
}
|
|
32
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
33
|
+
}
|
|
34
|
+
function rewriteJestProjectGeneratorUsage(source) {
|
|
35
|
+
ts ??= (0, devkit_1.ensurePackage)('typescript', '*');
|
|
36
|
+
const sourceFile = ts.createSourceFile('tmp.ts', source, ts.ScriptTarget.Latest,
|
|
37
|
+
/* setParentNodes */ true, ts.ScriptKind.TSX);
|
|
38
|
+
// `jestProjectGenerator as alias` — only the imported name changes.
|
|
39
|
+
let aliasedSpecifier;
|
|
40
|
+
// `jestProjectGenerator` — the local binding is the old name itself.
|
|
41
|
+
let plainSpecifier;
|
|
42
|
+
// Whether `configurationGenerator` is already a binding in the file, which
|
|
43
|
+
// means a plain rename would produce a duplicate import specifier.
|
|
44
|
+
let newNameAlreadyBound = false;
|
|
45
|
+
for (const stmt of sourceFile.statements) {
|
|
46
|
+
if (!ts.isImportDeclaration(stmt))
|
|
47
|
+
continue;
|
|
48
|
+
if (!ts.isStringLiteral(stmt.moduleSpecifier) ||
|
|
49
|
+
stmt.moduleSpecifier.text !== PACKAGE) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const named = stmt.importClause?.namedBindings;
|
|
53
|
+
if (!named || !ts.isNamedImports(named))
|
|
54
|
+
continue;
|
|
55
|
+
for (const spec of named.elements) {
|
|
56
|
+
const importedName = (spec.propertyName ?? spec.name).text;
|
|
57
|
+
if (importedName === OLD_NAME) {
|
|
58
|
+
if (spec.propertyName) {
|
|
59
|
+
aliasedSpecifier = spec;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
plainSpecifier = spec;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (importedName === NEW_NAME || spec.name.text === NEW_NAME) {
|
|
66
|
+
newNameAlreadyBound = true;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (!aliasedSpecifier && !plainSpecifier) {
|
|
71
|
+
return source;
|
|
72
|
+
}
|
|
73
|
+
const changes = [];
|
|
74
|
+
// `jestProjectGenerator as alias` -> `configurationGenerator as alias`.
|
|
75
|
+
// Call sites use `alias`, so only the imported name is rewritten.
|
|
76
|
+
if (aliasedSpecifier?.propertyName) {
|
|
77
|
+
replaceNode(sourceFile, aliasedSpecifier.propertyName, NEW_NAME, changes);
|
|
78
|
+
}
|
|
79
|
+
if (plainSpecifier) {
|
|
80
|
+
if (newNameAlreadyBound) {
|
|
81
|
+
// A plain rename would collide with the existing `configurationGenerator`
|
|
82
|
+
// binding, so alias the import and leave the call sites untouched.
|
|
83
|
+
replaceNode(sourceFile, plainSpecifier.name, `${NEW_NAME} as ${OLD_NAME}`, changes);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
// Rename the import binding and every bare-identifier usage in the file.
|
|
87
|
+
for (const id of collectBareIdentifiers(sourceFile)) {
|
|
88
|
+
replaceNode(sourceFile, id, NEW_NAME, changes);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return changes.length > 0 ? (0, devkit_1.applyChangesToString)(source, changes) : source;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Collect every `jestProjectGenerator` identifier that is a standalone
|
|
96
|
+
* reference — the import binding and its call sites — while skipping member
|
|
97
|
+
* accesses like `someObject.jestProjectGenerator`, which are unrelated.
|
|
98
|
+
*/
|
|
99
|
+
function collectBareIdentifiers(sourceFile) {
|
|
100
|
+
const found = [];
|
|
101
|
+
const visit = (node) => {
|
|
102
|
+
if (ts.isIdentifier(node) && node.text === OLD_NAME) {
|
|
103
|
+
const parent = node.parent;
|
|
104
|
+
const isMemberName = parent &&
|
|
105
|
+
ts.isPropertyAccessExpression(parent) &&
|
|
106
|
+
parent.name === node;
|
|
107
|
+
const isQualifiedName = parent && ts.isQualifiedName(parent) && parent.right === node;
|
|
108
|
+
if (!isMemberName && !isQualifiedName) {
|
|
109
|
+
found.push(node);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
ts.forEachChild(node, visit);
|
|
113
|
+
};
|
|
114
|
+
visit(sourceFile);
|
|
115
|
+
return found;
|
|
116
|
+
}
|
|
117
|
+
function replaceNode(sourceFile, node, text, changes) {
|
|
118
|
+
const start = node.getStart(sourceFile);
|
|
119
|
+
const end = node.getEnd();
|
|
120
|
+
changes.push({ type: devkit_1.ChangeType.Delete, start, length: end - start }, { type: devkit_1.ChangeType.Insert, index: start, text });
|
|
121
|
+
}
|
|
@@ -7,4 +7,3 @@ export declare const TEST_FILE_PATTERN: RegExp;
|
|
|
7
7
|
*/
|
|
8
8
|
export declare const TS_QUERY_JEST_CONFIG_PREFIX = ":matches(ExportAssignment, BinaryExpression:has(Identifier[name=\"module\"]):has(Identifier[name=\"exports\"]))";
|
|
9
9
|
export declare function addTransformerToConfig(configContents: string, transformer: string): string;
|
|
10
|
-
//# sourceMappingURL=ast-utils.d.ts.map
|
|
@@ -7,4 +7,3 @@ export declare function getPresetExt(tree: Tree): JestPresetExtension;
|
|
|
7
7
|
export declare function findRootJestConfig(tree: Tree): string | null;
|
|
8
8
|
export declare function findJestConfig(tree: Tree, projectPath: string): string | null;
|
|
9
9
|
export declare function findRootJestPreset(tree: Tree): string | null;
|
|
10
|
-
//# sourceMappingURL=config-file.d.ts.map
|
|
@@ -18,4 +18,3 @@ export declare function addPropertyToJestConfig(host: Tree, path: string, proper
|
|
|
18
18
|
*/
|
|
19
19
|
export declare function removePropertyFromJestConfig(host: Tree, path: string, propertyName: string | string[]): void;
|
|
20
20
|
export declare function addImportStatementToJestConfig(host: Tree, path: string, importStatement: string): void;
|
|
21
|
-
//# sourceMappingURL=update-config.d.ts.map
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
export declare const JEST_EXECUTOR_DEPRECATION_MESSAGE = "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 targets. See https://nx.dev/docs/guides/tasks--caching/convert-to-inferred for details.";
|
|
2
2
|
export declare function warnJestExecutorDeprecation(): void;
|
|
3
3
|
export declare function warnJestExecutorGenerating(): void;
|
|
4
|
-
//# sourceMappingURL=deprecation.d.ts.map
|
|
@@ -26,4 +26,3 @@ export declare function getInstalledJestVersionInfo(tree?: Tree): {
|
|
|
26
26
|
export declare function getInstalledJestMajorVersion(tree?: Tree): number | null;
|
|
27
27
|
export declare function validateInstalledJestVersion(tree?: Tree): void;
|
|
28
28
|
export {};
|
|
29
|
-
//# sourceMappingURL=versions.d.ts.map
|
|
@@ -7,8 +7,9 @@ exports.getInstalledJestVersionInfo = getInstalledJestVersionInfo;
|
|
|
7
7
|
exports.getInstalledJestMajorVersion = getInstalledJestMajorVersion;
|
|
8
8
|
exports.validateInstalledJestVersion = validateInstalledJestVersion;
|
|
9
9
|
const devkit_1 = require("@nx/devkit");
|
|
10
|
+
const path_1 = require("path");
|
|
10
11
|
const semver_1 = require("semver");
|
|
11
|
-
const nxVersion = require('
|
|
12
|
+
const nxVersion = require((0, path_1.join)('@nx/jest', 'package.json')).version;
|
|
12
13
|
// Jest is pinned to 30.3.x because jest-runtime@30.4.0 added a call to
|
|
13
14
|
// `_moduleMocker.clearMocksOnScope()`, which doesn't exist on the
|
|
14
15
|
// jest-mock@29 ModuleMocker that React Native's preset still feeds in
|
package/executors.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"executors": {
|
|
3
3
|
"jest": {
|
|
4
|
-
"implementation": "./src/executors/jest/jest.impl",
|
|
5
|
-
"batchImplementation": "./src/executors/jest/jest.impl#batchJest",
|
|
6
|
-
"schema": "./src/executors/jest/schema.json",
|
|
4
|
+
"implementation": "./dist/src/executors/jest/jest.impl",
|
|
5
|
+
"batchImplementation": "./dist/src/executors/jest/jest.impl#batchJest",
|
|
6
|
+
"schema": "./dist/src/executors/jest/schema.json",
|
|
7
7
|
"description": "Run Jest unit tests."
|
|
8
8
|
}
|
|
9
9
|
}
|
package/generators.json
CHANGED
|
@@ -3,21 +3,21 @@
|
|
|
3
3
|
"version": "0.1",
|
|
4
4
|
"generators": {
|
|
5
5
|
"init": {
|
|
6
|
-
"factory": "./src/generators/init/init#jestInitGeneratorInternal",
|
|
7
|
-
"schema": "./src/generators/init/schema.json",
|
|
6
|
+
"factory": "./dist/src/generators/init/init#jestInitGeneratorInternal",
|
|
7
|
+
"schema": "./dist/src/generators/init/schema.json",
|
|
8
8
|
"description": "Initialize the `@nx/jest` plugin.",
|
|
9
9
|
"aliases": ["ng-add"],
|
|
10
10
|
"hidden": true
|
|
11
11
|
},
|
|
12
12
|
"configuration": {
|
|
13
|
-
"factory": "./src/generators/configuration/configuration#configurationGeneratorInternal",
|
|
14
|
-
"schema": "./src/generators/configuration/schema.json",
|
|
13
|
+
"factory": "./dist/src/generators/configuration/configuration#configurationGeneratorInternal",
|
|
14
|
+
"schema": "./dist/src/generators/configuration/schema.json",
|
|
15
15
|
"description": "Add Jest configuration to a project.",
|
|
16
16
|
"hidden": true
|
|
17
17
|
},
|
|
18
18
|
"convert-to-inferred": {
|
|
19
|
-
"factory": "./src/generators/convert-to-inferred/convert-to-inferred",
|
|
20
|
-
"schema": "./src/generators/convert-to-inferred/schema.json",
|
|
19
|
+
"factory": "./dist/src/generators/convert-to-inferred/convert-to-inferred",
|
|
20
|
+
"schema": "./dist/src/generators/convert-to-inferred/schema.json",
|
|
21
21
|
"description": "Convert existing Jest project(s) using `@nx/jest:jest` executor to use `@nx/jest/plugin`."
|
|
22
22
|
}
|
|
23
23
|
}
|