fix(junit): merged report should preserve total duration (#30525)

Fixes https://github.com/microsoft/playwright/issues/30518
This commit is contained in:
Yury Semikhatsky 2024-04-25 13:34:17 -07:00 committed by GitHub
parent 714235d6c8
commit 5502a16e1d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 5 deletions

View File

@ -17,7 +17,6 @@
import fs from 'fs';
import path from 'path';
import type { FullConfig, FullResult, Suite, TestCase } from '../../types/testReporter';
import { monotonicTime } from 'playwright-core/lib/utils';
import { formatFailure, stripAnsiEscapes } from './base';
import EmptyReporter from './empty';
@ -34,7 +33,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 +61,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 +81,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);
});
});
}