Skip to content

Commit 8110540

Browse files
authoredJan 29, 2024
fix: fix sourcemap in vm pools (#5063)
1 parent bed252e commit 8110540

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed
 

‎packages/vitest/src/runtime/runVmTests.ts

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import timers from 'node:timers'
55
import { performance } from 'node:perf_hooks'
66
import { startTests } from '@vitest/runner'
77
import { createColors, setupColors } from '@vitest/utils'
8+
import { installSourcemapsSupport } from 'vite-node/source-map'
89
import { setupChaiConfig } from '../integrations/chai/config'
910
import { startCoverageInsideWorker, stopCoverageInsideWorker } from '../integrations/coverage'
1011
import type { ResolvedConfig } from '../types'
@@ -44,6 +45,10 @@ export async function run(files: string[], config: ResolvedConfig, executor: Vit
4445
timers,
4546
}
4647

48+
installSourcemapsSupport({
49+
getSourceMap: source => workerState.moduleCache.getSourceMap(source),
50+
})
51+
4752
await startCoverageInsideWorker(config.coverage, executor)
4853

4954
if (config.chaiConfig)

‎test/stacktraces/test/__snapshots__/runner.test.ts.snap

+22
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,28 @@ Error: Something truly horrible has happened!
2121
"
2222
`;
2323

24+
exports[`stacktrace in vmThreads 1`] = `
25+
"⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯
26+
27+
FAIL error-with-stack.test.js > error in deps
28+
Error: Something truly horrible has happened!
29+
❯ d error-with-stack.test.js:20:9
30+
18|
31+
19| function d() {
32+
20| throw new Error('Something truly horrible has happened!')
33+
| ^
34+
21| }
35+
22|
36+
❯ c error-with-stack.test.js:16:3
37+
❯ b error-with-stack.test.js:12:3
38+
❯ a error-with-stack.test.js:8:3
39+
❯ error-with-stack.test.js:4:3
40+
41+
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯
42+
43+
"
44+
`;
45+
2446
exports[`stacktrace should print error frame source file correctly > error-in-deps > error-in-deps 1`] = `
2547
"⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯
2648

‎test/stacktraces/test/runner.test.ts

+11
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,14 @@ describe('stacktrace filtering', async () => {
6666
expect(stderr).toMatchSnapshot('stacktrace-filtering')
6767
}, 30000)
6868
})
69+
70+
it('stacktrace in vmThreads', async () => {
71+
const root = resolve(__dirname, '../fixtures')
72+
const testFile = resolve(root, './error-with-stack.test.js')
73+
const { stderr } = await runVitest({
74+
root,
75+
pool: 'vmThreads',
76+
}, [testFile])
77+
78+
expect(stderr).toMatchSnapshot()
79+
}, 3000)

0 commit comments

Comments
 (0)
Please sign in to comment.