From 4fa1030af697f8c9f84dbd0d3c944bb59ab00d1b Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Thu, 25 Apr 2024 12:48:41 -0700 Subject: [PATCH] chore: hide skipped tests by default (#30546) Fixes https://github.com/microsoft/playwright/issues/30540 --- packages/html-reporter/src/filter.ts | 51 +++++++++++-------- .../html-reporter/src/headerView.spec.tsx | 2 +- packages/html-reporter/src/headerView.tsx | 2 +- tests/playwright-test/reporter-blob.spec.ts | 20 +++++--- tests/playwright-test/reporter-html.spec.ts | 28 +++------- 5 files changed, 51 insertions(+), 52 deletions(-) diff --git a/packages/html-reporter/src/filter.ts b/packages/html-reporter/src/filter.ts index 97cf675936..f8c61ba902 100644 --- a/packages/html-reporter/src/filter.ts +++ b/packages/html-reporter/src/filter.ts @@ -98,27 +98,7 @@ export class Filter { } matches(test: TestCaseSummary): boolean { - if (!(test as any).searchValues) { - let status = 'passed'; - if (test.outcome === 'unexpected') - status = 'failed'; - if (test.outcome === 'flaky') - status = 'flaky'; - if (test.outcome === 'skipped') - status = 'skipped'; - const searchValues: SearchValues = { - text: (status + ' ' + test.projectName + ' ' + test.tags.join(' ') + ' ' + test.location.file + ' ' + test.path.join(' ') + ' ' + test.title).toLowerCase(), - project: test.projectName.toLowerCase(), - status: status as any, - file: test.location.file, - line: String(test.location.line), - column: String(test.location.column), - labels: test.tags.map(tag => tag.toLowerCase()), - }; - (test as any).searchValues = searchValues; - } - - const searchValues = (test as any).searchValues as SearchValues; + const searchValues = cacheSearchValues(test); if (this.project.length) { const matches = !!this.project.find(p => searchValues.project.includes(p)); if (!matches) @@ -128,6 +108,9 @@ export class Filter { const matches = !!this.status.find(s => searchValues.status.includes(s)); if (!matches) return false; + } else { + if (searchValues.status === 'skipped') + return false; } if (this.text.length) { for (const text of this.text) { @@ -159,3 +142,29 @@ type SearchValues = { labels: string[]; }; +const searchValuesSymbol = Symbol('searchValues'); + +function cacheSearchValues(test: TestCaseSummary): SearchValues { + const cached = (test as any)[searchValuesSymbol] as SearchValues | undefined; + if (cached) + return cached; + + let status: SearchValues['status'] = 'passed'; + if (test.outcome === 'unexpected') + status = 'failed'; + if (test.outcome === 'flaky') + status = 'flaky'; + if (test.outcome === 'skipped') + status = 'skipped'; + const searchValues: SearchValues = { + text: (status + ' ' + test.projectName + ' ' + test.tags.join(' ') + ' ' + test.location.file + ' ' + test.path.join(' ') + ' ' + test.title).toLowerCase(), + project: test.projectName.toLowerCase(), + status, + file: test.location.file, + line: String(test.location.line), + column: String(test.location.column), + labels: test.tags.map(tag => tag.toLowerCase()), + }; + (test as any)[searchValuesSymbol] = searchValues; + return searchValues; +} diff --git a/packages/html-reporter/src/headerView.spec.tsx b/packages/html-reporter/src/headerView.spec.tsx index a0b27e6943..64ed858475 100644 --- a/packages/html-reporter/src/headerView.spec.tsx +++ b/packages/html-reporter/src/headerView.spec.tsx @@ -28,7 +28,7 @@ test('should render counters', async ({ mount }) => { skipped: 10, ok: false, }} filterText='' setFilterText={() => {}}>); - await expect(component.locator('a', { hasText: 'All' }).locator('.counter')).toHaveText('100'); + await expect(component.locator('a', { hasText: 'All' }).locator('.counter')).toHaveText('90'); await expect(component.locator('a', { hasText: 'Passed' }).locator('.counter')).toHaveText('42'); await expect(component.locator('a', { hasText: 'Failed' }).locator('.counter')).toHaveText('31'); await expect(component.locator('a', { hasText: 'Flaky' }).locator('.counter')).toHaveText('17'); diff --git a/packages/html-reporter/src/headerView.tsx b/packages/html-reporter/src/headerView.tsx index 04513eb7dc..1dc5420eec 100644 --- a/packages/html-reporter/src/headerView.tsx +++ b/packages/html-reporter/src/headerView.tsx @@ -66,7 +66,7 @@ const StatsNavView: React.FC<{ }> = ({ stats }) => { return