diff --git a/packages/playwright/src/reporters/json.ts b/packages/playwright/src/reporters/json.ts index a04406920595e..8b9eab573e5c5 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 89b995ff35269..1fc639bc33e37 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': `