@nx/jest 17.0.2 → 17.0.4

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.
Files changed (40) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +9 -4
  3. package/generators.json +2 -2
  4. package/index.d.ts +1 -1
  5. package/index.js +2 -1
  6. package/migrations.json +14 -0
  7. package/package.json +6 -4
  8. package/plugin.d.ts +1 -0
  9. package/plugin.js +6 -0
  10. package/src/generators/configuration/configuration.d.ts +1 -0
  11. package/src/generators/configuration/configuration.js +42 -7
  12. package/src/generators/configuration/files/jest.config.ts__tmpl__ +1 -1
  13. package/src/generators/configuration/files-angular/jest.config.ts__tmpl__ +1 -1
  14. package/src/generators/configuration/lib/create-files.d.ts +1 -1
  15. package/src/generators/configuration/lib/create-files.js +2 -1
  16. package/src/generators/configuration/lib/create-jest-config.d.ts +3 -0
  17. package/src/generators/configuration/lib/create-jest-config.js +102 -0
  18. package/src/generators/configuration/lib/ensure-dependencies.d.ts +3 -0
  19. package/src/generators/configuration/lib/ensure-dependencies.js +34 -0
  20. package/src/generators/configuration/lib/update-jestconfig.js +6 -1
  21. package/src/generators/configuration/lib/update-vscode-recommended-extensions.d.ts +2 -0
  22. package/src/generators/configuration/lib/update-vscode-recommended-extensions.js +18 -0
  23. package/src/generators/configuration/lib/update-workspace.js +1 -8
  24. package/src/generators/configuration/schema.d.ts +8 -0
  25. package/src/generators/configuration/schema.json +1 -1
  26. package/src/generators/init/init.d.ts +4 -3
  27. package/src/generators/init/init.js +66 -130
  28. package/src/generators/init/schema.d.ts +5 -8
  29. package/src/generators/init/schema.json +13 -20
  30. package/src/migrations/update-17-1-0/move-options-to-target-defaults.d.ts +2 -0
  31. package/src/migrations/update-17-1-0/move-options-to-target-defaults.js +117 -0
  32. package/src/plugins/plugin.d.ts +6 -0
  33. package/src/plugins/plugin.js +130 -0
  34. package/src/utils/config/find-root-jest-files.js +3 -0
  35. package/src/utils/config/get-jest-projects.d.ts +16 -1
  36. package/src/utils/config/get-jest-projects.js +98 -3
  37. package/src/utils/config/is-preset-cjs.d.ts +2 -0
  38. package/src/utils/config/is-preset-cjs.js +15 -0
  39. package/src/utils/versions.d.ts +1 -1
  40. package/src/utils/versions.js +1 -1
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getNestedJestProjects = exports.getJestProjects = void 0;
4
- const path_1 = require("path");
3
+ exports.getJestProjectsAsync = exports.getNestedJestProjects = exports.getJestProjects = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
5
  const file_utils_1 = require("nx/src/project-graph/file-utils");
6
+ const path_1 = require("path");
7
+ const yargs = require("yargs-parser");
6
8
  function getJestConfigProjectPath(projectJestConfigPath) {
7
9
  return (0, path_1.join)('<rootDir>', projectJestConfigPath);
8
10
  }
