From 5a3bc14a82f8265498eb19b92c62cc2bcf52f3db Mon Sep 17 00:00:00 2001 From: sebastien Date: Wed, 31 Dec 2025 16:17:59 +0100 Subject: [PATCH 1/3] simplify Jest snapshotPathNormalizer.ts --- jest/snapshotPathNormalizer.ts | 43 ++++++---------------------------- 1 file changed, 7 insertions(+), 36 deletions(-) diff --git a/jest/snapshotPathNormalizer.ts b/jest/snapshotPathNormalizer.ts index b8a5ec33ab52..3777e8ff53d4 100644 --- a/jest/snapshotPathNormalizer.ts +++ b/jest/snapshotPathNormalizer.ts @@ -10,7 +10,6 @@ import os from 'os'; import path from 'path'; -import fs from 'fs'; import _ from 'lodash'; import {escapePath} from '@docusaurus/utils'; import {version} from '@docusaurus/core/package.json'; @@ -65,29 +64,27 @@ function normalizePaths(value: T): T { } const cwd = process.cwd(); - const cwdReal = getRealPath(cwd); const tempDir = os.tmpdir(); - const tempDirReal = getRealPath(tempDir); const homeDir = os.homedir(); - const homeDirReal = getRealPath(homeDir); const homeRelativeToTemp = path.relative(tempDir, homeDir); - const homeRelativeToTempReal = path.relative(tempDirReal, homeDir); - const homeRealRelativeToTempReal = path.relative(tempDirReal, homeDirReal); - const homeRealRelativeToTemp = path.relative(tempDir, homeDirReal); const runner: ((val: string) => string)[] = [ + // Remove win32 drive letters, C:\ -> \ + (val) => val.replace(/[a-zA-Z]:\\/g, '\\'), + + // Convert win32 backslash's to forward slashes, \ -> /; + // ignore some that look like escape sequences. + (val) => val.replace(/\\(?!")/g, '/'), + (val) => (val.includes('keepAnsi') ? val : stripAnsi(val)), // Replace process.cwd with - (val) => val.split(cwdReal).join(''), (val) => val.split(cwd).join(''), // Replace temp directory with - (val) => val.split(tempDirReal).join(''), (val) => val.split(tempDir).join(''), // Replace home directory with - (val) => val.split(homeDirReal).join(''), (val) => val.split(homeDir).join(''), // Handle HOME_DIR nested inside TEMP_DIR @@ -95,18 +92,6 @@ function normalizePaths(value: T): T { val .split(`${path.sep + homeRelativeToTemp}`) .join(''), - (val) => - val - .split(`${path.sep + homeRelativeToTempReal}`) - .join(''), - (val) => - val - .split(`${path.sep + homeRealRelativeToTempReal}`) - .join(''), - (val) => - val - .split(`${path.sep + homeRealRelativeToTemp}`) - .join(''), // Replace the Docusaurus version with a stub (val) => val.split(version).join(''), @@ -119,10 +104,6 @@ function normalizePaths(value: T): T { // Remove duplicate backslashes created from escapePath (val) => val.replace(/\\\\/g, '\\'), - - // Convert win32 backslash's to forward slashes, \ -> /; - // ignore some that look like escape sequences. - (val) => val.replace(/\\(?!")/g, '/'), ]; let result = value as string; @@ -136,13 +117,3 @@ function normalizePaths(value: T): T { function shouldUpdate(value: unknown) { return typeof value === 'string' && normalizePaths(value) !== value; } - -function getRealPath(pathname: string) { - try { - // eslint-disable-next-line no-restricted-properties - const realPath = fs.realpathSync(pathname); - return realPath; - } catch (err) { - return pathname; - } -} From 6f51ce28691b663213a9a95ebefe75631f16b43e Mon Sep 17 00:00:00 2001 From: sebastien Date: Wed, 31 Dec 2025 16:27:42 +0100 Subject: [PATCH 2/3] run tests on jest/** changes --- .github/workflows/tests-e2e.yml | 2 ++ .github/workflows/tests-windows.yml | 1 + .github/workflows/tests.yml | 1 + 3 files changed, 4 insertions(+) diff --git a/.github/workflows/tests-e2e.yml b/.github/workflows/tests-e2e.yml index 06c703a756fc..f5de0a51e308 100644 --- a/.github/workflows/tests-e2e.yml +++ b/.github/workflows/tests-e2e.yml @@ -9,6 +9,7 @@ on: - package.json - yarn.lock - jest.config.mjs + - jest/** - packages/** - tsconfig.*.json pull_request: @@ -19,6 +20,7 @@ on: - package.json - yarn.lock - jest.config.mjs + - jest/** - packages/** - tsconfig.*.json - admin/verdaccio.yaml diff --git a/.github/workflows/tests-windows.yml b/.github/workflows/tests-windows.yml index c1feb517e80c..b967c22d1574 100644 --- a/.github/workflows/tests-windows.yml +++ b/.github/workflows/tests-windows.yml @@ -9,6 +9,7 @@ on: - package.json - yarn.lock - jest.config.mjs + - jest/** - packages/** - tsconfig.*.json - .github/workflows/tests-windows.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9a71d589f89f..63783b627882 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,6 +9,7 @@ on: - package.json - yarn.lock - jest.config.mjs + - jest/** - packages/** - tsconfig.*.json - .github/workflows/tests.yml From a9ce23c0629951509eec82be5ee7808996feafde Mon Sep 17 00:00:00 2001 From: sebastien Date: Wed, 31 Dec 2025 19:16:39 +0100 Subject: [PATCH 3/3] revert change? --- jest/snapshotPathNormalizer.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/jest/snapshotPathNormalizer.ts b/jest/snapshotPathNormalizer.ts index 3777e8ff53d4..378344c108b5 100644 --- a/jest/snapshotPathNormalizer.ts +++ b/jest/snapshotPathNormalizer.ts @@ -70,13 +70,6 @@ function normalizePaths(value: T): T { const homeRelativeToTemp = path.relative(tempDir, homeDir); const runner: ((val: string) => string)[] = [ - // Remove win32 drive letters, C:\ -> \ - (val) => val.replace(/[a-zA-Z]:\\/g, '\\'), - - // Convert win32 backslash's to forward slashes, \ -> /; - // ignore some that look like escape sequences. - (val) => val.replace(/\\(?!")/g, '/'), - (val) => (val.includes('keepAnsi') ? val : stripAnsi(val)), // Replace process.cwd with (val) => val.split(cwd).join(''), @@ -104,6 +97,10 @@ function normalizePaths(value: T): T { // Remove duplicate backslashes created from escapePath (val) => val.replace(/\\\\/g, '\\'), + + // Convert win32 backslash's to forward slashes, \ -> /; + // ignore some that look like escape sequences. + (val) => val.replace(/\\(?!")/g, '/'), ]; let result = value as string;