Skip to content

Commit 81248ee

Browse files
authored
chore(monorepo): upgrade to Jest 30 (#11702)
Co-authored-by: slorber <[email protected]>
1 parent db677a3 commit 81248ee

File tree

61 files changed

+1371
-1168
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1371
-1168
lines changed

jest/snapshotPathNormalizer.ts

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,60 @@
1010

1111
import os from 'os';
1212
import path from 'path';
13+
import fs from 'fs';
1314
import _ from 'lodash';
1415
import {escapePath} from '@docusaurus/utils';
1516
import {version} from '@docusaurus/core/package.json';
1617
import stripAnsi from 'strip-ansi';
1718

19+
/*
20+
This weird thing is to normalize paths on our Windows GitHub Actions runners
21+
22+
For some reason, os.tmpdir() returns the "legacy 8.3 DOS short paths"
23+
This prevents snapshot normalization on Windows
24+
25+
tempDir: 'C:\\Users\\RUNNER~1\\AppData\\Local\\Temp',
26+
tempDirReal: 'C:\\Users\\RUNNER~1\\AppData\\Local\\Temp',
27+
homeDir: 'C:\\Users\\runneradmin',
28+
homeDirReal: 'C:\\Users\\runneradmin',
29+
*/
30+
function normalizeWindowTempDirShortPath(str: string): string {
31+
return str.replace('\\RUNNER~1\\', '\\runneradmin\\');
32+
}
33+
34+
function readPathsForNormalization() {
35+
const cwd = process.cwd();
36+
37+
const tempDir = os.tmpdir();
38+
const homeDir = os.homedir();
39+
40+
// Can we get rid of this legacy sync FS function?
41+
function getRealPathSync(pathname: string): string {
42+
try {
43+
// eslint-disable-next-line no-restricted-properties
44+
return fs.realpathSync(pathname);
45+
} catch (err) {
46+
return pathname;
47+
}
48+
}
49+
50+
const tempDirReal = getRealPathSync(tempDir);
51+
const homeDirReal = getRealPathSync(homeDir);
52+
53+
return {
54+
cwd,
55+
tempDir: normalizeWindowTempDirShortPath(tempDir),
56+
tempDirReal: normalizeWindowTempDirShortPath(tempDirReal),
57+
homeDir,
58+
homeDirReal,
59+
};
60+
}
61+
62+
// We memoize it to avoid useless FS calls on each path normalization
63+
const getPathsForNormalization: typeof readPathsForNormalization = _.memoize(
64+
readPathsForNormalization,
65+
);
66+
1867
export function print(
1968
val: unknown,
2069
serialize: (val: unknown) => string,
@@ -63,9 +112,8 @@ function normalizePaths<T>(value: T): T {
63112
return value;
64113
}
65114

66-
const cwd = process.cwd();
67-
const tempDir = os.tmpdir();
68-
const homeDir = os.homedir();
115+
const {cwd, tempDir, tempDirReal, homeDir, homeDirReal} =
116+
getPathsForNormalization();
69117

70118
const homeRelativeToTemp = path.relative(tempDir, homeDir);
71119

@@ -75,17 +123,36 @@ function normalizePaths<T>(value: T): T {
75123
(val) => val.split(cwd).join('<PROJECT_ROOT>'),
76124

77125
// Replace temp directory with <TEMP_DIR>
126+
(val) => val.split(tempDirReal).join('<TEMP_DIR>'),
127+
(val) => val.split(tempDir).join('<TEMP_DIR>'),
128+
129+
(val) => val.split(tempDirReal).join('<TEMP_DIR>'),
78130
(val) => val.split(tempDir).join('<TEMP_DIR>'),
79131

80132
// Replace home directory with <HOME_DIR>
133+
(val) => val.split(homeDirReal).join('<HOME_DIR>'),
81134
(val) => val.split(homeDir).join('<HOME_DIR>'),
82135

83136
// Handle HOME_DIR nested inside TEMP_DIR
137+
// This happens on windows GitHub actions runners
138+
// tempDir: 'C:\\Users\\RUNNER~1\\AppData\\Local\\Temp',
139+
// homeDir: 'C:\\Users\\runneradmin',
84140
(val) =>
85141
val
86142
.split(`<TEMP_DIR>${path.sep + homeRelativeToTemp}`)
87143
.join('<HOME_DIR>'),
88144

145+
// replace /prefix___MKDTEMP_DIR___ABC123 with /prefix<MKDTEMP_DIR_STABLE>
146+
// The random 6-char suffix of mkdtemp() is removed to make snapshots stable
147+
(val) => {
148+
const [before, after] = val.split('___MKDTEMP_DIR___');
149+
if (after) {
150+
const afterSub = after.substring(6);
151+
return [before, afterSub].join('<MKDTEMP_DIR_STABLE>');
152+
}
153+
return before;
154+
},
155+
89156
// Replace the Docusaurus version with a stub
90157
(val) => val.split(version).join('<CURRENT_VERSION>'),
91158

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@
7878
"@crowdin/cli": "^3.13.0",
7979
"@prettier/plugin-xml": "^2.2.0",
8080
"@swc/core": "^1.7.14",
81-
"@swc/jest": "^0.2.36",
81+
"@swc/jest": "^0.2.39",
8282
"@testing-library/react-hooks": "^8.0.1",
8383
"@types/fs-extra": "^9.0.13",
84-
"@types/jest": "^29.5.12",
84+
"@types/jest": "^30.0.0",
8585
"@types/lodash": "^4.14.197",
8686
"@types/node": "^18.16.19",
8787
"@types/prompts": "^2.4.4",
@@ -98,17 +98,17 @@
9898
"eslint-config-prettier": "^8.8.0",
9999
"eslint-plugin-header": "^3.1.1",
100100
"eslint-plugin-import": "^2.27.5",
101-
"eslint-plugin-jest": "^27.2.3",
101+
"eslint-plugin-jest": "^27.9.0",
102102
"eslint-plugin-jsx-a11y": "^6.7.1",
103103
"eslint-plugin-react": "^7.32.2",
104104
"eslint-plugin-react-compiler": "^19.0.0-beta-40c6c23-20250301",
105105
"eslint-plugin-react-hooks": "^4.6.0",
106106
"eslint-plugin-regexp": "^1.15.0",
107107
"husky": "^8.0.3",
108108
"image-size": "^2.0.2",
109-
"jest": "^29.7.0",
110-
"jest-environment-jsdom": "^29.7.0",
111-
"jest-serializer-ansi-escapes": "^3.0.0",
109+
"jest": "^30.2.0",
110+
"jest-environment-jsdom": "^30.2.0",
111+
"jest-serializer-ansi-escapes": "^4.0.0",
112112
"jest-serializer-react-helmet-async": "^1.0.21",
113113
"lerna": "^6.6.2",
114114
"lerna-changelog": "^2.2.0",

packages/docusaurus-cssnano-preset/src/remove-overridden-custom-properties/__tests__/__snapshots__/index.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

33
exports[`remove-overridden-custom-properties overridden custom properties should be removed 1`] = `
44
"/* stylelint-disable docusaurus/copyright-header, declaration-block-no-duplicate-custom-properties */

packages/docusaurus-logger/src/__tests__/__snapshots__/index.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

33
exports[`error prints objects 1`] = `
44
[

packages/docusaurus-mdx-loader/src/remark/admonitions/__tests__/__snapshots__/index.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

33
exports[`admonitions remark plugin add custom keyword 1`] = `
44
"<p>The blog feature enables you to deploy in no time a full-featured blog.</p>

packages/docusaurus-mdx-loader/src/remark/toc/__tests__/__snapshots__/index.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

33
exports[`toc remark plugin does not overwrite TOC var if no TOC 1`] = `
44
"import {Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs} from "react/jsx-runtime";

packages/docusaurus-mdx-loader/src/remark/transformImage/__tests__/__snapshots__/index.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

33
exports[`transformImage plugin does not choke on invalid image 1`] = `
44
"<img alt="invalid image" src={require("!<PROJECT_ROOT>/node_modules/url-loader/dist/cjs.js?limit=10000&name=assets/images/[name]-[contenthash].[ext]&fallback=<PROJECT_ROOT>/node_modules/file-loader/dist/cjs.js!./../static/invalid.png").default} />

packages/docusaurus-mdx-loader/src/remark/transformLinks/__tests__/__snapshots__/index.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

33
exports[`transformLinks plugin transform md links to <a /> 1`] = `
44
"[asset](https://example.com/asset.pdf)

packages/docusaurus-mdx-loader/src/remark/unusedDirectives/__tests__/__snapshots__/index.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

33
exports[`directives remark plugin - client compiler default behavior for container directives: console 1`] = `
44
[

packages/docusaurus-plugin-client-redirects/src/__tests__/__snapshots__/collectRedirects.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

33
exports[`collectRedirects throw if plugin option redirects contain invalid to paths 1`] = `
44
"You are trying to create client-side redirections to invalid paths.

0 commit comments

Comments
 (0)