@@ -10,7 +12,8 @@ function getJestConfigProjectPath(projectJestConfigPath) {
10
12
  * Get a list of paths to all the jest config files
11
13
  * using the Nx Jest executor.
12
14
  *
13
- * This is used to configure Jest multi-project support.
15
+ * This is used to configure Jest multi-project support. To support projects
16
+ * using inferred targets @see getJestProjectsAsync
14
17
  *
15
18
  * To add a project not using the Nx Jest executor:
16
19
  * export default {
@@ -60,3 +63,95 @@ function getNestedJestProjects() {
60
63
  return ['/node_modules/'];
61
64
  }
62
65
  exports.getNestedJestProjects = getNestedJestProjects;
66
+ /**
67
+ * Get a list of paths to all the jest config files
68
+ * using the Nx Jest executor and `@nx/run:commands`
69
+ * running `jest`.
70
+ *
71
+ * This is used to configure Jest multi-project support.
72
+ *
73
+ * To add a project not using the Nx Jest executor:
74
+ * export default async () => ({
75
+ * projects: [...(await getJestProjectsAsync()), '<rootDir>/path/to/jest.config.ts'];
76
+ * });
77
+ *
78
+ **/
79
+ async function getJestProjectsAsync() {
80
+ const graph = await (0, devkit_1.createProjectGraphAsync)({
81
+ exitOnError: false,
82
+ resetDaemonClient: true,
83
+ });
84
+ const jestConfigurations = new Set();
85
+ for (const node of Object.values(graph.nodes)) {
86
+ const projectConfig = node.data;
87
+ if (!projectConfig.targets) {
88
+ continue;
89
+ }
90
+ for (const targetConfiguration of Object.values(projectConfig.targets)) {
91
+ if (targetConfiguration.executor === '@nx/jest:jest' ||
92
+ targetConfiguration.executor === '@nrwl/jest:jest') {
93
+ collectJestConfigFromJestExecutor(targetConfiguration, jestConfigurations);
94
+ }
95
+ else if (targetConfiguration.executor === 'nx:run-commands') {
96
+ collectJestConfigFromRunCommandsExecutor(targetConfiguration, projectConfig.root, jestConfigurations);
97
+ }
98
+ }
99
+ }
100
+ return Array.from(jestConfigurations);
101
+ }
102
+ exports.getJestProjectsAsync = getJestProjectsAsync;
103
+ function collectJestConfigFromJestExecutor(targetConfiguration, jestConfigurations) {
104
+ if (targetConfiguration.options?.jestConfig) {
105
+ jestConfigurations.add(getJestConfigProjectPath(targetConfiguration.options.jestConfig));
106
+ }
107
+ if (targetConfiguration.configurations) {
108
+ for (const configurationObject of Object.values(targetConfiguration.configurations)) {
109
+ if (configurationObject.jestConfig) {
110
+ jestConfigurations.add(getJestConfigProjectPath(configurationObject.jestConfig));
111
+ }
112
+ }
113
+ }
114
+ }
115
+ function collectJestConfigFromRunCommandsExecutor(targetConfiguration, projectRoot, jestConfigurations) {
116
+ if (targetConfiguration.options?.command) {
117
+ collectJestConfigFromCommand(targetConfiguration.options.command, targetConfiguration.options.cwd ?? projectRoot, jestConfigurations);
118
+ }
119
+ else if (targetConfiguration.options?.commands) {
120
+ for (const command of targetConfiguration.options.commands) {
121
+ const commandScript = typeof command === 'string' ? command : command.command;
122
+ collectJestConfigFromCommand(commandScript, targetConfiguration.options.cwd ?? projectRoot, jestConfigurations);
123
+ }
124
+ }
125
+ if (targetConfiguration.configurations) {
126
+ for (const configurationObject of Object.values(targetConfiguration.configurations)) {
127
+ if (configurationObject.command) {
128
+ collectJestConfigFromCommand(configurationObject.command, configurationObject.cwd ?? projectRoot, jestConfigurations);
129
+ }
130
+ else if (configurationObject.commands) {
131
+ for (const command of configurationObject.commands) {
132
+ const commandScript = typeof command === 'string' ? command : command.command;
133
+ collectJestConfigFromCommand(commandScript, configurationObject.cwd ?? projectRoot, jestConfigurations);
134
+ }
135
+ }
136
+ }
137
+ }
138
+ }
139
+ function collectJestConfigFromCommand(command, cwd, jestConfigurations) {
140
+ const jestCommandRegex = /(?<=^|&)(?:[^&\r\n\s]* )*jest(?: [^&\r\n\s]*)*(?=$|&)/g;
141
+ const matches = command.match(jestCommandRegex);
142
+ if (!matches) {
143
+ return;
144
+ }
145
+ for (const match of matches) {
146
+ const parsed = yargs(match, {
147
+ configuration: { 'strip-dashed': true },
148
+ string: ['config'],
149
+ });
150
+ if (parsed.config) {
151
+ jestConfigurations.add(getJestConfigProjectPath((0, path_1.join)(cwd, parsed.config)));
152
+ }
153
+ else {
154
+ jestConfigurations.add(getJestConfigProjectPath(cwd));
155
+ }
156
+ }
157
+ }
@@ -0,0 +1,2 @@
1
+ import { type Tree } from '@nx/devkit';
2
+ export declare function isPresetCjs(tree: Tree): boolean;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isPresetCjs = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ function isPresetCjs(tree) {
6
+ if (tree.exists('jest.preset.cjs')) {
7
+ return true;
8
+ }
9
+ const rootPkgJson = (0, devkit_1.readJson)(tree, 'package.json');
10
+ if (rootPkgJson.type && rootPkgJson.type === 'module') {
11
+ return true;
12
+ }
13
+ return false;
14
+ }
15
+ exports.isPresetCjs = isPresetCjs;
@@ -5,5 +5,5 @@ export declare const jestTypesVersion = "^29.4.0";
5
5
  export declare const tsJestVersion = "^29.1.0";
6
6
  export declare const tslibVersion = "^2.3.0";
7
7
  export declare const swcJestVersion = "0.2.20";
8
- export declare const typesNodeVersion = "16.11.7";
8
+ export declare const typesNodeVersion = "18.16.9";
9
9
  export declare const tsNodeVersion = "10.9.1";
@@ -8,5 +8,5 @@ exports.jestTypesVersion = '^29.4.0';
8
8
  exports.tsJestVersion = '^29.1.0';
9
9
  exports.tslibVersion = '^2.3.0';
10
10
  exports.swcJestVersion = '0.2.20';
11
- exports.typesNodeVersion = '16.11.7';
11
+ exports.typesNodeVersion = '18.16.9';
12
12
  exports.tsNodeVersion = '10.9.1';