Skip to content

Commit 3ab466e

Browse files
authored
cherry-pick(#30312): fix(ui-mode): do not loose run information after writing into testDir (#30328)
Partially reverts #30008 that started to reset all test results upon listing tests, including the test that did just run and triggered re-listing. #30300.
1 parent 35468cf commit 3ab466e

File tree

3 files changed

+55
-7
lines changed

3 files changed

+55
-7
lines changed

packages/playwright/src/isomorphic/teleReceiver.ts

+23-6
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ type TeleReporterReceiverOptions = {
130130
};
131131

132132
export class TeleReporterReceiver {
133+
public isListing = false;
133134
private _rootSuite: TeleSuite;
134135
private _options: TeleReporterReceiverOptions;
135136
private _reporter: Partial<ReporterV2>;
@@ -143,12 +144,6 @@ export class TeleReporterReceiver {
143144
this._reporter = reporter;
144145
}
145146

146-
reset() {
147-
this._rootSuite.suites = [];
148-
this._rootSuite.tests = [];
149-
this._tests.clear();
150-
}
151-
152147
dispatch(message: JsonEvent): Promise<void> | void {
153148
const { method, params } = message;
154149
if (method === 'onConfigure') {
@@ -209,6 +204,28 @@ export class TeleReporterReceiver {
209204
// Always update project in watch mode.
210205
projectSuite._project = this._parseProject(project);
211206
this._mergeSuitesInto(project.suites, projectSuite);
207+
208+
// Remove deleted tests when listing. Empty suites will be auto-filtered
209+
// in the UI layer.
210+
if (this.isListing) {
211+
const testIds = new Set<string>();
212+
const collectIds = (suite: JsonSuite) => {
213+
suite.tests.map(t => t.testId).forEach(testId => testIds.add(testId));
214+
suite.suites.forEach(collectIds);
215+
};
216+
project.suites.forEach(collectIds);
217+
218+
const filterTests = (suite: TeleSuite) => {
219+
suite.tests = suite.tests.filter(t => {
220+
if (testIds.has(t.id))
221+
return true;
222+
this._tests.delete(t.id);
223+
return false;
224+
});
225+
suite.suites.forEach(filterTests);
226+
};
227+
filterTests(projectSuite);
228+
}
212229
}
213230

214231
private _onBegin() {

packages/trace-viewer/src/ui/teleSuiteUpdater.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,10 @@ export class TeleSuiteUpdater {
123123
}
124124

125125
processListReport(report: any[]) {
126-
this._receiver.reset();
126+
this._receiver.isListing = true;
127127
for (const message of report)
128128
this._receiver.dispatch(message);
129+
this._receiver.isListing = false;
129130
}
130131

131132
processTestReportEvent(message: any) {

tests/playwright-test/ui-mode-test-update.spec.ts

+30
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,36 @@ test('should pick new / deleted tests', async ({ runUITest, writeFiles, deleteFi
129129
`);
130130
});
131131

132+
test('should not loose run information after execution if test wrote into testDir', async ({ runUITest, writeFiles, deleteFile }) => {
133+
test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/30300' });
134+
const { page } = await runUITest({
135+
'a.test.ts': `
136+
import fs from 'fs';
137+
import path from 'path';
138+
import { test, expect } from '@playwright/test';
139+
test('passes', () => {
140+
fs.writeFileSync(path.join(test.info().project.testDir, 'something.txt'), 'hi');
141+
});
142+
`,
143+
});
144+
await expect.poll(dumpTestTree(page)).toBe(`
145+
▼ ◯ a.test.ts
146+
◯ passes
147+
`);
148+
await page.getByTitle('passes').click();
149+
await page.getByTitle('Run all').click();
150+
await page.waitForTimeout(5_000);
151+
await expect(page.getByText('Did not run')).toBeHidden();
152+
const listItem = page.getByTestId('actions-tree').getByRole('listitem');
153+
await expect(
154+
listItem,
155+
'action list'
156+
).toHaveText([
157+
/Before Hooks[\d.]+m?s/,
158+
/After Hooks[\d.]+m?s/,
159+
]);
160+
});
161+
132162
test('should pick new / deleted nested tests', async ({ runUITest, writeFiles, deleteFile }) => {
133163
const { page } = await runUITest(basicTestTree);
134164
await expect.poll(dumpTestTree(page)).toContain(`

0 commit comments

Comments
 (0)