Skip to content

Commit

Permalink
fix(trace-viewer): don't show trace on debug
Browse files Browse the repository at this point in the history
  • Loading branch information
ruifigueira committed Aug 13, 2024
1 parent f23b3f5 commit 143e22f
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,11 @@ export class Extension implements RunHooks {
const testItem = this._testTree.testItemForTest(test);
if (testItem) {
testRun.started(testItem);
const fullProject = ancestorProject(test);
const traceUrl = `${fullProject.outputDir}/.playwright-artifacts-${result.workerIndex}/traces/${test.id}.json`;
let traceUrl: string | undefined;
if (!isDebug) {
const fullProject = ancestorProject(test);
traceUrl = `${fullProject.outputDir}/.playwright-artifacts-${result.workerIndex}/traces/${test.id}.json`;
}
(testItem as any)[traceUrlSymbol] = traceUrl;
}

Expand Down
7 changes: 7 additions & 0 deletions tests/mock/vscode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ export class TestItem {
tags: readonly TestTag[] = [];
canResolveChildren = false;
status: 'none' | 'enqueued' | 'started' | 'skipped' | 'failed' | 'passed' = 'none';
_didChangeStatus = new EventEmitter<TestItem>();
onDidChangeStatus = this._didChangeStatus.event;

constructor(
readonly testController: TestController,
Expand Down Expand Up @@ -411,26 +413,31 @@ export class TestRun {

enqueued(test: TestItem) {
test.status = 'enqueued';
test._didChangeStatus.fire(test);
this._log(test, { status: 'enqueued' });
}

started(test: TestItem) {
test.status = 'started';
test._didChangeStatus.fire(test);
this._log(test, { status: 'started' });
}

skipped(test: TestItem) {
test.status = 'skipped';
test._didChangeStatus.fire(test);
this._log(test, { status: 'skipped' });
}

failed(test: TestItem, messages: TestMessage[], duration?: number) {
test.status = 'failed';
test._didChangeStatus.fire(test);
this._log(test, { status: 'failed', duration, messages });
}

passed(test: TestItem, duration?: number) {
test.status = 'passed';
test._didChangeStatus.fire(test);
this._log(test, { status: 'passed', duration });
}

Expand Down
83 changes: 82 additions & 1 deletion tests/trace-viewer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,17 @@
*/

import { enableConfigs, expect, selectConfig, selectTestItem, test, traceViewerInfo } from './utils';
import { TestItem } from './mock/vscode';

test.skip(({ traceViewerMode }) => !traceViewerMode);

async function waitForTestItemStatus(testItem: TestItem, status: TestItem['status']) {
await new Promise<void>(resolve => testItem.onDidChangeStatus(() => {
if (testItem.status === status)
resolve();
}));
}

test('@smoke should open trace viewer', async ({ activate, traceViewerMode }) => {
const { vscode, testController } = await activate({
'playwright.config.js': `module.exports = { testDir: 'tests' }`,
Expand Down Expand Up @@ -94,9 +102,13 @@ test('should refresh trace viewer while test is running', async ({ activate, cre
});

await testController.expandTestItems(/test.spec/);
selectTestItem(testController.findTestItems(/pass/)[0]);
const [testItem] = testController.findTestItems(/pass/);
selectTestItem(testItem);

const testRunPromise = testController.run();
// wait for test to start
await waitForTestItemStatus(testItem, 'started');

await expect.poll(() => traceViewerInfo(vscode)).toMatchObject({
type: traceViewerMode,
traceFile: expect.stringMatching(/\.json$/),
Expand Down Expand Up @@ -181,3 +193,72 @@ test('should open new trace viewer when another test config is selected', async

expect(serverUrlPrefix2).not.toBe(serverUrlPrefix1);
});

test('should not open trace viewer test item is selected while debugging', async ({ activate, traceViewerMode, createLatch }) => {
const latch = createLatch();

const { vscode, testController } = await activate({
'playwright.config.js': `module.exports = { testDir: 'tests' }`,
'tests/test.spec.ts': `
import { test } from '@playwright/test';
test('should pass', async () => ${latch.blockingCode});
`,
});

await testController.expandTestItems(/test.spec/);
const [testItem] = testController.findTestItems(/pass/);

const debugPromise = testController.debug();

await waitForTestItemStatus(testItem, 'started');

selectTestItem(testItem);

// ensure it didn't open
await expect.poll(() => traceViewerInfo(vscode)).toMatchObject({
type: traceViewerMode,
traceFile: undefined,
});

latch.open();
await debugPromise;
});

test('should show empty state in trace viewer when test item is selected while debugging', async ({ activate, traceViewerMode, createLatch }) => {
const latch = createLatch();

const { vscode, testController } = await activate({
'playwright.config.js': `module.exports = { testDir: 'tests' }`,
'tests/test.spec.ts': `
import { test } from '@playwright/test';
test('should pass', async () => ${latch.blockingCode});
`,
});

await testController.expandTestItems(/test.spec/);
const [testItem] = testController.findTestItems(/pass/);

// run test without blocking, just to ensure trace viewer opens and displays a trace file
latch.open();
await testController.run();
await expect.poll(() => traceViewerInfo(vscode)).toMatchObject({
type: traceViewerMode,
traceFile: expect.stringMatching(/\.zip$/),
});

latch.close();
const debugPromise = testController.debug();

await waitForTestItemStatus(testItem, 'started');

selectTestItem(testItem);

// ensure it's not showing any trace file
await expect.poll(() => traceViewerInfo(vscode)).toMatchObject({
type: traceViewerMode,
traceFile: undefined,
});

latch.open();
await debugPromise;
});

0 comments on commit 143e22f

Please sign in to comment.