feat(json report): expose startTime and duration (#27290)
Fixes #27183.
This commit is contained in:
parent
d6ec1ae399
commit
66eb3043f5
|
|
@ -55,10 +55,10 @@ class JSONReporter extends EmptyReporter {
|
||||||
}
|
}
|
||||||
|
|
||||||
override async onEnd(result: FullResult) {
|
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 {
|
return {
|
||||||
config: {
|
config: {
|
||||||
...removePrivateFields(this.config),
|
...removePrivateFields(this.config),
|
||||||
|
|
@ -79,7 +79,11 @@ class JSONReporter extends EmptyReporter {
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
suites: this._mergeSuites(this.suite.suites),
|
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)),
|
stderr: result.stderr.map(s => stdioEntry(s)),
|
||||||
retry: result.retry,
|
retry: result.retry,
|
||||||
steps: steps.length ? steps.map(s => this._serializeTestStep(s)) : undefined,
|
steps: steps.length ? steps.map(s => this._serializeTestStep(s)) : undefined,
|
||||||
startTime: result.startTime,
|
startTime: result.startTime.toISOString(),
|
||||||
attachments: result.attachments.map(a => ({
|
attachments: result.attachments.map(a => ({
|
||||||
name: a.name,
|
name: a.name,
|
||||||
contentType: a.contentType,
|
contentType: a.contentType,
|
||||||
|
|
|
||||||
6
packages/playwright/types/testReporter.d.ts
vendored
6
packages/playwright/types/testReporter.d.ts
vendored
|
|
@ -504,6 +504,10 @@ export interface JSONReport {
|
||||||
};
|
};
|
||||||
suites: JSONReportSuite[];
|
suites: JSONReportSuite[];
|
||||||
errors: TestError[];
|
errors: TestError[];
|
||||||
|
stats: {
|
||||||
|
startTime: string; // Date in ISO 8601 format.
|
||||||
|
duration: number; // In milliseconds;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface JSONReportSuite {
|
export interface JSONReportSuite {
|
||||||
|
|
@ -551,7 +555,7 @@ export interface JSONReportTestResult {
|
||||||
stderr: JSONReportSTDIOEntry[];
|
stderr: JSONReportSTDIOEntry[];
|
||||||
retry: number;
|
retry: number;
|
||||||
steps?: JSONReportTestStep[];
|
steps?: JSONReportTestStep[];
|
||||||
startTime: Date;
|
startTime: string; // Date in ISO 8601 format.
|
||||||
attachments: {
|
attachments: {
|
||||||
name: string;
|
name: string;
|
||||||
path?: string;
|
path?: string;
|
||||||
|
|
|
||||||
|
|
@ -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');
|
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({
|
const result = await runInlineTest({
|
||||||
'playwright.config.ts': `
|
'playwright.config.ts': `
|
||||||
module.exports = {
|
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[0].projectName).toBe('p1');
|
||||||
expect(result.report.suites[0].specs[0].tests[1].projectName).toBe('p2');
|
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 }) => {
|
test('should show steps', async ({ runInlineTest }) => {
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,10 @@ export interface JSONReport {
|
||||||
};
|
};
|
||||||
suites: JSONReportSuite[];
|
suites: JSONReportSuite[];
|
||||||
errors: TestError[];
|
errors: TestError[];
|
||||||
|
stats: {
|
||||||
|
startTime: string; // Date in ISO 8601 format.
|
||||||
|
duration: number; // In milliseconds;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface JSONReportSuite {
|
export interface JSONReportSuite {
|
||||||
|
|
@ -122,7 +126,7 @@ export interface JSONReportTestResult {
|
||||||
stderr: JSONReportSTDIOEntry[];
|
stderr: JSONReportSTDIOEntry[];
|
||||||
retry: number;
|
retry: number;
|
||||||
steps?: JSONReportTestStep[];
|
steps?: JSONReportTestStep[];
|
||||||
startTime: Date;
|
startTime: string; // Date in ISO 8601 format.
|
||||||
attachments: {
|
attachments: {
|
||||||
name: string;
|
name: string;
|
||||||
path?: string;
|
path?: string;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue