Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cherry-pick(#30312): fix(ui-mode): do not loose run information after writing into testDir #30328

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions packages/playwright/src/isomorphic/teleReceiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ type TeleReporterReceiverOptions = {
};

export class TeleReporterReceiver {
public isListing = false;
private _rootSuite: TeleSuite;
private _options: TeleReporterReceiverOptions;
private _reporter: Partial<ReporterV2>;
Expand All @@ -143,12 +144,6 @@ export class TeleReporterReceiver {
this._reporter = reporter;
}

reset() {
this._rootSuite.suites = [];
this._rootSuite.tests = [];
this._tests.clear();
}

dispatch(message: JsonEvent): Promise<void> | void {
const { method, params } = message;
if (method === 'onConfigure') {
Expand Down Expand Up @@ -209,6 +204,28 @@ export class TeleReporterReceiver {
// Always update project in watch mode.
projectSuite._project = this._parseProject(project);
this._mergeSuitesInto(project.suites, projectSuite);

// Remove deleted tests when listing. Empty suites will be auto-filtered
// in the UI layer.
if (this.isListing) {
const testIds = new Set<string>();
const collectIds = (suite: JsonSuite) => {
suite.tests.map(t => t.testId).forEach(testId => testIds.add(testId));
suite.suites.forEach(collectIds);
};
project.suites.forEach(collectIds);

const filterTests = (suite: TeleSuite) => {
suite.tests = suite.tests.filter(t => {
if (testIds.has(t.id))
return true;
this._tests.delete(t.id);
return false;
});
suite.suites.forEach(filterTests);
};
filterTests(projectSuite);
}
}

private _onBegin() {
Expand Down
3 changes: 2 additions & 1 deletion packages/trace-viewer/src/ui/teleSuiteUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,10 @@ export class TeleSuiteUpdater {
}

processListReport(report: any[]) {
this._receiver.reset();
this._receiver.isListing = true;
for (const message of report)
this._receiver.dispatch(message);
this._receiver.isListing = false;
}

processTestReportEvent(message: any) {
Expand Down
30 changes: 30 additions & 0 deletions tests/playwright-test/ui-mode-test-update.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,36 @@ test('should pick new / deleted tests', async ({ runUITest, writeFiles, deleteFi
`);
});

test('should not loose run information after execution if test wrote into testDir', async ({ runUITest, writeFiles, deleteFile }) => {
test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/30300' });
const { page } = await runUITest({
'a.test.ts': `
import fs from 'fs';
import path from 'path';
import { test, expect } from '@playwright/test';
test('passes', () => {
fs.writeFileSync(path.join(test.info().project.testDir, 'something.txt'), 'hi');
});
`,
});
await expect.poll(dumpTestTree(page)).toBe(`
▼ ◯ a.test.ts
◯ passes
`);
await page.getByTitle('passes').click();
await page.getByTitle('Run all').click();
await page.waitForTimeout(5_000);
await expect(page.getByText('Did not run')).toBeHidden();
const listItem = page.getByTestId('actions-tree').getByRole('listitem');
await expect(
listItem,
'action list'
).toHaveText([
/Before Hooks[\d.]+m?s/,
/After Hooks[\d.]+m?s/,
]);
});

test('should pick new / deleted nested tests', async ({ runUITest, writeFiles, deleteFile }) => {
const { page } = await runUITest(basicTestTree);
await expect.poll(dumpTestTree(page)).toContain(`
Expand Down
Loading