Skip to content

Commit

Permalink
fix(ui mode): do not render anonymous describe (#33675)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgozman authored Nov 20, 2024
1 parent ae10d56 commit 50c8fbf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 39 deletions.
13 changes: 9 additions & 4 deletions packages/playwright/src/isomorphic/testTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,19 @@ export class TestTree {

const visitSuite = (project: reporterTypes.FullProject, parentSuite: reporterTypes.Suite, parentGroup: GroupItem) => {
for (const suite of parentSuite.suites) {
const title = suite.title || '<anonymous>';
let group = parentGroup.children.find(item => item.kind === 'group' && item.title === title) as GroupItem | undefined;
if (!suite.title) {
// Flatten anonymous describes.
visitSuite(project, suite, parentGroup);
continue;
}

let group = parentGroup.children.find(item => item.kind === 'group' && item.title === suite.title) as GroupItem | undefined;
if (!group) {
group = {
kind: 'group',
subKind: 'describe',
id: 'suite:' + parentSuite.titlePath().join('\x1e') + '\x1e' + title, // account for anonymous suites
title,
id: 'suite:' + parentSuite.titlePath().join('\x1e') + '\x1e' + suite.title, // account for anonymous suites
title: suite.title,
location: suite.location!,
duration: 0,
parent: parentGroup,
Expand Down
57 changes: 22 additions & 35 deletions tests/playwright-test/ui-mode-test-tree.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,28 +315,23 @@ test('should list parametrized tests', async ({ runUITest }) => {

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)).toBe(`
▼ ◯ a.test.ts
▼ ◯ cookies
▼ ◯ <anonymous> <=
◯ test FR
◯ test DE
◯ test LT
▼ ◯ cookies <=
◯ test FR
◯ test DE
◯ test LT
`);
await expect(page.getByTestId('test-tree')).toMatchAriaSnapshot(`
- tree:
- treeitem "[icon-circle-outline] a.test.ts" [expanded]:
- group:
- treeitem "[icon-circle-outline] cookies" [expanded]:
- treeitem "[icon-circle-outline] cookies" [expanded] [selected]:
- group:
- treeitem "[icon-circle-outline] <anonymous>" [expanded] [selected]:
- group:
- treeitem "[icon-circle-outline] test FR"
- treeitem "[icon-circle-outline] test DE"
- treeitem "[icon-circle-outline] test LT"
- treeitem "[icon-circle-outline] test FR"
- treeitem "[icon-circle-outline] test DE"
- treeitem "[icon-circle-outline] test LT"
`);
});

Expand All @@ -356,28 +351,23 @@ test('should update parametrized tests', async ({ runUITest, writeFiles }) => {

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)).toBe(`
▼ ◯ a.test.ts
▼ ◯ cookies
▼ ◯ <anonymous> <=
◯ test FR
◯ test DE
◯ test LT
▼ ◯ cookies <=
◯ test FR
◯ test DE
◯ test LT
`);
await expect(page.getByTestId('test-tree')).toMatchAriaSnapshot(`
- tree:
- treeitem "[icon-circle-outline] a.test.ts" [expanded]:
- group:
- treeitem "[icon-circle-outline] cookies" [expanded]:
- treeitem "[icon-circle-outline] cookies" [expanded] [selected]:
- group:
- treeitem "[icon-circle-outline] <anonymous>" [expanded] [selected]:
- group:
- treeitem "[icon-circle-outline] test FR"
- treeitem "[icon-circle-outline] test DE"
- treeitem "[icon-circle-outline] test LT"
- treeitem "[icon-circle-outline] test FR"
- treeitem "[icon-circle-outline] test DE"
- treeitem "[icon-circle-outline] test LT"
`);

await writeFiles({
Expand All @@ -396,21 +386,18 @@ test('should update parametrized tests', async ({ runUITest, writeFiles }) => {

await expect.poll(dumpTestTree(page)).toBe(`
▼ ◯ a.test.ts
▼ ◯ cookies
▼ ◯ <anonymous> <=
◯ test FR
◯ test LT
▼ ◯ cookies <=
◯ test FR
◯ test LT
`);
await expect(page.getByTestId('test-tree')).toMatchAriaSnapshot(`
- tree:
- treeitem "[icon-circle-outline] a.test.ts" [expanded]:
- group:
- treeitem "[icon-circle-outline] cookies" [expanded]:
- treeitem "[icon-circle-outline] cookies" [expanded] [selected]:
- group:
- treeitem "[icon-circle-outline] <anonymous>" [expanded] [selected]:
- group:
- treeitem "[icon-circle-outline] test FR"
- treeitem "[icon-circle-outline] test LT"
- treeitem "[icon-circle-outline] test FR"
- treeitem "[icon-circle-outline] test LT"
`);
});

Expand Down

0 comments on commit 50c8fbf

Please sign in to comment.