From e2a2196e6a97bdbfcc13fa740284089c368e1113 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Tue, 10 Jan 2023 17:11:38 +0100 Subject: [PATCH] chore(html-reporter): show project name always for the test file (#19905) Fixes https://github.com/microsoft/playwright/issues/19874 --- .../html-reporter/src/headerView.spec.tsx | 41 +++++++++++++++++-- packages/html-reporter/src/headerView.tsx | 8 +++- packages/html-reporter/src/metadataView.tsx | 16 ++++---- packages/html-reporter/src/reportView.tsx | 2 +- tests/playwright-test/reporter-html.spec.ts | 1 + 5 files changed, 54 insertions(+), 14 deletions(-) diff --git a/packages/html-reporter/src/headerView.spec.tsx b/packages/html-reporter/src/headerView.spec.tsx index 363d3aebea..d276b57dbe 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, duration: 100000 - }} filterText='' setFilterText={() => {}}>); + }} filterText='' setFilterText={() => {}} projectNames={[]}>); await expect(component.locator('a', { hasText: 'All' }).locator('.counter')).toHaveText('100'); await expect(component.locator('a', { hasText: 'Passed' }).locator('.counter')).toHaveText('42'); await expect(component.locator('a', { hasText: 'Failed' }).locator('.counter')).toHaveText('31'); @@ -36,7 +36,7 @@ test('should render counters', async ({ mount }) => { await expect(component.locator('a', { hasText: 'Skipped' }).locator('.counter')).toHaveText('10'); }); -test('should toggle filters', async ({ page, mount: mount }) => { +test('should toggle filters', async ({ page, mount }) => { const filters: string[] = []; const component = await mount( { duration: 100000 }} filterText='' - setFilterText={(filterText: string) => filters.push(filterText)}> + setFilterText={(filterText: string) => filters.push(filterText)} + projectNames={[]} + > ); await component.locator('a', { hasText: 'All' }).click(); await component.locator('a', { hasText: 'Passed' }).click(); @@ -62,3 +64,36 @@ test('should toggle filters', async ({ page, mount: mount }) => { await expect(page).toHaveURL(/#\?q=s:skipped/); expect(filters).toEqual(['', 's:passed', 's:failed', 's:flaky', 's:skipped']); }); + +test('should show the project names', async ({ mount }) => { + const stats = { + total: 100, + expected: 42, + unexpected: 31, + flaky: 17, + skipped: 10, + ok: false, + duration: 100000 + }; + await test.step('with 1 project', async () => { + const component = await mount( {}} + projectNames={['my-project']} + > + ); + await expect(component.getByText('Project: my-project')).toBeVisible(); + }); + await test.step('with more than 1 project', async () => { + const component = await mount( {}} + projectNames={['great-project', 'my-project']} + > + ); + await expect(component.getByText('my-project')).toBeHidden(); + await expect(component.getByText('great-project')).toBeHidden(); + }); +}); diff --git a/packages/html-reporter/src/headerView.tsx b/packages/html-reporter/src/headerView.tsx index d5d6483a24..cd5a252d66 100644 --- a/packages/html-reporter/src/headerView.tsx +++ b/packages/html-reporter/src/headerView.tsx @@ -28,7 +28,8 @@ export const HeaderView: React.FC void, -}>> = ({ stats, filterText, setFilterText }) => { + projectNames: string[], +}>> = ({ stats, filterText, setFilterText, projectNames }) => { React.useEffect(() => { (async () => { window.addEventListener('popstate', () => { @@ -56,7 +57,10 @@ export const HeaderView: React.FC -
Total time: {msToString(stats.duration)}
+
+ {projectNames.length === 1 && Project: {projectNames[0]}} + Total time: {msToString(stats.duration)} +
); }; diff --git a/packages/html-reporter/src/metadataView.tsx b/packages/html-reporter/src/metadataView.tsx index 6f57af9cff..7fc6b3a520 100644 --- a/packages/html-reporter/src/metadataView.tsx +++ b/packages/html-reporter/src/metadataView.tsx @@ -74,13 +74,13 @@ const InnerMetadataView: React.FC = metadata => { {metadata['revision.subject'] || 'Commit Metainfo'} } initialExpanded={false} dataTestId='metadata-chip'> {metadata['revision.subject'] && - {metadata['revision.subject']}} /> } {metadata['revision.id'] && - {metadata['revision.id']}} href={metadata['revision.link']} @@ -88,13 +88,13 @@ const InnerMetadataView: React.FC = metadata => { /> } {(metadata['revision.author'] || metadata['revision.email']) && - } {metadata['revision.timestamp'] && - @@ -107,23 +107,23 @@ const InnerMetadataView: React.FC = metadata => { /> } {metadata['ci.link'] && - } {metadata['timestamp'] && - Report generated on {Intl.DateTimeFormat(undefined, { dateStyle: 'full', timeStyle: 'long' }).format(metadata['timestamp'])} - }> + }> } ); }; -const MetadatViewItem: React.FC<{ content: JSX.Element | string; icon?: keyof typeof icons, href?: string, testId?: string }> = ({ content, icon, href, testId }) => { +const MetadataViewItem: React.FC<{ content: JSX.Element | string; icon?: keyof typeof icons, href?: string, testId?: string }> = ({ content, icon, href, testId }) => { return (
diff --git a/packages/html-reporter/src/reportView.tsx b/packages/html-reporter/src/reportView.tsx index 31daea4224..08dd0e11e9 100644 --- a/packages/html-reporter/src/reportView.tsx +++ b/packages/html-reporter/src/reportView.tsx @@ -50,7 +50,7 @@ export const ReportView: React.FC<{ return
- {report?.json() && } + {report?.json() && } {report?.json().metadata && } diff --git a/tests/playwright-test/reporter-html.spec.ts b/tests/playwright-test/reporter-html.spec.ts index 6f826fbb00..b2713f8bac 100644 --- a/tests/playwright-test/reporter-html.spec.ts +++ b/tests/playwright-test/reporter-html.spec.ts @@ -71,6 +71,7 @@ test('should generate report', async ({ runInlineTest, showReport, page }) => { await expect(page.locator('.test-file-test-outcome-skipped >> text=skipped')).toBeVisible(); await expect(page.getByTestId('overall-duration'), 'should contain humanized total time with at most 1 decimal place').toContainText(/^Total time: \d+(\.\d)?(ms|s|m)$/); + await expect(page.getByTestId('project-name'), 'should contain project name').toContainText('project-name'); await expect(page.locator('.metadata-view')).not.toBeVisible(); });