mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(junit): merged report should preserve total duration (#30525)
Fixes https://github.com/microsoft/playwright/issues/30518
This commit is contained in:
parent
714235d6c8
commit
5502a16e1d
@ -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
|
||||
};
|
||||
|
||||
@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user