fix(junit): merged report should preserve total duration

Fixes https://github.com/microsoft/playwright/issues/30518
This commit is contained in:
Yury Semikhatsky 2024-04-24 15:11:29 -07:00
parent f1f3929a67
commit 5fbc3e3513
2 changed files with 17 additions and 4 deletions

View file

@ -34,7 +34,6 @@ class JUnitReporter extends EmptyReporter {
private configDir: string;
private suite!: Suite;
private timestamp!: Date;
private startTime!: number;
private totalTests = 0;
private totalFailures = 0;
private totalSkipped = 0;
@ -63,11 +62,9 @@ class JUnitReporter extends EmptyReporter {
override onBegin(suite: Suite) {
this.suite = suite;
this.timestamp = new Date();
this.startTime = monotonicTime();
}
override async onEnd(result: FullResult) {
const duration = monotonicTime() - this.startTime;
const children: XMLEntry[] = [];
for (const projectSuite of this.suite.suites) {
for (const fileSuite of projectSuite.suites)
@ -85,7 +82,7 @@ class JUnitReporter extends EmptyReporter {
failures: self.totalFailures,
skipped: self.totalSkipped,
errors: 0,
time: duration / 1000
time: result.duration / 1000
},
children
};

View file

@ -505,5 +505,21 @@ for (const useIntermediateMergeReport of [false, true] as const) {
expect(fs.existsSync(testInfo.outputPath('foo', 'bar', 'baz', 'my-report.xml'))).toBe(true);
});
});
test('testsuites time is test run wall time', async ({ runInlineTest }) => {
test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/30518' });
const result = await runInlineTest({
'a.test.js': `
import { test, expect } from '@playwright/test';
test('one', async ({}) => {
await new Promise(f => setTimeout(f, 1000));
});
`
}, { reporter: 'junit' });
const xml = parseXML(result.output);
const time = +xml['testsuites']['$']['time'];
expect(time).toBe(result.report.stats.duration/1000);
expect(time).toBeGreaterThan(1);
});
});
}