diff --git a/packages/extension/src/runner.ts b/packages/extension/src/runner.ts index 57a6b95..9371b65 100644 --- a/packages/extension/src/runner.ts +++ b/packages/extension/src/runner.ts @@ -8,7 +8,7 @@ import type { TraceReportManager } from './traceReport' import crypto from 'node:crypto' import path from 'node:path' import { stripVTControlCharacters } from 'node:util' -import { basename, normalize, relative } from 'pathe' +import { basename, normalize, relative, resolve } from 'pathe' import { normalizeDriveLetter } from 'vitest-vscode-shared' import * as vscode from 'vscode' import { getConfig } from './config' @@ -111,30 +111,29 @@ export class TestRunner extends vscode.Disposable { }) }) - handle.handlers.onTestRunEnd( - async (files, unhandledError, collecting, coverage, htmlReportPath) => { - if (!collecting && htmlReportPath) { - this.traceReports?.update(this.api.id, htmlReportPath, files, this.tree) - } - const testRun = this.testRun + handle.handlers.onTestRunEnd(async (files, unhandledError, collecting, coverage) => { + if (!collecting) { + const reportPath = resolve(this.api.config.cwd, '.vitest/index.html') + this.traceReports?.update(this.api.id, reportPath, files, this.tree) + } + const testRun = this.testRun - if (!testRun) { - if (unhandledError) log.error(unhandledError) - this.endTestRun() - return - } + if (!testRun) { + if (unhandledError) log.error(unhandledError) + this.endTestRun() + return + } - if (coverage) { - await this.reportCoverage(coverage).catch((err) => { - showVitestError(`Failed to report coverage. ${err.message}`, err) - }) - } + if (coverage) { + await this.reportCoverage(coverage).catch((err) => { + showVitestError(`Failed to report coverage. ${err.message}`, err) + }) + } - if (unhandledError) testRun.appendOutput(formatTestOutput(unhandledError)) + if (unhandledError) testRun.appendOutput(formatTestOutput(unhandledError)) - if (!collecting) this.endTestRun() - }, - ) + if (!collecting) this.endTestRun() + }) handle.handlers.onConsoleLog((consoleLog) => { const testRun = this.testRun diff --git a/packages/extension/src/traceReport.ts b/packages/extension/src/traceReport.ts index b5429de..56957d7 100644 --- a/packages/extension/src/traceReport.ts +++ b/packages/extension/src/traceReport.ts @@ -2,14 +2,14 @@ import type { RunnerTask, RunnerTestFile } from 'vitest' import type { TestTree } from './testTree' import * as vscode from 'vscode' -export interface TraceReportTarget { +interface TraceReportTarget { apiId: string reportPath: string fileId: string testId: string } -export function findTraceReportTargets( +function findTraceReportTargets( apiId: string, reportPath: string, files: RunnerTestFile[], @@ -31,7 +31,7 @@ export function findTraceReportTargets( return targets } -export function createTraceReportUri(target: TraceReportTarget) { +function createTraceReportUri(target: TraceReportTarget) { const params = new URLSearchParams({ file: target.fileId, view: 'editor', diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts index 7c21589..cfd4da4 100644 --- a/packages/shared/src/index.ts +++ b/packages/shared/src/index.ts @@ -90,7 +90,6 @@ export interface ExtensionWorkerEvents { unhandledError: string, collecting?: boolean, coverage?: unknown, - htmlReportPath?: string, ) => void onCollected: (file: RunnerTestFile, collecting?: boolean) => void onTestRunStart: (files: string[]) => void diff --git a/packages/worker/src/reporter.ts b/packages/worker/src/reporter.ts index 1ca785e..d91536a 100644 --- a/packages/worker/src/reporter.ts +++ b/packages/worker/src/reporter.ts @@ -16,7 +16,6 @@ import type { Vitest as VitestCore, } from 'vitest/node' import { parseErrorStacktrace } from '@vitest/utils/source-map' -import { resolve } from 'pathe' import { ExtensionWorker } from './worker' export class VSCodeReporter implements Reporter { @@ -30,7 +29,6 @@ export class VSCodeReporter implements Reporter { private debuggerAttached: boolean | undefined = undefined private coverageData: Record | undefined = undefined private silent: boolean | 'passed-only' = false - private htmlReportPath: string | undefined constructor(meta: WorkerInitMetadata, debug: WorkerRunnerOptions['debug']) { this.setupFilePaths = meta.setupFilePaths @@ -45,18 +43,6 @@ export class VSCodeReporter implements Reporter { this.configureAttachDebugging(vitest) this.silent = vitest.config.silent - for (const reporter of vitest.config.reporters) { - if (Array.isArray(reporter) && reporter[0] === 'html') { - const options = reporter[1] as { outputDir?: string } - this.htmlReportPath = resolve( - vitest.config.root, - options.outputDir || '.vitest', - 'index.html', - ) - break - } - } - vitest.projects.forEach((project) => { this.ensureSetupFileIsAllowed(project.vite.config) this.ensurePnpSuported(project.config) @@ -203,7 +189,7 @@ export class VSCodeReporter implements Reporter { // as any because Vitest types are different between v3 and v4, // and shared packages uses the lowest Vitest version - this.rpc.onTestRunEnd(files as any, '', false, coverage, this.htmlReportPath) + this.rpc.onTestRunEnd(files as any, '', false, coverage) } onTestModuleCollected(testModule: TestModule) { diff --git a/test/unit/traceReport.test.ts b/test/unit/traceReport.test.ts deleted file mode 100644 index 367cd88..0000000 --- a/test/unit/traceReport.test.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { expect } from 'chai' -import { - createTraceReportUri, - findTraceReportTargets, -} from '../../packages/extension/src/traceReport' - -describe('trace reports', () => { - it('finds tests with browser trace artifacts', () => { - const targets = findTraceReportTargets('api', '/root/.vitest/index.html', [ - { - id: 'file-id', - type: 'suite', - tasks: [ - { - id: 'suite-id', - type: 'suite', - tasks: [ - { - id: 'trace-test-id', - type: 'test', - artifacts: [{ type: 'internal:browserTrace' }], - }, - { - id: 'regular-test-id', - type: 'test', - artifacts: [], - }, - ], - }, - ], - } as any, - ]) - - expect(targets).to.deep.equal([ - { - apiId: 'api', - reportPath: '/root/.vitest/index.html', - fileId: 'file-id', - testId: 'trace-test-id', - }, - ]) - }) - - it('creates a URL that opens the first trace step', () => { - const uri = createTraceReportUri({ - apiId: 'api', - reportPath: '/root/.vitest/index.html', - fileId: 'file-id', - testId: 'test-id', - }) - - expect(uri.fsPath.replaceAll('\\', '/')).to.equal('/root/.vitest/index.html') - expect(Object.fromEntries(new URLSearchParams(uri.fragment.slice(2)))).to.deep.equal({ - file: 'file-id', - view: 'editor', - test: 'test-id', - traceStep: '0', - }) - }) -})