@nx/jest 22.5.2 → 22.5.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/jest",
3
- "version": "22.5.2",
3
+ "version": "22.5.4",
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,14 +37,14 @@
37
37
  "dependencies": {
38
38
  "@jest/reporters": "^30.0.2",
39
39
  "@jest/test-result": "^30.0.2",
40
- "@nx/devkit": "22.5.2",
41
- "@nx/js": "22.5.2",
40
+ "@nx/devkit": "22.5.4",
41
+ "@nx/js": "22.5.4",
42
42
  "@phenomnomnominal/tsquery": "~6.1.4",
43
43
  "identity-obj-proxy": "3.0.0",
44
44
  "jest-config": "^30.0.2",
45
45
  "jest-resolve": "^30.0.2",
46
46
  "jest-util": "^30.0.2",
47
- "minimatch": "10.1.1",
47
+ "minimatch": "10.2.4",
48
48
  "picocolors": "^1.1.0",
49
49
  "resolve.exports": "2.0.3",
50
50
  "semver": "^7.6.3",
@@ -52,7 +52,7 @@
52
52
  "yargs-parser": "21.1.1"
53
53
  },
54
54
  "devDependencies": {
55
- "nx": "22.5.2"
55
+ "nx": "22.5.4"
56
56
  },
57
57
  "publishConfig": {
58
58
  "access": "public"
@@ -1 +1 @@
1
- {"version":3,"file":"replace-removed-matcher-aliases.d.ts","sourceRoot":"","sources":["../../../../../../packages/jest/src/migrations/update-21-3-0/replace-removed-matcher-aliases.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,IAAI,EAAE,MAAM,YAAY,CAAC;AAuB/D,yBAA+B,IAAI,EAAE,IAAI,iBAexC"}
1
+ {"version":3,"file":"replace-removed-matcher-aliases.d.ts","sourceRoot":"","sources":["../../../../../../packages/jest/src/migrations/update-21-3-0/replace-removed-matcher-aliases.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,IAAI,EAAE,MAAM,YAAY,CAAC;AAuB/D,yBAA+B,IAAI,EAAE,IAAI,iBAWxC"}
@@ -24,14 +24,53 @@ const matcherAliasesMap = new Map([
24
24
  async function default_1(tree) {
25
25
  const testFilePaths = await getTestFilePaths(tree);
26
26
  for (const testFilePath of testFilePaths) {
27
- let testFileContent = tree.read(testFilePath, 'utf-8');
28
- for (const [alias, matcher] of matcherAliasesMap) {
29
- testFileContent = (0, tsquery_1.replace)(testFileContent, `CallExpression PropertyAccessExpression:has(CallExpression Identifier[name=expect]) Identifier[name=${alias}]`, (_node) => matcher);
27
+ const testFileContent = tree.read(testFilePath, 'utf-8');
28
+ const updatedContent = replaceMatcherAliases(testFileContent);
29
+ if (updatedContent !== testFileContent) {
30
+ tree.write(testFilePath, updatedContent);
30
31
  }
31
- tree.write(testFilePath, testFileContent);
32
32
  }
33
33
  await (0, devkit_1.formatFiles)(tree);
34
34
  }
35
+ function replaceMatcherAliases(fileContent) {
36
+ // Build a selector that matches any of the deprecated matcher aliases
37
+ const aliasNames = Array.from(matcherAliasesMap.keys());
38
+ const aliasPattern = aliasNames.join('|');
39
+ // Quick check to avoid parsing files that don't contain any aliases
40
+ const hasAnyAlias = aliasNames.some((alias) => fileContent.includes(alias));
41
+ if (!hasAnyAlias) {
42
+ return fileContent;
43
+ }
44
+ const sourceFile = (0, tsquery_1.ast)(fileContent);
45
+ const updates = [];
46
+ // Query for all deprecated matcher identifiers in expect() chains
47
+ // The selector matches: expect(...).toBeCalled(), expect(...).not.toBeCalled(), etc.
48
+ const selector = `CallExpression PropertyAccessExpression:has(CallExpression Identifier[name=expect]) Identifier[name=/^(${aliasPattern})$/]`;
49
+ const matchedNodes = (0, tsquery_1.query)(sourceFile, selector);
50
+ for (const node of matchedNodes) {
51
+ const alias = node.text;
52
+ const replacement = matcherAliasesMap.get(alias);
53
+ if (replacement) {
54
+ updates.push({
55
+ start: node.getStart(sourceFile),
56
+ end: node.getEnd(),
57
+ text: replacement,
58
+ });
59
+ }
60
+ }
61
+ if (!updates.length) {
62
+ return fileContent;
63
+ }
64
+ // Apply updates in reverse order to preserve positions
65
+ let updatedContent = fileContent;
66
+ for (const update of updates.sort((a, b) => b.start - a.start)) {
67
+ updatedContent =
68
+ updatedContent.slice(0, update.start) +
69
+ update.text +
70
+ updatedContent.slice(update.end);
71
+ }
72
+ return updatedContent;
73
+ }
35
74
  async function getTestFilePaths(tree) {
36
75
  const jestConfigFiles = await (0, devkit_1.globAsync)(tree, [
37
76
  '**/jest.config.{cjs,mjs,js,cts,mts,ts}',