@nx/jest 21.2.1 → 21.2.3

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": "21.2.1",
3
+ "version": "21.2.3",
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": {
@@ -37,8 +37,8 @@
37
37
  "dependencies": {
38
38
  "@jest/reporters": "^29.4.1",
39
39
  "@jest/test-result": "^29.4.1",
40
- "@nx/devkit": "21.2.1",
41
- "@nx/js": "21.2.1",
40
+ "@nx/devkit": "21.2.3",
41
+ "@nx/js": "21.2.3",
42
42
  "@phenomnomnominal/tsquery": "~5.0.1",
43
43
  "identity-obj-proxy": "3.0.0",
44
44
  "jest-config": "^29.4.1",
@@ -58,6 +58,10 @@ function configurationGenerator(tree, schema) {
58
58
  }
59
59
  async function configurationGeneratorInternal(tree, schema) {
60
60
  const options = normalizeOptions(tree, schema);
61
+ // we'll only add the vscode recommended extension if the jest preset does
62
+ // not exist, which most likely means this is a first run, in the cases it's
63
+ // not a first run, we'll skip adding it but it's not a critical thing to do
64
+ const shouldAddVsCodeRecommendations = (0, config_file_1.findRootJestPreset)(tree) === null;
61
65
  const tasks = [];
62
66
  tasks.push(await (0, js_1.initGenerator)(tree, { ...schema, skipFormat: true }));
63
67
  tasks.push(await (0, init_1.jestInitGenerator)(tree, { ...options, skipFormat: true }));
@@ -69,7 +73,9 @@ async function configurationGeneratorInternal(tree, schema) {
69
73
  (0, check_for_test_target_1.checkForTestTarget)(tree, options);
70
74
  (0, create_files_1.createFiles)(tree, options, presetExt);
71
75
  (0, update_tsconfig_1.updateTsConfig)(tree, options);
72
- (0, update_vscode_recommended_extensions_1.updateVsCodeRecommendedExtensions)(tree);
76
+ if (shouldAddVsCodeRecommendations) {
77
+ (0, update_vscode_recommended_extensions_1.updateVsCodeRecommendedExtensions)(tree);
78
+ }
73
79
  const nxJson = (0, devkit_1.readNxJson)(tree);
74
80
  const hasPlugin = nxJson.plugins?.some((p) => {
75
81
  if (typeof p === 'string') {
@@ -32,11 +32,11 @@ exports.createNodesV2 = [
32
32
  const targetsCache = readTargetsCache(cachePath);
33
33
  // Cache jest preset(s) to avoid penalties of module load times. Most of jest configs will use the same preset.
34
34
  const presetCache = {};
35
- const packageManagerWorkspacesGlob = (0, globs_1.combineGlobPatterns)((0, package_json_1.getGlobPatternsFromPackageManagerWorkspaces)(context.workspaceRoot));
35
+ const isInPackageManagerWorkspaces = buildPackageJsonWorkspacesMatcher(context.workspaceRoot);
36
36
  options = normalizeOptions(options);
37
37
  const { roots: projectRoots, configFiles: validConfigFiles } = configFiles.reduce((acc, configFile) => {
38
38
  const potentialRoot = (0, path_1.dirname)(configFile);
39
- if (checkIfConfigFileShouldBeProject(configFile, potentialRoot, packageManagerWorkspacesGlob, context)) {
39
+ if (checkIfConfigFileShouldBeProject(configFile, potentialRoot, isInPackageManagerWorkspaces, context)) {
40
40
  acc.roots.push(potentialRoot);
41
41
  acc.configFiles.push(configFile);
42
42
  }
@@ -77,8 +77,8 @@ exports.createNodes = [
77
77
  async (configFilePath, options, context) => {
78
78
  devkit_1.logger.warn('`createNodes` is deprecated. Update your plugin to utilize createNodesV2 instead. In Nx 20, this will change to the createNodesV2 API.');
79
79
  const projectRoot = (0, path_1.dirname)(configFilePath);
80
- const packageManagerWorkspacesGlob = (0, globs_1.combineGlobPatterns)((0, package_json_1.getGlobPatternsFromPackageManagerWorkspaces)(context.workspaceRoot));
81
- if (!checkIfConfigFileShouldBeProject(configFilePath, projectRoot, packageManagerWorkspacesGlob, context)) {
80
+ const isInPackageManagerWorkspaces = buildPackageJsonWorkspacesMatcher(context.workspaceRoot);
81
+ if (!checkIfConfigFileShouldBeProject(configFilePath, projectRoot, isInPackageManagerWorkspaces, context)) {
82
82
  return {};
83
83
  }
84
84
  options = normalizeOptions(options);
@@ -94,7 +94,14 @@ exports.createNodes = [
94
94
  };
95
95
  },
96
96
  ];
97
- function checkIfConfigFileShouldBeProject(configFilePath, projectRoot, packageManagerWorkspacesGlob, context) {
97
+ function buildPackageJsonWorkspacesMatcher(workspaceRoot) {
98
+ if (process.env.NX_INFER_ALL_PACKAGE_JSONS === 'true') {
99
+ return () => true;
100
+ }
101
+ const packageManagerWorkspacesGlob = (0, globs_1.combineGlobPatterns)((0, package_json_1.getGlobPatternsFromPackageManagerWorkspaces)(workspaceRoot));
102
+ return (path) => (0, minimatch_1.minimatch)(path, packageManagerWorkspacesGlob);
103
+ }
104
+ function checkIfConfigFileShouldBeProject(configFilePath, projectRoot, isInPackageManagerWorkspaces, context) {
98
105
  // Do not create a project if package.json and project.json isn't there.
99
106
  const siblingFiles = (0, fs_1.readdirSync)((0, path_1.join)(context.workspaceRoot, projectRoot));
100
107
  if (!siblingFiles.includes('package.json') &&
@@ -104,7 +111,7 @@ function checkIfConfigFileShouldBeProject(configFilePath, projectRoot, packageMa
104
111
  else if (!siblingFiles.includes('project.json') &&
105
112
  siblingFiles.includes('package.json')) {
106
113
  const path = (0, devkit_1.joinPathFragments)(projectRoot, 'package.json');
107
- const isPackageJsonProject = (0, minimatch_1.minimatch)(path, packageManagerWorkspacesGlob);
114
+ const isPackageJsonProject = isInPackageManagerWorkspaces(path);
108
115
  if (!isPackageJsonProject) {
109
116
  return false;
110
117
  }
@@ -122,7 +129,14 @@ async function buildJestTargets(configFilePath, projectRoot, options, context, p
122
129
  const absConfigFilePath = (0, path_1.resolve)(context.workspaceRoot, configFilePath);
123
130
  if (require.cache[absConfigFilePath])
124
131
  (0, config_utils_1.clearRequireCache)();
125
- const rawConfig = await (0, config_utils_1.loadConfigFile)(absConfigFilePath);
132
+ const rawConfig = await (0, config_utils_1.loadConfigFile)(absConfigFilePath,
133
+ // lookup for the same files we look for in the resolver and fall back to tsconfig.json
134
+ [
135
+ 'tsconfig.spec.json',
136
+ 'tsconfig.test.json',
137
+ 'tsconfig.jest.json',
138
+ 'tsconfig.json',
139
+ ]);
126
140
  const targets = {};
127
141
  const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
128
142
  const tsNodeCompilerOptions = JSON.stringify({