chore: expose JSON Reporter types (#13241)

Resolves #13208
This commit is contained in:
Wojciech Jureczka 2022-04-14 22:55:29 +02:00 committed by GitHub
parent 562fd989df
commit 7ba527c65f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 230 additions and 70 deletions

View File

@ -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);
}

View File

@ -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-340490459
export {};

View File

@ -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-340490459
export {};

View File

@ -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';

View File

@ -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'));

View File

@ -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-340490459
export {};