@@ -4,11 +4,11 @@ import type { VitestBrowserClientMocker } from './mocker'
44import { globalChannel , onCancel } from '@vitest/browser/client'
55import { page , userEvent } from '@vitest/browser/context'
66import {
7+ DecodedMap ,
8+ getOriginalPosition ,
79 loadDiffConfig ,
810 loadSnapshotSerializers ,
9- originalPositionFor ,
1011 takeCoverageInsideWorker ,
11- TraceMap ,
1212} from 'vitest/internal/browser'
1313import { NodeBenchmarkRunner , VitestTestRunner } from 'vitest/runners'
1414import { createStackString , parseStacktrace } from '../../../../utils/src/source-map'
@@ -154,20 +154,11 @@ export function createBrowserRunner(
154154 return rpc ( ) . onTaskAnnotate ( test . id , annotation )
155155 }
156156
157- const traceMap = new TraceMap ( map as any )
158- const { line, column, source } = originalPositionFor ( traceMap , annotation . location )
159- if ( line != null && column != null && source != null ) {
160- let file : string = annotation . location . file
161- if ( source ) {
162- const fileUrl = annotation . location . file . startsWith ( 'file://' )
163- ? annotation . location . file
164- : `file://${ annotation . location . file } `
165- const sourceRootUrl = map . sourceRoot
166- ? new URL ( map . sourceRoot , fileUrl )
167- : fileUrl
168- file = new URL ( source , sourceRootUrl ) . pathname
169- }
170-
157+ const traceMap = new DecodedMap ( map as any , annotation . location . file )
158+ const position = getOriginalPosition ( traceMap , annotation . location )
159+ if ( position ) {
160+ const { source, column, line } = position
161+ const file = source || annotation . location . file
171162 annotation . location = {
172163 line,
173164 column : column + 1 ,
@@ -261,7 +252,7 @@ async function getTraceMap(file: string, sourceMaps: Map<string, any>) {
261252 if ( ! result ) {
262253 return null
263254 }
264- return new TraceMap ( result as any )
255+ return new DecodedMap ( result as any , file )
265256}
266257
267258async function updateTestFilesLocations ( files : File [ ] , sourceMaps : Map < string , any > ) {
@@ -272,8 +263,9 @@ async function updateTestFilesLocations(files: File[], sourceMaps: Map<string, a
272263 }
273264 const updateLocation = ( task : Task ) => {
274265 if ( task . location ) {
275- const { line, column } = originalPositionFor ( traceMap , task . location )
276- if ( line != null && column != null ) {
266+ const position = getOriginalPosition ( traceMap , task . location )
267+ if ( position ) {
268+ const { line, column } = position
277269 task . location = { line, column : task . each ? column : column + 1 }
278270 }
279271 }
0 commit comments