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
chore: expose JSON Reporter types (#13241)
Wojciech Jureczka7ba527c65f5d
diff --git a/packages/playwright-test/src/reporters/json.ts b/packages/playwright-test/src/reporters/json.tsindex 97be4ad40a..7bb3f4d8d3 100644--- a/packages/playwright-test/src/reporters/json.ts+++ b/packages/playwright-test/src/reporters/json.ts@@ -16,76 +16,9 @@import fs from 'fs';import path from 'path';-import type { FullConfig, TestCase, Suite, TestResult, TestError, TestStep, FullResult, TestStatus, Location, Reporter } from '../../types/testReporter';+import type { FullConfig, TestCase, Suite, TestResult, TestError, TestStep, FullResult, Location, Reporter, JSONReport, JSONReportSuite, JSONReportSpec, JSONReportTest, JSONReportTestResult, JSONReportTestStep } from '../../types/testReporter';import { prepareErrorStack } from './base';-export interface JSONReport {- config: Omit<FullConfig, 'projects'> & {- projects: {- outputDir: string,- repeatEach: number,- retries: number,- metadata: any,- name: string,- testDir: string,- testIgnore: string[],- testMatch: string[],- timeout: number,- }[],- };- suites: JSONReportSuite[];- errors: TestError[];-}-export interface JSONReportSuite {- title: string;- file: string;- column: number;- line: number;- specs: JSONReportSpec[];- suites?: JSONReportSuite[];-}-export interface JSONReportSpec {- tags: string[],- title: string;- ok: boolean;- tests: JSONReportTest[];- file: string;- line: number;- column: number;-}-export interface JSONReportTest {- timeout: number;- annotations: { type: string, description?: string }[],- expectedStatus: TestStatus;- projectName: string;- results: JSONReportTestResult[];- status: 'skipped' | 'expected' | 'unexpected' | 'flaky';-}-export interface JSONReportTestResult {- workerIndex: number;- status: TestStatus | undefined;- duration: number;- error: TestError | undefined;- stdout: JSONReportSTDIOEntry[];- stderr: JSONReportSTDIOEntry[];- retry: number;- steps?: JSONReportTestStep[];- attachments: {- name: string;- path?: string;- body?: string;- contentType: string;- }[];- errorLocation?: Location;-}-export interface JSONReportTestStep {- title: string;- duration: number;- error: TestError | undefined;- steps?: JSONReportTestStep[];-}-export type JSONReportSTDIOEntry = { text: string } | { buffer: string };-export function toPosixPath(aPath: string): string {return aPath.split(path.sep).join(path.posix.sep);}diff --git a/packages/playwright-test/types/testReporter.d.ts b/packages/playwright-test/types/testReporter.d.tsindex 1c0e2e58fd..6cd9a127cf 100644--- a/packages/playwright-test/types/testReporter.d.ts+++ b/packages/playwright-test/types/testReporter.d.ts@@ -457,6 +457,79 @@ export interface Reporter {*/printsToStdio?(): boolean;}+export interface JSONReport {+ config: Omit<FullConfig, 'projects'> & {+ projects: {+ outputDir: string,+ repeatEach: number,+ retries: number,+ metadata: any,+ name: string,+ testDir: string,+ testIgnore: string[],+ testMatch: string[],+ timeout: number,+ }[],+ };+ suites: JSONReportSuite[];+ errors: TestError[];+}++export interface JSONReportSuite {+ title: string;+ file: string;+ column: number;+ line: number;+ specs: JSONReportSpec[];+ suites?: JSONReportSuite[];+}++export interface JSONReportSpec {+ tags: string[],+ title: string;+ ok: boolean;+ tests: JSONReportTest[];+ file: string;+ line: number;+ column: number;+}++export interface JSONReportTest {+ timeout: number;+ annotations: { type: string, description?: string }[],+ expectedStatus: TestStatus;+ projectName: string;+ results: JSONReportTestResult[];+ status: 'skipped' | 'expected' | 'unexpected' | 'flaky';+}++export interface JSONReportTestResult {+ workerIndex: number;+ status: TestStatus | undefined;+ duration: number;+ error: TestError | undefined;+ stdout: JSONReportSTDIOEntry[];+ stderr: JSONReportSTDIOEntry[];+ retry: number;+ steps?: JSONReportTestStep[];+ attachments: {+ name: string;+ path?: string;+ body?: string;+ contentType: string;+ }[];+ errorLocation?: Location;+}++export interface JSONReportTestStep {+ title: string;+ duration: number;+ error: TestError | undefined;+ steps?: JSONReportTestStep[];+}++export type JSONReportSTDIOEntry = { text: string } | { buffer: string };+// This is required to not export everything by default. See https://github.com/Microsoft/TypeScript/issues/19545#issuecomment-340490459export {};diff --git a/tests/config/experimental.d.ts b/tests/config/experimental.d.tsindex b349adbf11..cd7d4a4b7c 100644--- a/tests/config/experimental.d.ts+++ b/tests/config/experimental.d.ts@@ -20594,6 +20594,79 @@ export interface Reporter {*/printsToStdio?(): boolean;}+export interface JSONReport {+ config: Omit<FullConfig, 'projects'> & {+ projects: {+ outputDir: string,+ repeatEach: number,+ retries: number,+ metadata: any,+ name: string,+ testDir: string,+ testIgnore: string[],+ testMatch: string[],+ timeout: number,+ }[],+ };+ suites: JSONReportSuite[];+ errors: TestError[];+}++export interface JSONReportSuite {+ title: string;+ file: string;+ column: number;+ line: number;+ specs: JSONReportSpec[];+ suites?: JSONReportSuite[];+}++export interface JSONReportSpec {+ tags: string[],+ title: string;+ ok: boolean;+ tests: JSONReportTest[];+ file: string;+ line: number;+ column: number;+}++export interface JSONReportTest {+ timeout: number;+ annotations: { type: string, description?: string }[],+ expectedStatus: TestStatus;+ projectName: string;+ results: JSONReportTestResult[];+ status: 'skipped' | 'expected' | 'unexpected' | 'flaky';+}++export interface JSONReportTestResult {+ workerIndex: number;+ status: TestStatus | undefined;+ duration: number;+ error: TestError | undefined;+ stdout: JSONReportSTDIOEntry[];+ stderr: JSONReportSTDIOEntry[];+ retry: number;+ steps?: JSONReportTestStep[];+ attachments: {+ name: string;+ path?: string;+ body?: string;+ contentType: string;+ }[];+ errorLocation?: Location;+}++export interface JSONReportTestStep {+ title: string;+ duration: number;+ error: TestError | undefined;+ steps?: JSONReportTestStep[];+}++export type JSONReportSTDIOEntry = { text: string } | { buffer: string };+// This is required to not export everything by default. See https://github.com/Microsoft/TypeScript/issues/19545#issuecomment-340490459export {};diff --git a/tests/playwright-test/playwright-test-fixtures.ts b/tests/playwright-test/playwright-test-fixtures.tsindex abf3df3de9..d1ec8a3611 100644--- a/tests/playwright-test/playwright-test-fixtures.ts+++ b/tests/playwright-test/playwright-test-fixtures.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import type { JSONReport, JSONReportSuite } from '@playwright/test/src/reporters/json';+import type { JSONReport, JSONReportSuite } from '@playwright/test/reporter';import * as fs from 'fs';import * as os from 'os';import * as path from 'path';diff --git a/utils/generate_types/index.js b/utils/generate_types/index.jsindex 3a74ca0c26..d2c9089a27 100644--- a/utils/generate_types/index.js+++ b/utils/generate_types/index.js@@ -591,7 +591,15 @@ class TypesGenerator {...coreDocumentation.classesArray.map(cls => cls.name),...testDocumentation.classesArray.map(cls => cls.name),]),- ignoreMissing: new Set(['FullResult']),+ ignoreMissing: new Set([+ 'FullResult',+ 'JSONReport',+ 'JSONReportSuite',+ 'JSONReportSpec',+ 'JSONReportTest',+ 'JSONReportTestResult',+ 'JSONReportTestStep',+ ]),includeExperimental,});return await generator.generateTypes(path.join(__dirname, 'overrides-testReporter.d.ts'));diff --git a/utils/generate_types/overrides-testReporter.d.ts b/utils/generate_types/overrides-testReporter.d.tsindex 39e1a8bf05..4ea382858c 100644--- a/utils/generate_types/overrides-testReporter.d.ts+++ b/utils/generate_types/overrides-testReporter.d.ts@@ -48,5 +48,78 @@ export interface Reporter {onEnd?(result: FullResult): void | Promise<void>;}+export interface JSONReport {+ config: Omit<FullConfig, 'projects'> & {+ projects: {+ outputDir: string,+ repeatEach: number,+ retries: number,+ metadata: any,+ name: string,+ testDir: string,+ testIgnore: string[],+ testMatch: string[],+ timeout: number,+ }[],+ };+ suites: JSONReportSuite[];+ errors: TestError[];+}++export interface JSONReportSuite {+ title: string;+ file: string;+ column: number;+ line: number;+ specs: JSONReportSpec[];+ suites?: JSONReportSuite[];+}++export interface JSONReportSpec {+ tags: string[],+ title: string;+ ok: boolean;+ tests: JSONReportTest[];+ file: string;+ line: number;+ column: number;+}++export interface JSONReportTest {+ timeout: number;+ annotations: { type: string, description?: string }[],+ expectedStatus: TestStatus;+ projectName: string;+ results: JSONReportTestResult[];+ status: 'skipped' | 'expected' | 'unexpected' | 'flaky';+}++export interface JSONReportTestResult {+ workerIndex: number;+ status: TestStatus | undefined;+ duration: number;+ error: TestError | undefined;+ stdout: JSONReportSTDIOEntry[];+ stderr: JSONReportSTDIOEntry[];+ retry: number;+ steps?: JSONReportTestStep[];+ attachments: {+ name: string;+ path?: string;+ body?: string;+ contentType: string;+ }[];+ errorLocation?: Location;+}++export interface JSONReportTestStep {+ title: string;+ duration: number;+ error: TestError | undefined;+ steps?: JSONReportTestStep[];+}++export type JSONReportSTDIOEntry = { text: string } | { buffer: string };+// This is required to not export everything by default. See https://github.com/Microsoft/TypeScript/issues/19545#issuecomment-340490459export {};