feat(json report): add expected/unexpected/skipped/flaky stats (#27685)
Fixes #27498.
This commit is contained in:
parent
3aa147914c
commit
fd82b2b3fa
|
|
@ -59,7 +59,7 @@ class JSONReporter extends EmptyReporter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private _serializeReport(result: FullResult): JSONReport {
|
private _serializeReport(result: FullResult): JSONReport {
|
||||||
return {
|
const report: JSONReport = {
|
||||||
config: {
|
config: {
|
||||||
...removePrivateFields(this.config),
|
...removePrivateFields(this.config),
|
||||||
rootDir: toPosixPath(this.config.rootDir),
|
rootDir: toPosixPath(this.config.rootDir),
|
||||||
|
|
@ -83,8 +83,15 @@ class JSONReporter extends EmptyReporter {
|
||||||
stats: {
|
stats: {
|
||||||
startTime: result.startTime.toISOString(),
|
startTime: result.startTime.toISOString(),
|
||||||
duration: result.duration,
|
duration: result.duration,
|
||||||
|
expected: 0,
|
||||||
|
skipped: 0,
|
||||||
|
unexpected: 0,
|
||||||
|
flaky: 0,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
for (const test of this.suite.allTests())
|
||||||
|
++report.stats[test.outcome()];
|
||||||
|
return report;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _mergeSuites(suites: Suite[]): JSONReportSuite[] {
|
private _mergeSuites(suites: Suite[]): JSONReportSuite[] {
|
||||||
|
|
|
||||||
4
packages/playwright/types/testReporter.d.ts
vendored
4
packages/playwright/types/testReporter.d.ts
vendored
|
|
@ -507,6 +507,10 @@ export interface JSONReport {
|
||||||
stats: {
|
stats: {
|
||||||
startTime: string; // Date in ISO 8601 format.
|
startTime: string; // Date in ISO 8601 format.
|
||||||
duration: number; // In milliseconds;
|
duration: number; // In milliseconds;
|
||||||
|
expected: number;
|
||||||
|
unexpected: number;
|
||||||
|
flaky: number;
|
||||||
|
skipped: number;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ import * as path from 'path';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import { test, expect, stripAnsi } from './playwright-test-fixtures';
|
import { test, expect, stripAnsi } from './playwright-test-fixtures';
|
||||||
|
|
||||||
test('should support spec.ok', async ({ runInlineTest }) => {
|
test('should support spec.ok and stats', async ({ runInlineTest }) => {
|
||||||
const result = await runInlineTest({
|
const result = await runInlineTest({
|
||||||
'a.test.js': `
|
'a.test.js': `
|
||||||
import { test, expect } from '@playwright/test';
|
import { test, expect } from '@playwright/test';
|
||||||
|
|
@ -28,11 +28,18 @@ test('should support spec.ok', async ({ runInlineTest }) => {
|
||||||
test('math fails!', async ({}) => {
|
test('math fails!', async ({}) => {
|
||||||
expect(1 + 1).toBe(3);
|
expect(1 + 1).toBe(3);
|
||||||
});
|
});
|
||||||
|
test.skip('math skipped', async ({}) => {
|
||||||
|
});
|
||||||
`
|
`
|
||||||
}, { });
|
}, { });
|
||||||
expect(result.exitCode).toBe(1);
|
expect(result.exitCode).toBe(1);
|
||||||
expect(result.report.suites[0].specs[0].ok).toBe(true);
|
expect(result.report.suites[0].specs[0].ok).toBe(true);
|
||||||
expect(result.report.suites[0].specs[1].ok).toBe(false);
|
expect(result.report.suites[0].specs[1].ok).toBe(false);
|
||||||
|
expect(result.report.suites[0].specs[2].ok).toBe(true);
|
||||||
|
expect(result.report.stats.expected).toEqual(1);
|
||||||
|
expect(result.report.stats.unexpected).toEqual(1);
|
||||||
|
expect(result.report.stats.flaky).toEqual(0);
|
||||||
|
expect(result.report.stats.skipped).toEqual(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should not report skipped due to sharding', async ({ runInlineTest }) => {
|
test('should not report skipped due to sharding', async ({ runInlineTest }) => {
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,10 @@ export interface JSONReport {
|
||||||
stats: {
|
stats: {
|
||||||
startTime: string; // Date in ISO 8601 format.
|
startTime: string; // Date in ISO 8601 format.
|
||||||
duration: number; // In milliseconds;
|
duration: number; // In milliseconds;
|
||||||
|
expected: number;
|
||||||
|
unexpected: number;
|
||||||
|
flaky: number;
|
||||||
|
skipped: number;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue