Skip to content

Commit 21e29a4

Browse files
authored
cherry-pick(#37153): fix(html): don't display a chip with empty content with no projects
1 parent ba62e6a commit 21e29a4

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

packages/html-reporter/src/labels.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ export const ProjectAndTagLabelsView: React.FC<{
4444
useLinks?: boolean,
4545
style?: React.CSSProperties,
4646
}> = ({ projectNames, activeProjectName, otherLabels, useLinks, style }) => {
47-
return (projectNames.length > 0 || otherLabels.length > 0) && <span className='label-row' style={style ?? {}}>
47+
// We can have an empty project name if we have no projects specified in the config
48+
const hasProjectNames = projectNames.length > 0 && !!activeProjectName;
49+
50+
return (hasProjectNames || otherLabels.length > 0) && <span className='label-row' style={style ?? {}}>
4851
<ProjectLink projectNames={projectNames} projectName={activeProjectName} />
4952
{!!useLinks ? <LabelsLinkView labels={otherLabels} /> : <LabelsClickView labels={otherLabels} />}
5053
</span>;

tests/playwright-test/reporter-html.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,6 +1717,25 @@ for (const useIntermediateMergeReport of [true, false] as const) {
17171717
await expect(page.locator('.label')).toHaveText('webkit');
17181718
});
17191719

1720+
test('project label should not show if there are no explicit projects', async ({ runInlineTest, showReport, page }) => {
1721+
const result = await runInlineTest({
1722+
'a.test.js': `
1723+
const { expect, test } = require('@playwright/test');
1724+
test('pass', async ({}) => {
1725+
expect(1).toBe(1);
1726+
});
1727+
`,
1728+
}, { reporter: 'dot,html' }, { PLAYWRIGHT_HTML_OPEN: 'never' });
1729+
1730+
expect(result.exitCode).toBe(0);
1731+
expect(result.passed).toBe(1);
1732+
1733+
await showReport();
1734+
1735+
await expect(page.locator('.test-file-test .label')).toHaveCount(0);
1736+
await expect(page.locator('.label-row')).not.toBeVisible();
1737+
});
1738+
17201739
test('testCaseView - after click test label and go back, testCaseView should be visible', async ({ runInlineTest, showReport, page }) => {
17211740
const result = await runInlineTest({
17221741
'playwright.config.js': `

0 commit comments

Comments
 (0)