| 55 | coverageModule: CoverageHandler | null, |
| 56 | ): { new (options: BrowserRunnerOptions): BrowserVitestRunner } { |
| 57 | return class BrowserTestRunner extends runnerClass implements VitestRunner { |
| 58 | public config: SerializedConfig |
| 59 | hashMap = browserHashMap |
| 60 | public sourceMapCache = new Map<string, any>() |
| 61 | public method = 'run' as TestExecutionMethod |
| 62 | private commands: CommandsManager |
| 63 | private _otel!: Traces |
| 64 | |
| 65 | constructor(options: BrowserRunnerOptions) { |
| 66 | super(options.config) |
| 67 | this.config = options.config |
| 68 | this.commands = getBrowserState().commands |
| 69 | this.viteEnvironment = '__browser__' |
| 70 | this._otel = getBrowserState().traces |
| 71 | } |
| 72 | |
| 73 | setMethod(method: TestExecutionMethod) { |
| 74 | this.method = method |
| 75 | } |
| 76 | |
| 77 | private traces = new Map<string, string[]>() |
| 78 | |
| 79 | onBeforeTryTask: VitestRunner['onBeforeTryTask'] = async (...args) => { |
| 80 | await userEvent.cleanup() |
| 81 | await super.onBeforeTryTask?.(...args) |
| 82 | const trace = this.config.browser.trace |
| 83 | const test = args[0] |
| 84 | const { retry, repeats } = args[1] |
| 85 | const shouldTrace = trace !== 'off' |
| 86 | && !(trace === 'on-all-retries' && retry === 0) |
| 87 | && !(trace === 'on-first-retry' && retry !== 1) |
| 88 | if (!shouldTrace) { |
| 89 | getBrowserState().activeTraceTaskIds.delete(test.id) |
| 90 | return |
| 91 | } |
| 92 | getBrowserState().activeTraceTaskIds.add(test.id) |
| 93 | let title = getTestName(test) |
| 94 | if (retry) { |
| 95 | title += ` (retry x${retry})` |
| 96 | } |
| 97 | if (repeats) { |
| 98 | title += ` (repeat x${repeats})` |
| 99 | } |
| 100 | |
| 101 | const name = getTraceName(test, retry, repeats) |
| 102 | await this.commands.triggerCommand( |
| 103 | '__vitest_startChunkTrace', |
| 104 | [{ name, title }], |
| 105 | ) |
| 106 | } |
| 107 | |
| 108 | onAfterRetryTask = async (test: Test, { retry, repeats }: { retry: number; repeats: number }) => { |
| 109 | if (!getBrowserState().activeTraceTaskIds.has(test.id)) { |
| 110 | return |
| 111 | } |
| 112 | await this.commands.triggerCommand('__vitest_markTrace', [{ |
| 113 | name: `onAfterRetryTask [${test.result?.state}]`, |
| 114 | stack: test.result?.errors?.[0].stack, |
nothing calls this directly
no test coverage detected