Skip to content

Commit 7bfb41f

Browse files
authored
test(jest): simplify Jest snapshotPathNormalizer.ts (#11639)
1 parent e5ab150 commit 7bfb41f

File tree

4 files changed

+4
-32
lines changed

4 files changed

+4
-32
lines changed

.github/workflows/tests-e2e.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
- package.json
1010
- yarn.lock
1111
- jest.config.mjs
12+
- jest/**
1213
- packages/**
1314
- tsconfig.*.json
1415
pull_request:
@@ -19,6 +20,7 @@ on:
1920
- package.json
2021
- yarn.lock
2122
- jest.config.mjs
23+
- jest/**
2224
- packages/**
2325
- tsconfig.*.json
2426
- admin/verdaccio.yaml

.github/workflows/tests-windows.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
- package.json
1010
- yarn.lock
1111
- jest.config.mjs
12+
- jest/**
1213
- packages/**
1314
- tsconfig.*.json
1415
- .github/workflows/tests-windows.yml

.github/workflows/tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
- package.json
1010
- yarn.lock
1111
- jest.config.mjs
12+
- jest/**
1213
- packages/**
1314
- tsconfig.*.json
1415
- .github/workflows/tests.yml

jest/snapshotPathNormalizer.ts

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import os from 'os';
1212
import path from 'path';
13-
import fs from 'fs';
1413
import _ from 'lodash';
1514
import {escapePath} from '@docusaurus/utils';
1615
import {version} from '@docusaurus/core/package.json';
@@ -65,48 +64,27 @@ function normalizePaths<T>(value: T): T {
6564
}
6665

6766
const cwd = process.cwd();
68-
const cwdReal = getRealPath(cwd);
6967
const tempDir = os.tmpdir();
70-
const tempDirReal = getRealPath(tempDir);
7168
const homeDir = os.homedir();
72-
const homeDirReal = getRealPath(homeDir);
7369

7470
const homeRelativeToTemp = path.relative(tempDir, homeDir);
75-
const homeRelativeToTempReal = path.relative(tempDirReal, homeDir);
76-
const homeRealRelativeToTempReal = path.relative(tempDirReal, homeDirReal);
77-
const homeRealRelativeToTemp = path.relative(tempDir, homeDirReal);
7871

7972
const runner: ((val: string) => string)[] = [
8073
(val) => (val.includes('keepAnsi') ? val : stripAnsi(val)),
8174
// Replace process.cwd with <PROJECT_ROOT>
82-
(val) => val.split(cwdReal).join('<PROJECT_ROOT>'),
8375
(val) => val.split(cwd).join('<PROJECT_ROOT>'),
8476

8577
// Replace temp directory with <TEMP_DIR>
86-
(val) => val.split(tempDirReal).join('<TEMP_DIR>'),
8778
(val) => val.split(tempDir).join('<TEMP_DIR>'),
8879

8980
// Replace home directory with <HOME_DIR>
90-
(val) => val.split(homeDirReal).join('<HOME_DIR>'),
9181
(val) => val.split(homeDir).join('<HOME_DIR>'),
9282

9383
// Handle HOME_DIR nested inside TEMP_DIR
9484
(val) =>
9585
val
9686
.split(`<TEMP_DIR>${path.sep + homeRelativeToTemp}`)
9787
.join('<HOME_DIR>'),
98-
(val) =>
99-
val
100-
.split(`<TEMP_DIR>${path.sep + homeRelativeToTempReal}`)
101-
.join('<HOME_DIR>'),
102-
(val) =>
103-
val
104-
.split(`<TEMP_DIR>${path.sep + homeRealRelativeToTempReal}`)
105-
.join('<HOME_DIR>'),
106-
(val) =>
107-
val
108-
.split(`<TEMP_DIR>${path.sep + homeRealRelativeToTemp}`)
109-
.join('<HOME_DIR>'),
11088

11189
// Replace the Docusaurus version with a stub
11290
(val) => val.split(version).join('<CURRENT_VERSION>'),
@@ -136,13 +114,3 @@ function normalizePaths<T>(value: T): T {
136114
function shouldUpdate(value: unknown) {
137115
return typeof value === 'string' && normalizePaths(value) !== value;
138116
}
139-
140-
function getRealPath(pathname: string) {
141-
try {
142-
// eslint-disable-next-line no-restricted-properties
143-
const realPath = fs.realpathSync(pathname);
144-
return realPath;
145-
} catch (err) {
146-
return pathname;
147-
}
148-
}

0 commit comments

Comments
 (0)