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 16, 2024
1 parent 65292ac commit ac3a73c
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 5 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 (mode !== 'debug') {
const fullProject = ancestorProject(test);
traceUrl = `${fullProject.outputDir}/.playwright-artifacts-${result.workerIndex}/traces/${test.id}.json`;
}
(testItem as any)[traceUrlSymbol] = traceUrl;
}

Expand Down
86 changes: 83 additions & 3 deletions tests/trace-viewer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,18 @@
*/

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

test.skip(({ showTrace }) => !showTrace);
test.skip(({ showTrace, overridePlaywrightVersion }) => overridePlaywrightVersion && showTrace === 'embedded');

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

test('@smoke should open trace viewer', async ({ activate, showTrace }) => {
const { vscode, testController } = await activate({
Expand Down Expand Up @@ -95,9 +104,12 @@ 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();
await waitForTestItemStatus(testItem, 'started');

await expect.poll(() => traceViewerInfo(vscode)).toMatchObject({
type: showTrace,
traceFile: expect.stringMatching(/\.json$/),
Expand Down Expand Up @@ -130,7 +142,7 @@ test('should close trace viewer if test configs refreshed', async ({ activate, s
traceFile: expect.stringContaining('pass'),
});

await testController.refreshHandler(null);
await testController.refreshHandler!(null);

await expect.poll(() => traceViewerInfo(vscode)).toMatchObject({
type: showTrace,
Expand Down Expand Up @@ -190,3 +202,71 @@ 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, showTrace, 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: showTrace,
traceFile: undefined,
});

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

test('should show empty state in trace viewer when test item is selected while debugging', async ({ activate, showTrace, 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: showTrace,
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: showTrace,
traceFile: undefined,
});

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

0 comments on commit ac3a73c

Please sign in to comment.