Skip to content

Commit 60e2351

Browse files
committed
test: normalize asset paths in snapshots
1 parent d98960a commit 60e2351

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

test/__snapshots__/minify-option.test.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ Array [
1717

1818
exports[`minify option should report an error when the \`extractComments\` option for \`swcMinify\` uses a function condition: assets 1`] = `
1919
Object {
20-
"203.203.js": "Error: ENOENT: no such file or directory, open '/Users/kdy1/.codex/worktrees/72b5/terser-webpack-plugin/test/helpers/dist/203.203.js'",
21-
"main.js": "Error: ENOENT: no such file or directory, open '/Users/kdy1/.codex/worktrees/72b5/terser-webpack-plugin/test/helpers/dist/main.js'",
20+
"203.203.js": "Error: ENOENT: no such file or directory, open 'test/helpers/dist/203.203.js'",
21+
"main.js": "Error: ENOENT: no such file or directory, open 'test/helpers/dist/main.js'",
2222
}
2323
`;
2424

test/helpers/readAsset.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
import path from "path";
22

3+
/**
4+
* @param {string} value value
5+
* @returns {string} value without cwd
6+
*/
7+
function removeCWD(value) {
8+
const isWin = process.platform === "win32";
9+
let normalizedValue = value;
10+
let cwd = process.cwd();
11+
12+
if (isWin) {
13+
normalizedValue = normalizedValue.replace(/\\/g, "/");
14+
cwd = cwd.replace(/\\/g, "/");
15+
}
16+
17+
const cwdPrefix = `${cwd}/`;
18+
19+
return normalizedValue.split(cwdPrefix).join("");
20+
}
21+
322
/**
423
* @param {string} asset asset name
524
* @param {import("webpack").Compiler} compiler compiler
@@ -22,7 +41,7 @@ export default (asset, compiler, stats) => {
2241
try {
2342
data = usedFs.readFileSync(path.join(outputPath, targetFile)).toString();
2443
} catch (error) {
25-
data = error.toString();
44+
data = removeCWD(error.toString());
2645
}
2746

2847
return data;

0 commit comments

Comments
 (0)