Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
feat(json report): add expected/unexpected/skipped/flaky stats (#27685)
Dmitry Gozmanfd82b2b3fa4d
diff --git a/packages/playwright/src/reporters/json.ts b/packages/playwright/src/reporters/json.tsindex f0bb1ecbb7..d677079ab5 100644--- a/packages/playwright/src/reporters/json.ts+++ b/packages/playwright/src/reporters/json.ts@@ -59,7 +59,7 @@ class JSONReporter extends EmptyReporter {}private _serializeReport(result: FullResult): JSONReport {- return {+ const report: JSONReport = {config: {...removePrivateFields(this.config),rootDir: toPosixPath(this.config.rootDir),@@ -83,8 +83,15 @@ class JSONReporter extends EmptyReporter {stats: {startTime: result.startTime.toISOString(),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[] {diff --git a/packages/playwright/types/testReporter.d.ts b/packages/playwright/types/testReporter.d.tsindex 0b3a472e08..d38f07be54 100644--- a/packages/playwright/types/testReporter.d.ts+++ b/packages/playwright/types/testReporter.d.ts@@ -507,6 +507,10 @@ export interface JSONReport {stats: {startTime: string; // Date in ISO 8601 format.duration: number; // In milliseconds;+ expected: number;+ unexpected: number;+ flaky: number;+ skipped: number;}}diff --git a/tests/playwright-test/reporter-json.spec.ts b/tests/playwright-test/reporter-json.spec.tsindex 2148c2cfe0..f86f22d4fd 100644--- a/tests/playwright-test/reporter-json.spec.ts+++ b/tests/playwright-test/reporter-json.spec.ts@@ -18,7 +18,7 @@ import * as path from 'path';import * as fs from 'fs';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({'a.test.js': `import { test, expect } from '@playwright/test';@@ -28,11 +28,18 @@ test('should support spec.ok', async ({ runInlineTest }) => {test('math fails!', async ({}) => {expect(1 + 1).toBe(3);});+ test.skip('math skipped', async ({}) => {+ });`}, { });expect(result.exitCode).toBe(1);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[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 }) => {diff --git a/utils/generate_types/overrides-testReporter.d.ts b/utils/generate_types/overrides-testReporter.d.tsindex fe371001af..db8ae7c6de 100644--- a/utils/generate_types/overrides-testReporter.d.ts+++ b/utils/generate_types/overrides-testReporter.d.ts@@ -78,6 +78,10 @@ export interface JSONReport {stats: {startTime: string; // Date in ISO 8601 format.duration: number; // In milliseconds;+ expected: number;+ unexpected: number;+ flaky: number;+ skipped: number;}}