@nx/jest 18.0.0-beta.1 → 18.0.0-beta.2

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/generators.json CHANGED
@@ -3,14 +3,14 @@
3
3
  "version": "0.1",
4
4
  "generators": {
5
5
  "init": {
6
- "factory": "./src/generators/init/init#jestInitGenerator",
6
+ "factory": "./src/generators/init/init#jestInitGeneratorInternal",
7
7
  "schema": "./src/generators/init/schema.json",
8
8
  "description": "Initialize the `@nrwl/jest` plugin.",
9
9
  "aliases": ["ng-add"],
10
10
  "hidden": true
11
11
  },
12
12
  "configuration": {
13
- "factory": "./src/generators/configuration/configuration",
13
+ "factory": "./src/generators/configuration/configuration#configurationGeneratorInternal",
14
14
  "schema": "./src/generators/configuration/schema.json",
15
15
  "description": "Add Jest configuration to a project.",
16
16
  "hidden": true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/jest",
3
- "version": "18.0.0-beta.1",
3
+ "version": "18.0.0-beta.2",
4
4
  "private": false,
5
5
  "description": "The Nx Plugin for Jest contains executors and generators allowing your workspace to use the powerful Jest testing capabilities.",
6
6
  "repository": {
@@ -45,9 +45,9 @@
45
45
  "minimatch": "9.0.3",
46
46
  "resolve.exports": "1.1.0",
47
47
  "tslib": "^2.3.0",
48
- "@nx/devkit": "18.0.0-beta.1",
49
- "@nx/js": "18.0.0-beta.1",
50
- "@nrwl/jest": "18.0.0-beta.1"
48
+ "@nx/devkit": "18.0.0-beta.2",
49
+ "@nx/js": "18.0.0-beta.2",
50
+ "@nrwl/jest": "18.0.0-beta.2"
51
51
  },
52
52
  "publishConfig": {
53
53
  "access": "public"
@@ -1,4 +1,5 @@
1
1
  import { JestProjectSchema } from './schema';
2
2
  import { Tree, GeneratorCallback } from '@nx/devkit';
3
3
  export declare function configurationGenerator(tree: Tree, schema: JestProjectSchema): Promise<GeneratorCallback>;
4
+ export declare function configurationGeneratorInternal(tree: Tree, schema: JestProjectSchema): Promise<GeneratorCallback>;
4
5
  export default configurationGenerator;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.configurationGenerator = void 0;
3
+ exports.configurationGeneratorInternal = exports.configurationGenerator = void 0;
4
4
  const init_1 = require("../init/init");
5
5
  const check_for_test_target_1 = require("./lib/check-for-test-target");
6
6
  const create_files_1 = require("./lib/create-files");
@@ -23,6 +23,8 @@ function normalizeOptions(tree, options) {
23
23
  if (!options.testEnvironment) {
24
24
  options.testEnvironment = 'jsdom';
25
25
  }
26
+ options.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';
27
+ options.targetName ??= 'test';
26
28
  if (!options.hasOwnProperty('supportTsx')) {
27
29
  options.supportTsx = false;
28
30
  }
@@ -43,11 +45,15 @@ function normalizeOptions(tree, options) {
43
45
  rootProject: project.root === '.' || project.root === '',
44
46
  };
45
47
  }
46
- async function configurationGenerator(tree, schema) {
48
+ function configurationGenerator(tree, schema) {
49
+ return configurationGeneratorInternal(tree, { addPlugin: false, ...schema });
50
+ }
51
+ exports.configurationGenerator = configurationGenerator;
52
+ async function configurationGeneratorInternal(tree, schema) {
47
53
  const options = normalizeOptions(tree, schema);
48
54
  const tasks = [];
49
55
  tasks.push(await (0, js_1.initGenerator)(tree, { ...schema, skipFormat: true }));
50
- tasks.push(await (0, init_1.jestInitGenerator)(tree, options));
56
+ tasks.push(await (0, init_1.jestInitGenerator)(tree, { ...options, skipFormat: true }));
51
57
  if (!schema.skipPackageJson) {
52
58
  tasks.push((0, ensure_dependencies_1.ensureDependencies)(tree, options));
53
59
  }
@@ -57,9 +63,16 @@ async function configurationGenerator(tree, schema) {
57
63
  (0, update_tsconfig_1.updateTsConfig)(tree, options);
58
64
  (0, update_vscode_recommended_extensions_1.updateVsCodeRecommendedExtensions)(tree);
59
65
  const nxJson = (0, devkit_1.readNxJson)(tree);
60
- const hasPlugin = nxJson.plugins?.some((p) => typeof p === 'string'
61
- ? p === '@nx/jest/plugin'
62
- : p.plugin === '@nx/jest/plugin');
66
+ const hasPlugin = nxJson.plugins?.some((p) => {
67
+ if (typeof p === 'string') {
68
+ return p === '@nx/jest/plugin' && options.targetName === 'test';
69
+ }
70
+ else {
71
+ return (p.plugin === '@nx/jest/plugin' &&
72
+ (p.options?.targetName ?? 'test') ===
73
+ options.targetName);
74
+ }
75
+ });
63
76
  if (!hasPlugin) {
64
77
  (0, update_workspace_1.updateWorkspace)(tree, options);
65
78
  }
@@ -68,5 +81,5 @@ async function configurationGenerator(tree, schema) {
68
81
  }
69
82
  return (0, devkit_1.runTasksInSerial)(...tasks);
70
83
  }
71
- exports.configurationGenerator = configurationGenerator;
84
+ exports.configurationGeneratorInternal = configurationGeneratorInternal;
72
85
  exports.default = configurationGenerator;
@@ -7,7 +7,7 @@ function updateWorkspace(tree, options) {
7
7
  if (!projectConfig.targets) {
8
8
  projectConfig.targets = {};
9
9
  }
10
- projectConfig.targets.test = {
10
+ projectConfig.targets[options.targetName] = {
11
11
  executor: '@nx/jest:jest',
12
12
  outputs: [
13
13
  options.rootProject
@@ -1,5 +1,6 @@
1
1
  export interface JestProjectSchema {
2
2
  project: string;
3
+ targetName?: string;
3
4
  supportTsx?: boolean;
4
5
  /**
5
6
  * @deprecated use setupFile instead
@@ -13,6 +14,8 @@ export interface JestProjectSchema {
13
14
  */
14
15
  babelJest?: boolean;
15
16
  skipFormat?: boolean;
17
+
18
+ addPlugin?: boolean;
16
19
  compiler?: 'tsc' | 'babel' | 'swc';
17
20
  skipPackageJson?: boolean;
18
21
  js?: boolean;
@@ -1,4 +1,5 @@
1
1
  import { type GeneratorCallback, type Tree } from '@nx/devkit';
2
2
  import type { JestInitSchema } from './schema';
3
3
  export declare function jestInitGenerator(tree: Tree, options: JestInitSchema): Promise<GeneratorCallback>;
4
+ export declare function jestInitGeneratorInternal(tree: Tree, options: JestInitSchema): Promise<GeneratorCallback>;
4
5
  export default jestInitGenerator;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.jestInitGenerator = void 0;
3
+ exports.jestInitGeneratorInternal = exports.jestInitGenerator = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const update_package_scripts_1 = require("@nx/devkit/src/utils/update-package-scripts");
6
6
  const plugin_1 = require("../../plugins/plugin");
@@ -69,10 +69,15 @@ function updateDependencies(tree, options) {
69
69
  jest: versions_1.jestVersion,
70
70
  }, undefined, options.keepExistingVersions);
71
71
  }
72
- async function jestInitGenerator(tree, options) {
72
+ function jestInitGenerator(tree, options) {
73
+ return jestInitGeneratorInternal(tree, { addPlugin: false, ...options });
74
+ }
75
+ exports.jestInitGenerator = jestInitGenerator;
76
+ async function jestInitGeneratorInternal(tree, options) {
77
+ options.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';
73
78
  if (!tree.exists('jest.preset.js')) {
74
79
  updateProductionFileSet(tree);
75
- if (process.env.NX_PCV3 === 'true') {
80
+ if (options.addPlugin) {
76
81
  addPlugin(tree);
77
82
  }
78
83
  else {
@@ -92,5 +97,5 @@ async function jestInitGenerator(tree, options) {
92
97
  }
93
98
  return (0, devkit_1.runTasksInSerial)(...tasks);
94
99
  }
95
- exports.jestInitGenerator = jestInitGenerator;
100
+ exports.jestInitGeneratorInternal = jestInitGeneratorInternal;
96
101
  exports.default = jestInitGenerator;
@@ -3,4 +3,6 @@ export interface JestInitSchema {
3
3
  skipPackageJson?: boolean;
4
4
  keepExistingVersions?: boolean;
5
5
  updatePackageScripts?: boolean;
6
+
7
+ addPlugin?: boolean;
6
8
  }
@@ -64,7 +64,7 @@ async function buildJestTargets(configFilePath, projectRoot, options, context) {
64
64
  const config = await (0, jest_config_1.readConfig)({
65
65
  _: [],
66
66
  $0: undefined,
67
- }, (0, path_1.resolve)(context.workspaceRoot, configFilePath), true, null, undefined, true);
67
+ }, (0, path_1.resolve)(context.workspaceRoot, configFilePath));
68
68
  const targetDefaults = (0, project_configuration_utils_1.readTargetDefaultsForTarget)(options.targetName, context.nxJsonConfiguration.targetDefaults, 'nx:run-commands');
69
69
  const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
70
70
  const targets = {};