diff --git a/README.md b/README.md index 78bc580..4487bc2 100644 --- a/README.md +++ b/README.md @@ -153,7 +153,7 @@ export default defineConfig({ }) ``` -After running a browser test through the extension, right-click the test in the Testing view or its editor gutter icon and select **Open Trace View**. The extension opens the generated HTML report in a reusable editor webview beside your code. Opening another test updates the same tab. Changes to the report reload the view while preserving its trace selection. +After running a browser test through the extension, right-click the test in the Testing view or its editor gutter icon and select **Open Trace View**. The extension opens the generated HTML report in a reusable editor webview beside your code. Opening another test updates the same tab. Changes to the report reload the view and reset its selection. This webview prototype loads report resources through VS Code's local-resource API without a static server. Canvas replay and snapshots referencing external resources have not been verified. diff --git a/packages/extension/src/traceView.ts b/packages/extension/src/traceView.ts index 3731250..c028532 100644 --- a/packages/extension/src/traceView.ts +++ b/packages/extension/src/traceView.ts @@ -14,7 +14,6 @@ export class TraceViewManager { private targets = new Map() private panel?: vscode.WebviewPanel private reportPath?: string - private selection = '' private watcher?: vscode.FileSystemWatcher private refreshTimer?: ReturnType private revision = 0 @@ -73,7 +72,7 @@ export class TraceViewManager { const sameReport = this.reportPath === target.reportPath this.reportPath = target.reportPath - this.selection = createTraceViewUrl(target).split('#')[1] + const selection = createTraceViewUrl(target).split('#')[1] if (!this.panel) { const panel = vscode.window.createWebviewPanel( 'vitest.traceView', @@ -82,10 +81,6 @@ export class TraceViewManager { { enableScripts: true, retainContextWhenHidden: true }, ) this.panel = panel - panel.webview.onDidReceiveMessage((message) => { - if (message.type === 'selection' && typeof message.hash === 'string') - this.selection = message.hash.replace(/^#/, '') - }) panel.onDidDispose(() => { this.panel = undefined this.watcher?.dispose() @@ -95,7 +90,7 @@ export class TraceViewManager { } this.panel.reveal(undefined, true) if (sameReport && this.panel.webview.html) { - await this.panel.webview.postMessage({ type: 'select', hash: this.selection }) + await this.panel.webview.postMessage({ type: 'select', hash: selection }) return } this.watcher?.dispose() @@ -109,10 +104,10 @@ export class TraceViewManager { } this.watcher.onDidChange(refresh) this.watcher.onDidCreate(refresh) - await this.refresh() + await this.refresh(selection) } - private async refresh() { + private async refresh(selection = '') { const panel = this.panel const reportPath = this.reportPath if (!panel || !reportPath) @@ -136,23 +131,16 @@ export class TraceViewManager { JSON.stringify(`${metadata.toString()}?v=${Date.now()}`), ) html = html.replace(/]*>/i, `$& `) panel.webview.html = html