feat(json report): expose startTime and duration (#27290)

Fixes #27183.
This commit is contained in:
Dmitry Gozman 2023-09-25 10:58:55 -07:00 committed by GitHub
parent d6ec1ae399
commit 66eb3043f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 7 deletions

View file

@ -55,10 +55,10 @@ class JSONReporter extends EmptyReporter {
}
override async onEnd(result: FullResult) {
await outputReport(this._serializeReport(), this.config, this._outputFile);
await outputReport(this._serializeReport(result), this.config, this._outputFile);
}
private _serializeReport(): JSONReport {
private _serializeReport(result: FullResult): JSONReport {
return {
config: {
...removePrivateFields(this.config),
@ -79,7 +79,11 @@ class JSONReporter extends EmptyReporter {
})
},
suites: this._mergeSuites(this.suite.suites),
errors: this._errors
errors: this._errors,
stats: {
startTime: result.startTime.toISOString(),
duration: result.duration,
},
};
}
@ -194,7 +198,7 @@ class JSONReporter extends EmptyReporter {
stderr: result.stderr.map(s => stdioEntry(s)),
retry: result.retry,
steps: steps.length ? steps.map(s => this._serializeTestStep(s)) : undefined,
startTime: result.startTime,
startTime: result.startTime.toISOString(),
attachments: result.attachments.map(a => ({
name: a.name,
contentType: a.contentType,

View file

@ -504,6 +504,10 @@ export interface JSONReport {
};
suites: JSONReportSuite[];
errors: TestError[];
stats: {
startTime: string; // Date in ISO 8601 format.
duration: number; // In milliseconds;
}
}
export interface JSONReportSuite {
@ -551,7 +555,7 @@ export interface JSONReportTestResult {
stderr: JSONReportSTDIOEntry[];
retry: number;
steps?: JSONReportTestStep[];
startTime: Date;
startTime: string; // Date in ISO 8601 format.
attachments: {
name: string;
path?: string;

View file

@ -63,7 +63,7 @@ test('should not report skipped due to sharding', async ({ runInlineTest }) => {
expect(result.report.suites[0].specs[1].tests[0].status).toBe('skipped');
});
test('should report projects', async ({ runInlineTest }, testInfo) => {
test('should report projects and stats', async ({ runInlineTest }, testInfo) => {
const result = await runInlineTest({
'playwright.config.ts': `
module.exports = {
@ -107,6 +107,9 @@ test('should report projects', async ({ runInlineTest }, testInfo) => {
expect(result.report.suites[0].specs[0].tests[0].projectName).toBe('p1');
expect(result.report.suites[0].specs[0].tests[1].projectName).toBe('p2');
expect(new Date(result.report.stats.startTime).valueOf()).not.toBeNaN();
expect(result.report.stats.duration).toEqual(expect.any(Number));
});
test('should show steps', async ({ runInlineTest }) => {

View file

@ -75,6 +75,10 @@ export interface JSONReport {
};
suites: JSONReportSuite[];
errors: TestError[];
stats: {
startTime: string; // Date in ISO 8601 format.
duration: number; // In milliseconds;
}
}
export interface JSONReportSuite {
@ -122,7 +126,7 @@ export interface JSONReportTestResult {
stderr: JSONReportSTDIOEntry[];
retry: number;
steps?: JSONReportTestStep[];
startTime: Date;
startTime: string; // Date in ISO 8601 format.
attachments: {
name: string;
path?: string;