Skip to content

Commit

Permalink
cherry-pick(#21967): chore: allow sibling describes with the same name
Browse files Browse the repository at this point in the history
Fixes #21953
  • Loading branch information
aslushnikov committed Mar 25, 2023
1 parent 8bc3e0b commit 1869bd2
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 15 deletions.
36 changes: 22 additions & 14 deletions packages/playwright-test/src/isomorphic/teleReceiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ export class TeleReporterReceiver {
}

private _onBegin(config: JsonConfig, projects: JsonProject[]) {
const removeMissing = config.listOnly;
for (const project of projects) {
let projectSuite = this._rootSuite.suites.find(suite => suite.project()!.id === project.id);
if (!projectSuite) {
Expand All @@ -159,7 +158,24 @@ export class TeleReporterReceiver {
}
const p = this._parseProject(project);
projectSuite.project = () => p;
this._mergeSuitesInto(project.suites, projectSuite, removeMissing);
this._mergeSuitesInto(project.suites, projectSuite);

// Remove deleted tests when listing. Empty suites will be auto-filtered
// in the UI layer.
if (config.listOnly) {
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 => testIds.has(t.id));
suite.suites.forEach(filterTests);
};
filterTests(projectSuite);
}
}
this._reporter.onBegin?.(this._parseConfig(config), this._rootSuite);
}
Expand Down Expand Up @@ -262,7 +278,7 @@ export class TeleReporterReceiver {
};
}

private _mergeSuitesInto(jsonSuites: JsonSuite[], parent: TeleSuite, removeMissing: boolean) {
private _mergeSuitesInto(jsonSuites: JsonSuite[], parent: TeleSuite) {
for (const jsonSuite of jsonSuites) {
let targetSuite = parent.suites.find(s => s.title === jsonSuite.title);
if (!targetSuite) {
Expand All @@ -273,16 +289,12 @@ export class TeleReporterReceiver {
targetSuite.location = jsonSuite.location;
targetSuite._fileId = jsonSuite.fileId;
targetSuite._parallelMode = jsonSuite.parallelMode;
this._mergeSuitesInto(jsonSuite.suites, targetSuite, removeMissing);
this._mergeTestsInto(jsonSuite.tests, targetSuite, removeMissing);
}
if (removeMissing) {
const suiteMap = new Map(parent.suites.map(p => [p.title, p]));
parent.suites = jsonSuites.map(s => suiteMap.get(s.title)).filter(Boolean) as TeleSuite[];
this._mergeSuitesInto(jsonSuite.suites, targetSuite);
this._mergeTestsInto(jsonSuite.tests, targetSuite);
}
}

private _mergeTestsInto(jsonTests: JsonTestCase[], parent: TeleSuite, removeMissing: boolean) {
private _mergeTestsInto(jsonTests: JsonTestCase[], parent: TeleSuite) {
for (const jsonTest of jsonTests) {
let targetTest = parent.tests.find(s => s.title === jsonTest.title);
if (!targetTest) {
Expand All @@ -293,10 +305,6 @@ export class TeleReporterReceiver {
}
this._updateTest(jsonTest, targetTest);
}
if (removeMissing) {
const testMap = new Map(parent.tests.map(p => [p.title, p]));
parent.tests = jsonTests.map(s => testMap.get(s.title)).filter(Boolean) as TeleTestCase[];
}
}

private _updateTest(payload: JsonTestCase, test: TeleTestCase): TeleTestCase {
Expand Down
2 changes: 1 addition & 1 deletion packages/trace-viewer/src/ui/watchMode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ function createTree(rootSuite: Suite | undefined, projectFilters: Map<string, bo

const visitSuite = (projectName: string, parentSuite: Suite, parentGroup: GroupItem) => {
for (const suite of parentSuite.suites) {
const title = suite.title;
const title = suite.title || '<anonymous>';
let group = parentGroup.children.find(item => item.title === title) as GroupItem | undefined;
if (!group) {
group = {
Expand Down
80 changes: 80 additions & 0 deletions tests/playwright-test/ui-mode-test-tree.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,83 @@ test('should merge folder trees', async ({ runUITest }) => {
◯ passes
`);
});

test('should list parametrized tests', async ({ runUITest }) => {
const page = await runUITest({
'a.test.ts': `
import { test } from '@playwright/test';
test.describe('cookies', () => {
for (const country of ['FR', 'DE', 'LT']) {
test.describe(() => {
test('test ' + country, async ({}) => {});
});
}
})
`
});

await page.getByText('cookies').click();
await page.keyboard.press('ArrowRight');
await page.getByText('<anonymous>').click();
await page.keyboard.press('ArrowRight');

await expect.poll(dumpTestTree(page), { timeout: 15000 }).toBe(`
▼ ◯ a.test.ts
▼ ◯ cookies
▼ ◯ <anonymous> <=
◯ test FR
◯ test DE
◯ test LT
`);
});

test('should update parametrized tests', async ({ runUITest, writeFiles }) => {
const page = await runUITest({
'a.test.ts': `
import { test } from '@playwright/test';
test.describe('cookies', () => {
for (const country of ['FR', 'DE', 'LT']) {
test.describe(() => {
test('test ' + country, async ({}) => {});
});
}
})
`
});

await page.getByText('cookies').click();
await page.keyboard.press('ArrowRight');
await page.getByText('<anonymous>').click();
await page.keyboard.press('ArrowRight');

await expect.poll(dumpTestTree(page), { timeout: 15000 }).toBe(`
▼ ◯ a.test.ts
▼ ◯ cookies
▼ ◯ <anonymous> <=
◯ test FR
◯ test DE
◯ test LT
`);

writeFiles({
'a.test.ts': `
import { test } from '@playwright/test';
test.describe('cookies', () => {
for (const country of ['FR', 'LT']) {
test.describe(() => {
test('test ' + country, async ({}) => {});
});
}
})
`
});


await expect.poll(dumpTestTree(page), { timeout: 15000 }).toBe(`
▼ ◯ a.test.ts
▼ ◯ cookies
▼ ◯ <anonymous> <=
◯ test FR
◯ test LT
`);
});

0 comments on commit 1869bd2

Please sign in to comment.