diff --git a/packages/vitest/src/runtime/runVmTests.ts b/packages/vitest/src/runtime/runVmTests.ts index 6f241a0d8912..d022370d2890 100644 --- a/packages/vitest/src/runtime/runVmTests.ts +++ b/packages/vitest/src/runtime/runVmTests.ts @@ -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' @@ -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) diff --git a/test/stacktraces/test/__snapshots__/runner.test.ts.snap b/test/stacktraces/test/__snapshots__/runner.test.ts.snap index 1ec6515c94cb..91a73a22ac5c 100644 --- a/test/stacktraces/test/__snapshots__/runner.test.ts.snap +++ b/test/stacktraces/test/__snapshots__/runner.test.ts.snap @@ -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 ⎯⎯⎯⎯⎯⎯⎯ diff --git a/test/stacktraces/test/runner.test.ts b/test/stacktraces/test/runner.test.ts index a4e165760fe1..c8a7c4edfca1 100644 --- a/test/stacktraces/test/runner.test.ts +++ b/test/stacktraces/test/runner.test.ts @@ -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)