Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(markdown-reporter): improve formatting for GitHub comments (#37005)

Max Schmitt8df00a9f7391
diff --git a/packages/playwright/src/reporters/markdown.ts b/packages/playwright/src/reporters/markdown.ts
index f7f28cf60d..523ca75bfa 100644
--- a/packages/playwright/src/reporters/markdown.ts
+++ b/packages/playwright/src/reporters/markdown.ts
@@ -73,7 +73,6 @@ class MarkdownReporter implements Reporter {
const skipped = summary.skipped ? `, ${summary.skipped} skipped` : '';
const didNotRun = summary.didNotRun ? `, ${summary.didNotRun} did not run` : '';
lines.push(`**${summary.expected} passed${skipped}${didNotRun}**`);
- lines.push(`:heavy_check_mark::heavy_check_mark::heavy_check_mark:`);
lines.push(``);
await this.publishReport(lines.join('\n'));
@@ -136,11 +135,13 @@ function formatTestTitle(rootDir: string, test: TestCase): string {
// root, project, file, ...describes, test
const [, projectName, , ...titles] = test.titlePath();
const relativeTestPath = path.relative(rootDir, test.location.file);
- const location = `${relativeTestPath}:${test.location.line}:${test.location.column}`;
+ // intentionally add a zero-width space to prevent creating markdown icons on GitHub
+ const location = `${relativeTestPath}:​${test.location.line}:${test.location.column}`;
const projectTitle = projectName ? `[${projectName}] › ` : '';
const testTitle = `${projectTitle}${location} › ${titles.join(' › ')}`;
const extraTags = test.tags.filter(t => !testTitle.includes(t));
- return `${testTitle}${extraTags.length ? ' ' + extraTags.join(' ') : ''}`;
+ const formattedTags = extraTags.map(t => `\`${t}\``).join(' ');
+ return `${testTitle}${extraTags.length ? ' ' + formattedTags : ''}`;
}
export default MarkdownReporter;
diff --git a/tests/config/ghaMarkdownReporter.ts b/tests/config/ghaMarkdownReporter.ts
index c6c31605cb..c1b390646f 100644
--- a/tests/config/ghaMarkdownReporter.ts
+++ b/tests/config/ghaMarkdownReporter.ts
@@ -112,6 +112,8 @@ class GHAMarkdownReporter extends MarkdownReporter {
`### ${reportUrl ? `[Test results](${reportUrl})` : 'Test results'} for "${this._workflowRunName()}"`,
report,
'',
+ '---',
+ '',
`Merge [workflow run](${mergeWorkflowUrl}).`
]);
diff --git a/tests/playwright-test/reporter-markdown.spec.ts b/tests/playwright-test/reporter-markdown.spec.ts
index 558a1f8a84..9b04bb395c 100644
--- a/tests/playwright-test/reporter-markdown.spec.ts
+++ b/tests/playwright-test/reporter-markdown.spec.ts
@@ -66,18 +66,17 @@ test('simple report', async ({ runInlineTest }) => {
expect(exitCode).toBe(1);
const reportFile = await fs.promises.readFile(test.info().outputPath('report.md'));
expect(reportFile.toString()).toContain(`**2 failed**
-:x: dir1${path.sep}a.test.js:6:11 › failing 1
-:x: dir2${path.sep}b.test.js:6:11 › failing 2
+:x: dir1${path.sep}a.test.js:​6:11 › failing 1
+:x: dir2${path.sep}b.test.js:​6:11 › failing 2
<details>
<summary><b>2 flaky</b></summary>
-:warning: c.test.js:6:11 › flaky 2 <br/>
-:warning: dir1${path.sep}a.test.js:9:11 › flaky 1 <br/>
+:warning: c.test.js:​6:11 › flaky 2 <br/>
+:warning: dir1${path.sep}a.test.js:​9:11 › flaky 1 <br/>
</details>
**3 passed, 3 skipped**
-:heavy_check_mark::heavy_check_mark::heavy_check_mark:
`);
});
@@ -100,7 +99,6 @@ test('custom report file', async ({ runInlineTest }) => {
expect(exitCode).toBe(0);
const reportFile = await fs.promises.readFile(test.info().outputPath('my-report.md'));
expect(reportFile.toString()).toBe(`**1 passed**
-:heavy_check_mark::heavy_check_mark::heavy_check_mark:
`);
});
@@ -125,10 +123,9 @@ test('report error without snippet', async ({ runInlineTest }) => {
await runInlineTest(files);
const reportFile = await fs.promises.readFile(test.info().outputPath('report.md'));
expect(reportFile.toString()).toContain(`**1 failed**
-:x: a.test.js:3:11 › math 1
+:x: a.test.js:​3:11 › math 1
**0 passed**
-:heavy_check_mark::heavy_check_mark::heavy_check_mark:
`);
});
@@ -155,6 +152,54 @@ test('report with worker error', async ({ runInlineTest }) => {
const reportFile = await fs.promises.readFile(test.info().outputPath('report.md'));
expect(reportFile.toString()).toContain(`**3 fatal errors, not part of any test**
**0 passed**
-:heavy_check_mark::heavy_check_mark::heavy_check_mark:
`);
});
+
+test('report with annotations', async ({ runInlineTest }) => {
+ const files = {
+ 'playwright.config.ts': `
+ module.exports = {
+ retries: 0,
+ reporter: ${JSON.stringify(markdownReporter)},
+ };
+ `,
+ 'a.test.js': `
+ import { test, expect } from '@playwright/test';
+
+ test('test login page', {
+ annotation: {
+ type: 'issue',
+ description: 'https://github.com/microsoft/playwright/issues/23180',
+ },
+ tag: '@login',
+ }, async ({ page }) => {
+ expect(1 + 1).toBe(2);
+ });
+
+ test('failing test with annotation', {
+ annotation: [
+ { type: 'bug', description: 'Known issue' },
+ { type: 'performance', description: 'slow test' }
+ ],
+ tag: '@slow',
+ }, async ({ page }) => {
+ expect(1).toBe(2);
+ });
+ `,
+ };
+
+ const { exitCode } = await runInlineTest(files);
+ expect(exitCode).toBe(1);
+ const reportFile = await fs.promises.readFile(test.info().outputPath('report.md'));
+ const reportContent = reportFile.toString();
+
+ // Check that failed tests are reported with tags
+ expect(reportContent).toContain(`**1 failed**
+:x: a.test.js:​14:11 › failing test with annotation \`@slow\``);
+
+ // Check that passed tests are reported (but without individual titles)
+ expect(reportContent).toContain(`**1 passed**`);
+
+ // Check that tags are included in the failed test output
+ expect(reportContent).toContain('`@slow`');
+});