Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix sourcemap in vm pools #5063

Merged
merged 2 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 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
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)