Skip to content

Commit

Permalink
chore(trace-viewer): ensure unselected testModel traceViewer are cl…
Browse files Browse the repository at this point in the history
…osed
  • Loading branch information
ruifigueira committed Jul 26, 2024
1 parent f01b9d4 commit 643d3c3
Showing 2 changed files with 15 additions and 14 deletions.
27 changes: 14 additions & 13 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -27,7 +27,6 @@ import { TestTree } from './testTree';
import { NodeJSNotFoundError, ansiToHtml, getPlaywrightInfo } from './utils';
import * as vscodeTypes from './vscodeTypes';
import { WorkspaceChange, WorkspaceObserver } from './workspaceObserver';
import { TraceViewer } from './traceViewer';
import { registerTerminalLinkProvider } from './terminalLinkProvider';
import { RunHooks, TestConfig } from './playwrightTestTypes';

@@ -67,7 +66,6 @@ export class Extension implements RunHooks {
private _debugHighlight: DebugHighlight;
private _isUnderTest: boolean;
private _reusedBrowser: ReusedBrowser;
private _currentTraceViewer?: TraceViewer;
private _settingsModel: SettingsModel;
private _settingsView!: SettingsView;
private _diagnostics: vscodeTypes.DiagnosticCollection;
@@ -228,6 +226,13 @@ export class Extension implements RunHooks {
this._diagnostics,
this._treeItemObserver,
this._models,
this._models.onUpdated(() => {
const selectedModel = this._models.selectedModel();
for (const model of this._models.models()) {
if (model !== selectedModel)
model.traceViewer()?.close();
}
}),
registerTerminalLinkProvider(this._vscode),
];
const fileSystemWatchers = [
@@ -485,7 +490,7 @@ export class Extension implements RunHooks {
// if trace viewer is currently displaying the trace file about to be replaced, it needs to be refreshed
const prevTrace = (testItem as any)[traceUrlSymbol];
(testItem as any)[traceUrlSymbol] = trace;
if (enqueuedSingleTest || prevTrace === this._currentTraceViewer?.currentFile())
if (enqueuedSingleTest || prevTrace === this._traceViewer()?.currentFile())
this._showTrace(testItem);

if (result.status === test.expectedStatus) {
@@ -537,7 +542,7 @@ export class Extension implements RunHooks {
if (isDebug) {
await model.debugTests(items, testListener, testRun.token);
} else {
await this._enabledTraceView()?.willRunTests();
await this._traceViewer()?.willRunTests();
await model.runTests(items, testListener, testRun.token);
}
}
@@ -757,24 +762,20 @@ export class Extension implements RunHooks {
private _showTrace(testItem: vscodeTypes.TestItem) {
const traceUrl = (testItem as any)[traceUrlSymbol];
if (traceUrl)
this._enabledTraceView()?.open(traceUrl);
this._traceViewer()?.open(traceUrl);
}

private _treeItemSelected(treeItem: vscodeTypes.TreeItem | null) {
if (!treeItem)
return;
const traceUrl = (treeItem as any)[traceUrlSymbol] || '';
if (!traceUrl && !this._currentTraceViewer?.isStarted())
if (!traceUrl && !this._traceViewer()?.isStarted())
return;
this._enabledTraceView()?.open(traceUrl);
this._traceViewer()?.open(traceUrl);
}

private _enabledTraceView() {
const traceViewer = this._models.selectedModel()?.enabledTraceViewer();
if (traceViewer !== this._currentTraceViewer)
this._currentTraceViewer?.close();
this._currentTraceViewer = traceViewer;
return traceViewer;
private _traceViewer() {
return this._models.selectedModel()?.traceViewer();
}

private _queueCommand<T>(callback: () => Promise<T>, defaultValue: T): Promise<T> {
2 changes: 1 addition & 1 deletion src/testModel.ts
Original file line number Diff line number Diff line change
@@ -103,7 +103,7 @@ export class TestModel extends DisposableBase {
);
}

enabledTraceViewer() {
traceViewer() {
if (!this._options.settingsModel.showTrace.get())
return;
if (this._spawnTraceViewer.checkVersion())

0 comments on commit 643d3c3

Please sign in to comment.