mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-11 12:33:45 +03:00
fix: print fatal and no snippet errors in markdown report (#24263)
This commit is contained in:
parent
af3e735147
commit
15b9e5afdb
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import type { FullResult, TestCase } from '../../types/testReporter';
|
import type { FullResult, TestCase, TestError } from '../../types/testReporter';
|
||||||
import { BaseReporter, formatError, formatTestTitle, stripAnsiEscapes } from './base';
|
import { BaseReporter, formatError, formatTestTitle, stripAnsiEscapes } from './base';
|
||||||
|
|
||||||
type MarkdownReporterOptions = {
|
type MarkdownReporterOptions = {
|
||||||
@ -41,6 +41,8 @@ class MarkdownReporter extends BaseReporter {
|
|||||||
await super.onEnd(result);
|
await super.onEnd(result);
|
||||||
const summary = this.generateSummary();
|
const summary = this.generateSummary();
|
||||||
const lines: string[] = [];
|
const lines: string[] = [];
|
||||||
|
if (summary.fatalErrors.length)
|
||||||
|
lines.push(`**${summary.fatalErrors.length} fatal errors, not part of any test**`);
|
||||||
if (summary.unexpected.length) {
|
if (summary.unexpected.length) {
|
||||||
lines.push(`**${summary.unexpected.length} failed**`);
|
lines.push(`**${summary.unexpected.length} failed**`);
|
||||||
this._printTestList(':x:', summary.unexpected, lines);
|
this._printTestList(':x:', summary.unexpected, lines);
|
||||||
@ -58,9 +60,11 @@ class MarkdownReporter extends BaseReporter {
|
|||||||
lines.push(`:heavy_check_mark::heavy_check_mark::heavy_check_mark:`);
|
lines.push(`:heavy_check_mark::heavy_check_mark::heavy_check_mark:`);
|
||||||
lines.push(``);
|
lines.push(``);
|
||||||
|
|
||||||
if (summary.unexpected.length || summary.flaky.length) {
|
if (summary.unexpected.length || summary.fatalErrors.length || summary.flaky.length) {
|
||||||
lines.push(`<details>`);
|
lines.push(`<details>`);
|
||||||
lines.push(``);
|
lines.push(``);
|
||||||
|
if (summary.fatalErrors.length)
|
||||||
|
this._printFatalErrorDetails(summary.fatalErrors, lines);
|
||||||
if (summary.unexpected.length)
|
if (summary.unexpected.length)
|
||||||
this._printTestListDetails(':x:', summary.unexpected, lines);
|
this._printTestListDetails(':x:', summary.unexpected, lines);
|
||||||
if (summary.flaky.length)
|
if (summary.flaky.length)
|
||||||
@ -93,7 +97,7 @@ class MarkdownReporter extends BaseReporter {
|
|||||||
if (retry)
|
if (retry)
|
||||||
lines.push(`<b>Retry ${retry}:</b>`);
|
lines.push(`<b>Retry ${retry}:</b>`);
|
||||||
retry++;
|
retry++;
|
||||||
if (result.error?.snippet) {
|
if (result.error) {
|
||||||
lines.push(``);
|
lines.push(``);
|
||||||
lines.push('```');
|
lines.push('```');
|
||||||
lines.push(stripAnsiEscapes(formatError(result.error, false).message));
|
lines.push(stripAnsiEscapes(formatError(result.error, false).message));
|
||||||
@ -103,8 +107,18 @@ class MarkdownReporter extends BaseReporter {
|
|||||||
}
|
}
|
||||||
lines.push(``);
|
lines.push(``);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _printFatalErrorDetails(errors: TestError[], lines: string[]) {
|
||||||
|
for (const error of errors) {
|
||||||
|
lines.push(`:x: <b>fatal error, not part of any test</b>`);
|
||||||
|
lines.push(``);
|
||||||
|
lines.push('```');
|
||||||
|
lines.push(stripAnsiEscapes(formatError(error, false).message));
|
||||||
|
lines.push('```');
|
||||||
|
lines.push(``);
|
||||||
|
}
|
||||||
|
lines.push(``);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export default MarkdownReporter;
|
export default MarkdownReporter;
|
||||||
|
|
||||||
|
@ -114,4 +114,79 @@ test('custom report file', async ({ runInlineTest }) => {
|
|||||||
expect(reportFile.toString()).toBe(`**1 passed**
|
expect(reportFile.toString()).toBe(`**1 passed**
|
||||||
:heavy_check_mark::heavy_check_mark::heavy_check_mark:
|
:heavy_check_mark::heavy_check_mark::heavy_check_mark:
|
||||||
`);
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('report error without snippet', async ({ runInlineTest }) => {
|
||||||
|
const files = {
|
||||||
|
'playwright.config.ts': `
|
||||||
|
module.exports = {
|
||||||
|
retries: 1,
|
||||||
|
reporter: 'markdown',
|
||||||
|
};
|
||||||
|
`,
|
||||||
|
'a.test.js': `
|
||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
test('math 1', async ({}) => {
|
||||||
|
const e = new Error('My error');
|
||||||
|
e.stack = null;
|
||||||
|
throw e;
|
||||||
|
});
|
||||||
|
`,
|
||||||
|
};
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
**0 passed**
|
||||||
|
:heavy_check_mark::heavy_check_mark::heavy_check_mark:
|
||||||
|
|
||||||
|
<details>
|
||||||
|
|
||||||
|
:x: <b> a.test.js:3:11 › math 1 </b>
|
||||||
|
`);
|
||||||
|
expect(reportFile.toString()).toContain(`Error: My error`);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('report with worker error', async ({ runInlineTest }) => {
|
||||||
|
const files = {
|
||||||
|
'playwright.config.ts': `
|
||||||
|
module.exports = {
|
||||||
|
retries: 1,
|
||||||
|
reporter: 'markdown',
|
||||||
|
};
|
||||||
|
`,
|
||||||
|
'a.test.js': `
|
||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
throw new Error('My error 1');
|
||||||
|
`,
|
||||||
|
'b.test.js': `
|
||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
throw new Error('My error 2');
|
||||||
|
`,
|
||||||
|
};
|
||||||
|
|
||||||
|
const { exitCode } = await runInlineTest(files);
|
||||||
|
expect(exitCode).toBe(1);
|
||||||
|
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:
|
||||||
|
|
||||||
|
<details>
|
||||||
|
|
||||||
|
:x: <b>fatal error, not part of any test</b>
|
||||||
|
`);
|
||||||
|
expect(reportFile.toString()).toContain(`Error: My error 1
|
||||||
|
|
||||||
|
at a.test.js:3
|
||||||
|
|
||||||
|
1 |
|
||||||
|
2 | import { test, expect } from '@playwright/test';
|
||||||
|
> 3 | throw new Error('My error 1');
|
||||||
|
| ^
|
||||||
|
4 |
|
||||||
|
`);
|
||||||
|
expect(reportFile.toString()).toContain(`Error: No tests found`);
|
||||||
});
|
});
|
Loading…
Reference in New Issue
Block a user