Skip to content

Commit 24092ed

Browse files
✅ Sanitize pnpm v11 store paths in stack traces
Co-authored-by: Nicolas DUBIEN <dubzzz@users.noreply.github.com>
1 parent 862d151 commit 24092ed

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

packages/fast-check/test/e2e/__test-helpers__/StackSanitizer.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ function sanitizeStack(initialMessage: string) {
55
.join('\n')
66
.replace(/at [^(]*fast-check\/(packages|node_modules)(.*):\d+:\d+/g, 'at $1$2:?:?') // line for the spec file itself
77
.replace(/at (.*) \(.*fast-check\/(packages|node_modules)(.*):\d+:\d+\)/g, 'at $1 ($2$3:?:?)') // any import linked to internals of fast-check
8+
// pnpm v11 stores dependencies under a global virtual store (`.../store/v<N>/links/...`) instead of `<repo>/node_modules/.pnpm/`.
9+
// Re-shape unscoped (`@/<pkg>/<version>/<hash>`) and scoped (`@<scope>/<pkg>/<version>/<hash>`) store paths back into the v10
10+
// `node_modules/.pnpm/<flat-name>@<version>/...` form so the snapshot stays valid across pnpm versions.
11+
.replace(
12+
/at (.*) \(file:\/\/[^()]+?\/store\/v\d+\/links\/@\/([^/]+)\/([^/]+)\/[a-f0-9]+\/node_modules\/([^)]*?):\d+:\d+\)/g,
13+
'at $1 (node_modules/.pnpm/$2@$3/node_modules/$4:?:?)',
14+
)
15+
.replace(
16+
/at (.*) \(file:\/\/[^()]+?\/store\/v\d+\/links\/@([^/]+)\/([^/]+)\/([^/]+)\/[a-f0-9]+\/node_modules\/([^)]*?):\d+:\d+\)/g,
17+
'at $1 (node_modules/.pnpm/@$2+$3@$4/node_modules/$5:?:?)',
18+
)
819
.replace(/node_modules\/\.pnpm\/([^/]*)@([^/]*)\//g, 'node_modules/.pnpm/$1@<version>/') // drop version from pnpm modules
920
.split('\n');
1021
// Drop internals of Vitest from the stack: internals of vitest, subject to regular changes and OS dependent

0 commit comments

Comments
 (0)