Skip to content

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

fix(reporter): merge json specs across projects regardless of cwd (#43267)

Ravi Kumar Gupta606f017a1b51
diff --git a/packages/playwright/src/reporters/json.ts b/packages/playwright/src/reporters/json.ts
index a044069205..8b9eab573e 100644
--- a/packages/playwright/src/reporters/json.ts
+++ b/packages/playwright/src/reporters/json.ts
@@ -156,7 +156,7 @@ class JSONReporter implements ReporterV2 {
}
for (const spec of from.specs || []) {
- const toSpec = to.specs.find(s => s.title === spec.title && s.file === toPosixPath(path.relative(this.config.rootDir, spec.file)) && s.line === spec.line && s.column === spec.column);
+ const toSpec = to.specs.find(s => s.title === spec.title && this._locationMatches(s, spec));
if (toSpec)
toSpec.tests.push(...spec.tests);
else
diff --git a/tests/playwright-test/reporter-json.spec.ts b/tests/playwright-test/reporter-json.spec.ts
index 89b995ff35..1fc639bc33 100644
--- a/tests/playwright-test/reporter-json.spec.ts
+++ b/tests/playwright-test/reporter-json.spec.ts
@@ -119,6 +119,35 @@ test('should report projects and stats', async ({ runInlineTest }, testInfo) =>
expect(result.report.stats.duration).toEqual(expect.any(Number));
});
+test('should merge specs from all projects when testDir is not cwd', async ({ runInlineTest }) => {
+ const result = await runInlineTest({
+ 'playwright.config.ts': `
+ module.exports = {
+ testDir: 'tests',
+ projects: [{ name: 'p1' }, { name: 'p2' }],
+ };
+ `,
+ 'tests/a.test.js': `
+ import { test, expect } from '@playwright/test';
+ test('math works!', async ({}) => {
+ expect(1 + 1).toBe(2);
+ });
+ test.describe('suite', () => {
+ test('nested math works!', async ({}) => {
+ expect(1 + 1).toBe(2);
+ });
+ });
+ `
+ });
+ expect(result.exitCode).toBe(0);
+ const fileSuite = result.report.suites[0];
+ expect(fileSuite.specs.length).toBe(1);
+ expect(fileSuite.specs[0].tests.map(t => t.projectName)).toEqual(['p1', 'p2']);
+ expect(fileSuite.suites!.length).toBe(1);
+ expect(fileSuite.suites![0].specs.length).toBe(1);
+ expect(fileSuite.suites![0].specs[0].tests.map(t => t.projectName)).toEqual(['p1', 'p2']);
+});
+
test('should show steps', async ({ runInlineTest }) => {
const result = await runInlineTest({
'a.test.js': `