Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

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

Yury Semikhatsky5502a16e1dcb
diff --git a/packages/playwright/src/reporters/junit.ts b/packages/playwright/src/reporters/junit.ts
index 00c8415b05..99e3fe6ba1 100644
--- a/packages/playwright/src/reporters/junit.ts
+++ b/packages/playwright/src/reporters/junit.ts
@@ -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
};
diff --git a/tests/playwright-test/reporter-junit.spec.ts b/tests/playwright-test/reporter-junit.spec.ts
index cade24f3b6..644db548b7 100644
--- a/tests/playwright-test/reporter-junit.spec.ts
+++ b/tests/playwright-test/reporter-junit.spec.ts
@@ -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);
+ });
});
}
\ No newline at end of file