Skip to content

Commit 30dcce7

Browse files
authored
fix: update config.projects when merging projects (microsoft#39145)
1 parent 5db56c1 commit 30dcce7

2 files changed

Lines changed: 51 additions & 1 deletion

File tree

packages/playwright/src/isomorphic/teleReceiver.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,19 @@ export class TeleReporterReceiver {
338338
projectSuite = new TeleSuite(project.name, 'project');
339339
this._rootSuite._addSuite(projectSuite);
340340
}
341+
342+
const parsed = this._parseProject(project);
341343
// Always update project in watch mode.
342-
projectSuite._project = this._parseProject(project);
344+
projectSuite._project = parsed;
345+
346+
let index = -1;
347+
if (this._options.mergeProjects)
348+
index = this._config.projects.findIndex(p => p.name === project.name);
349+
if (index === -1)
350+
this._config.projects.push(parsed);
351+
else
352+
this._config.projects[index] = parsed;
353+
343354
for (const suite of project.suites)
344355
this._mergeSuiteInto(suite, projectSuite);
345356
}

tests/playwright-test/reporter-blob.spec.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,3 +2287,42 @@ test('shard chart', async ({ runInlineTest, writeFiles, showReport, page, mergeR
22872287
- listitem /@mac/
22882288
`);
22892289
});
2290+
2291+
test('should populate projects in config when merging reports', async ({ runInlineTest, mergeReports }) => {
2292+
const reportDir = test.info().outputPath('blob-report');
2293+
class CustomReporter {
2294+
onBegin(config, suite) {
2295+
const projectNames = config.projects.map(p => p.name);
2296+
console.log('%%' + JSON.stringify(projectNames));
2297+
}
2298+
}
2299+
const files = {
2300+
'reporter.js': `module.exports = ${CustomReporter.toString()};`,
2301+
'playwright.config.ts': `
2302+
module.exports = {
2303+
reporter: [['blob', { outputDir: '${reportDir.replace(/\\/g, '/')}' }]],
2304+
projects: [
2305+
{ name: 'setup' },
2306+
{ name: 'p1', dependencies: ['setup'] },
2307+
{ name: 'p2', dependencies: ['setup'] },
2308+
]
2309+
};
2310+
`,
2311+
'a.test.js': `
2312+
import { test } from '@playwright/test';
2313+
test('test 1', async ({}) => {});
2314+
`,
2315+
};
2316+
2317+
await runInlineTest(files, { shard: `1/2`, workers: 1 });
2318+
await runInlineTest(files, { shard: `2/2`, workers: 1 }, { PWTEST_BLOB_DO_NOT_REMOVE: '1' });
2319+
2320+
const reportFiles = await fs.promises.readdir(reportDir);
2321+
expect(reportFiles).toHaveLength(2);
2322+
2323+
const { exitCode, outputLines } = await mergeReports(reportDir, {}, { additionalArgs: ['--reporter', test.info().outputPath('reporter.js')] });
2324+
expect(exitCode).toBe(0);
2325+
2326+
const projectNames = JSON.parse(outputLines[0]);
2327+
expect(projectNames).toEqual(['setup', 'p1', 'setup', 'p2']);
2328+
});

0 commit comments

Comments
 (0)