@nx/jest 18.2.4 → 18.3.0-beta.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/jest",
3
- "version": "18.2.4",
3
+ "version": "18.3.0-beta.1",
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": {
@@ -36,8 +36,8 @@
36
36
  "dependencies": {
37
37
  "@jest/reporters": "^29.4.1",
38
38
  "@jest/test-result": "^29.4.1",
39
- "@nx/devkit": "18.2.4",
40
- "@nx/js": "18.2.4",
39
+ "@nx/devkit": "18.3.0-beta.1",
40
+ "@nx/js": "18.3.0-beta.1",
41
41
  "@phenomnomnominal/tsquery": "~5.0.1",
42
42
  "chalk": "^4.1.0",
43
43
  "identity-obj-proxy": "3.0.0",
@@ -48,7 +48,7 @@
48
48
  "resolve.exports": "1.1.0",
49
49
  "tslib": "^2.3.0",
50
50
  "yargs-parser": "21.1.1",
51
- "@nrwl/jest": "18.2.4"
51
+ "@nrwl/jest": "18.3.0-beta.1"
52
52
  },
53
53
  "publishConfig": {
54
54
  "access": "public"
@@ -1,6 +1,7 @@
1
1
  import { CreateDependencies, CreateNodes } from '@nx/devkit';
2
2
  export interface JestPluginOptions {
3
3
  targetName?: string;
4
+ ciTargetName?: string;
4
5
  }
5
6
  export declare const createDependencies: CreateDependencies;
6
7
  export declare const createNodes: CreateNodes<JestPluginOptions>;
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createNodes = exports.createDependencies = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const path_1 = require("path");
6
- const project_configuration_utils_1 = require("nx/src/project-graph/utils/project-configuration-utils");
7
6
  const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
8
7
  const fs_1 = require("fs");
9
8
  const jest_config_1 = require("jest-config");
@@ -54,14 +53,15 @@ exports.createNodes = [
54
53
  }
55
54
  options = normalizeOptions(options);
56
55
  const hash = (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, options, context);
57
- const targets = targetsCache[hash] ??
56
+ const { targets, metadata } = targetsCache[hash] ??
58
57
  (await buildJestTargets(configFilePath, projectRoot, options, context));
59
- calculatedTargets[hash] = targets;
58
+ calculatedTargets[hash] = { targets, metadata };
60
59
  return {
61
60
  projects: {
62
61
  [projectRoot]: {
63
62
  root: projectRoot,
64
- targets: targets,
63
+ targets,
64
+ metadata,
65
65
  },
66
66
  },
67
67
  };
@@ -72,7 +72,6 @@ async function buildJestTargets(configFilePath, projectRoot, options, context) {
72
72
  _: [],
73
73
  $0: undefined,
74
74
  }, (0, path_1.resolve)(context.workspaceRoot, configFilePath));
75
- const targetDefaults = (0, project_configuration_utils_1.readTargetDefaultsForTarget)(options.targetName, context.nxJsonConfiguration.targetDefaults, 'nx:run-commands');
76
75
  const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
77
76
  const targets = {};
78
77
  const target = (targets[options.targetName] = {
@@ -80,17 +79,74 @@ async function buildJestTargets(configFilePath, projectRoot, options, context) {
80
79
  options: {
81
80
  cwd: projectRoot,
82
81
  },
82
+ metadata: {
83
+ technologies: ['jest'],
84
+ description: 'Run Jest Tests',
85
+ },
83
86
  });
84
- if (!targetDefaults?.cache) {
85
- target.cache = true;
86
- }
87
- if (!targetDefaults?.inputs) {
88
- target.inputs = getInputs(namedInputs);
89
- }
90
- if (!targetDefaults?.outputs) {
91
- target.outputs = getOutputs(projectRoot, config, context);
87
+ const cache = (target.cache = true);
88
+ const inputs = (target.inputs = getInputs(namedInputs));
89
+ const outputs = (target.outputs = getOutputs(projectRoot, config, context));
90
+ let metadata;
91
+ if (options?.ciTargetName) {
92
+ // Resolve the version of `jest-runtime` that `jest` is using.
93
+ const jestPath = require.resolve('jest');
94
+ const jest = require(jestPath);
95
+ // nx-ignore-next-line
96
+ const { default: Runtime } = require(require.resolve('jest-runtime', {
97
+ paths: [(0, path_1.dirname)(jestPath)],
98
+ // nx-ignore-next-line
99
+ }));
100
+ const context = await Runtime.createContext(config.projectConfig, {
101
+ maxWorkers: 1,
102
+ watchman: false,
103
+ });
104
+ const source = new jest.SearchSource(context);
105
+ const specs = await source.getTestPaths(config.globalConfig);
106
+ const testPaths = new Set(specs.tests.map(({ path }) => path));
107
+ if (testPaths.size > 0) {
108
+ const groupName = 'E2E (CI)';
109
+ const targetGroup = [];
110
+ metadata = {
111
+ targetGroups: {
112
+ [groupName]: targetGroup,
113
+ },
114
+ };
115
+ const dependsOn = [];
116
+ targets[options.ciTargetName] = {
117
+ executor: 'nx:noop',
118
+ cache: true,
119
+ inputs,
120
+ outputs,
121
+ dependsOn,
122
+ metadata: {
123
+ technologies: ['jest'],
124
+ description: 'Run Jest Tests in CI',
125
+ },
126
+ };
127
+ targetGroup.push(options.ciTargetName);
128
+ for (const testPath of testPaths) {
129
+ const relativePath = (0, path_1.normalize)((0, path_1.relative)(projectRoot, testPath));
130
+ const targetName = `${options.ciTargetName}--${relativePath}`;
131
+ dependsOn.push(targetName);
132
+ targets[targetName] = {
133
+ command: `jest ${relativePath}`,
134
+ cache,
135
+ inputs,
136
+ outputs,
137
+ options: {
138
+ cwd: projectRoot,
139
+ },
140
+ metadata: {
141
+ technologies: ['jest'],
142
+ description: `Run Jest Tests in ${relativePath}`,
143
+ },
144
+ };
145
+ targetGroup.push(targetName);
146
+ }
147
+ }
92
148
  }
93
- return targets;
149
+ return { targets, metadata };
94
150
  }
95
151
  function getInputs(namedInputs) {
96
152
  return [