Skip to content

Commit ed255d5

Browse files
committed
fixup! lib: cache source maps in vm sources
1 parent 30587f7 commit ed255d5

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

test/common/assertSnapshot.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,20 @@ function replaceWindowsPaths(str) {
3333
return common.isWindows ? str.replaceAll(path.win32.sep, path.posix.sep) : str;
3434
}
3535

36-
function replaceFullPaths(str) {
37-
return str.replaceAll(process.cwd(), '');
36+
function replaceWindowsDriveLetter(str) {
37+
if (!common.isWindows) {
38+
return str;
39+
}
40+
const currentDriveLetter = path.parse(process.cwd()).root.substring(0, 1).toLowerCase();
41+
const regex = new RegExp(`${currentDriveLetter}:`, 'gi');
42+
return str.replaceAll(regex, '');
43+
}
44+
45+
function transformCwd(replacement = '') {
46+
const cwd = process.cwd();
47+
return (str) => {
48+
return str.replaceAll(cwd, replacement);
49+
}
3850
}
3951

4052
function transform(...args) {
@@ -97,12 +109,13 @@ module.exports = {
97109
assertSnapshot,
98110
getSnapshotPath,
99111
replaceExperimentalWarning,
100-
replaceFullPaths,
101112
replaceNodeVersion,
102113
replaceStackTrace,
103114
replaceInternalStackTrace,
104115
replaceWindowsLineEndings,
105116
replaceWindowsPaths,
117+
replaceWindowsDriveLetter,
106118
spawnAndAssert,
107119
transform,
120+
transformCwd,
108121
};

test/parallel/test-node-output-sourcemaps.mjs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,18 @@
1-
import * as common from '../common/index.mjs';
1+
import '../common/index.mjs';
22
import * as fixtures from '../common/fixtures.mjs';
33
import * as snapshot from '../common/assertSnapshot.js';
4-
import * as path from 'node:path';
54
import { describe, it } from 'node:test';
65

76
describe('sourcemaps output', { concurrency: true }, () => {
8-
function normalize(str) {
9-
const result = str
10-
.replaceAll(snapshot.replaceWindowsPaths(process.cwd()), '*');
11-
12-
if (common.isWindows) {
13-
const currentDeviceLetter = path.parse(process.cwd()).root.substring(0, 1).toLowerCase();
14-
const regex = new RegExp(`${currentDeviceLetter}:/?`, 'gi');
15-
return result.replaceAll(regex, '');
16-
}
17-
return result;
18-
}
197
const defaultTransform = snapshot
208
.transform(
219
snapshot.replaceWindowsLineEndings,
10+
snapshot.transformCwd('*'),
2211
snapshot.replaceWindowsPaths,
12+
// Remove drive letters from synthethized paths (i.e. not cwd).
13+
snapshot.replaceWindowsDriveLetter,
2314
snapshot.replaceInternalStackTrace,
2415
snapshot.replaceExperimentalWarning,
25-
normalize,
2616
snapshot.replaceNodeVersion
2717
);
2818

test/parallel/test-runner-output.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const defaultTransform = snapshot.transform(
6161
snapshot.replaceWindowsLineEndings,
6262
snapshot.replaceStackTrace,
6363
removeWindowsPathEscaping,
64-
snapshot.replaceFullPaths,
64+
snapshot.transformCwd(),
6565
snapshot.replaceWindowsPaths,
6666
replaceTestDuration,
6767
replaceTestLocationLine,
@@ -79,7 +79,7 @@ const junitTransform = snapshot.transform(
7979
const lcovTransform = snapshot.transform(
8080
snapshot.replaceWindowsLineEndings,
8181
snapshot.replaceStackTrace,
82-
snapshot.replaceFullPaths,
82+
snapshot.transformCwd(),
8383
snapshot.replaceWindowsPaths,
8484
pickTestFileFromLcov
8585
);

0 commit comments

Comments
 (0)