Skip to content

Commit

Permalink
fix: fix sourcemap in vm pools
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Jan 29, 2024
1 parent b1462a4 commit 89d5315
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/vitest/src/runtime/runVmTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import timers from 'node:timers'
import { performance } from 'node:perf_hooks'
import { startTests } from '@vitest/runner'
import { createColors, setupColors } from '@vitest/utils'
import { installSourcemapsSupport } from 'vite-node/source-map'
import { setupChaiConfig } from '../integrations/chai/config'
import { startCoverageInsideWorker, stopCoverageInsideWorker } from '../integrations/coverage'
import type { ResolvedConfig } from '../types'
Expand All @@ -18,6 +19,10 @@ import { setupCommonEnv } from './setup-common'
export async function run(files: string[], config: ResolvedConfig, executor: VitestExecutor): Promise<void> {
const workerState = getWorkerState()

installSourcemapsSupport({
getSourceMap: source => workerState.moduleCache.getSourceMap(source),
})

await setupCommonEnv(config)

Object.defineProperty(globalThis, '__vitest_index__', {
Expand Down
22 changes: 22 additions & 0 deletions test/stacktraces/test/__snapshots__/runner.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,28 @@ Error: Something truly horrible has happened!
"
`;

exports[`stacktrace in vmThreads 1`] = `
"⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯
FAIL error-with-stack.test.js > error in deps
Error: Something truly horrible has happened!
❯ d error-with-stack.test.js:20:9
18|
19| function d() {
20| throw new Error('Something truly horrible has happened!')
| ^
21| }
22|
❯ c error-with-stack.test.js:16:3
❯ b error-with-stack.test.js:12:3
❯ a error-with-stack.test.js:8:3
❯ error-with-stack.test.js:4:3
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯
"
`;

exports[`stacktrace should print error frame source file correctly > error-in-deps > error-in-deps 1`] = `
"⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯
Expand Down
11 changes: 11 additions & 0 deletions test/stacktraces/test/runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,14 @@ describe('stacktrace filtering', async () => {
expect(stderr).toMatchSnapshot('stacktrace-filtering')
}, 30000)
})

it('stacktrace in vmThreads', async () => {
const root = resolve(__dirname, '../fixtures')
const testFile = resolve(root, './error-with-stack.test.js')
const { stderr } = await runVitest({
root,
pool: 'vmThreads',
}, [testFile])

expect(stderr).toMatchSnapshot()
}, 3000)

0 comments on commit 89d5315

Please sign in to comment.