mirror of
https://github.com/facebook/docusaurus.git
synced 2025-12-31 23:54:25 +00:00
test(jest): simplify Jest snapshotPathNormalizer.ts (#11639)
Some checks are pending
Argos CI / take-screenshots (push) Waiting to run
Build Hash Router / Build Hash Router (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
Continuous Releases / Continuous Releases (push) Waiting to run
E2E Tests / E2E — Yarn v1 (20) (push) Waiting to run
E2E Tests / E2E — Yarn v1 (20.0) (push) Waiting to run
E2E Tests / E2E — Yarn v1 (22) (push) Waiting to run
E2E Tests / E2E — Yarn v1 (24) (push) Waiting to run
E2E Tests / E2E — Yarn v1 (25.1) (push) Waiting to run
E2E Tests / E2E — Yarn v1 Windows (push) Waiting to run
E2E Tests / E2E — Yarn Berry (node-modules, -s) (push) Waiting to run
E2E Tests / E2E — Yarn Berry (node-modules, -st) (push) Waiting to run
E2E Tests / E2E — Yarn Berry (pnp, -s) (push) Waiting to run
E2E Tests / E2E — Yarn Berry (pnp, -st) (push) Waiting to run
E2E Tests / E2E — npm (push) Waiting to run
E2E Tests / E2E — pnpm (push) Waiting to run
Some checks are pending
Argos CI / take-screenshots (push) Waiting to run
Build Hash Router / Build Hash Router (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
Continuous Releases / Continuous Releases (push) Waiting to run
E2E Tests / E2E — Yarn v1 (20) (push) Waiting to run
E2E Tests / E2E — Yarn v1 (20.0) (push) Waiting to run
E2E Tests / E2E — Yarn v1 (22) (push) Waiting to run
E2E Tests / E2E — Yarn v1 (24) (push) Waiting to run
E2E Tests / E2E — Yarn v1 (25.1) (push) Waiting to run
E2E Tests / E2E — Yarn v1 Windows (push) Waiting to run
E2E Tests / E2E — Yarn Berry (node-modules, -s) (push) Waiting to run
E2E Tests / E2E — Yarn Berry (node-modules, -st) (push) Waiting to run
E2E Tests / E2E — Yarn Berry (pnp, -s) (push) Waiting to run
E2E Tests / E2E — Yarn Berry (pnp, -st) (push) Waiting to run
E2E Tests / E2E — npm (push) Waiting to run
E2E Tests / E2E — pnpm (push) Waiting to run
This commit is contained in:
parent
e5ab150e8b
commit
7bfb41f453
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ on:
|
|||
- package.json
|
||||
- yarn.lock
|
||||
- jest.config.mjs
|
||||
- jest/**
|
||||
- packages/**
|
||||
- tsconfig.*.json
|
||||
- .github/workflows/tests-windows.yml
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ on:
|
|||
- package.json
|
||||
- yarn.lock
|
||||
- jest.config.mjs
|
||||
- jest/**
|
||||
- packages/**
|
||||
- tsconfig.*.json
|
||||
- .github/workflows/tests.yml
|
||||
|
|
|
|||
|
|
@ -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,20 @@ function normalizePaths<T>(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)[] = [
|
||||
(val) => (val.includes('keepAnsi') ? val : stripAnsi(val)),
|
||||
// Replace process.cwd with <PROJECT_ROOT>
|
||||
(val) => val.split(cwdReal).join('<PROJECT_ROOT>'),
|
||||
(val) => val.split(cwd).join('<PROJECT_ROOT>'),
|
||||
|
||||
// Replace temp directory with <TEMP_DIR>
|
||||
(val) => val.split(tempDirReal).join('<TEMP_DIR>'),
|
||||
(val) => val.split(tempDir).join('<TEMP_DIR>'),
|
||||
|
||||
// Replace home directory with <HOME_DIR>
|
||||
(val) => val.split(homeDirReal).join('<HOME_DIR>'),
|
||||
(val) => val.split(homeDir).join('<HOME_DIR>'),
|
||||
|
||||
// Handle HOME_DIR nested inside TEMP_DIR
|
||||
|
|
@ -95,18 +85,6 @@ function normalizePaths<T>(value: T): T {
|
|||
val
|
||||
.split(`<TEMP_DIR>${path.sep + homeRelativeToTemp}`)
|
||||
.join('<HOME_DIR>'),
|
||||
(val) =>
|
||||
val
|
||||
.split(`<TEMP_DIR>${path.sep + homeRelativeToTempReal}`)
|
||||
.join('<HOME_DIR>'),
|
||||
(val) =>
|
||||
val
|
||||
.split(`<TEMP_DIR>${path.sep + homeRealRelativeToTempReal}`)
|
||||
.join('<HOME_DIR>'),
|
||||
(val) =>
|
||||
val
|
||||
.split(`<TEMP_DIR>${path.sep + homeRealRelativeToTemp}`)
|
||||
.join('<HOME_DIR>'),
|
||||
|
||||
// Replace the Docusaurus version with a stub
|
||||
(val) => val.split(version).join('<CURRENT_VERSION>'),
|
||||
|
|
@ -136,13 +114,3 @@ function normalizePaths<T>(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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue