Skip to content

Commit

Permalink
fix: fix sourcemap in vm pools (#5063)
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Jan 29, 2024
1 parent bed252e commit 8110540
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
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 Down Expand Up @@ -44,6 +45,10 @@ export async function run(files: string[], config: ResolvedConfig, executor: Vit
timers,
}

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

await startCoverageInsideWorker(config.coverage, executor)

if (config.chaiConfig)
Expand Down
22 changes: 22 additions & 0 deletions test/stacktraces/test/__snapshots__/runner.test.ts.snap
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
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 8110540

Please sign in to comment.