Skip to content

Commit 5f7db5b

Browse files
authored
fix: properly merge projects in defineConfig (microsoft#36898)
1 parent 33e70e3 commit 5f7db5b

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

packages/playwright/src/common/configLoader.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export const defineConfig = (...configs: any[]) => {
3434
let result = configs[0];
3535
for (let i = 1; i < configs.length; ++i) {
3636
const config = configs[i];
37+
const prevProjects = result.projects;
3738
result = {
3839
...result,
3940
...config,
@@ -63,7 +64,7 @@ export const defineConfig = (...configs: any[]) => {
6364
projectOverrides.set(project.name, project);
6465

6566
const projects = [];
66-
for (const project of result.projects || []) {
67+
for (const project of prevProjects || []) {
6768
const projectOverride = projectOverrides.get(project.name);
6869
if (projectOverride) {
6970
projects.push({

tests/playwright-test/config.spec.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,8 +661,8 @@ test('should merge configs', async ({ runInlineTest }) => {
661661
use: { foo: 1, bar: 2 },
662662
expect: { timeout: 12 },
663663
projects: [
664-
{ name: 'B', timeout: 40, use: {} },
665-
{ name: 'A', timeout: 50, use: {} }
664+
{ name: 'A', timeout: 50, use: {} },
665+
{ name: 'B', timeout: 40 },
666666
],
667667
webServer: [{
668668
command: 'echo 123',
@@ -680,6 +680,33 @@ test('should merge configs', async ({ runInlineTest }) => {
680680
expect(result.exitCode).toBe(0);
681681
});
682682

683+
test('should merge projects in the config', async ({ runInlineTest }) => {
684+
const result = await runInlineTest({
685+
'playwright.config.ts': `
686+
import { defineConfig, expect } from '@playwright/test';
687+
const baseConfig = defineConfig({
688+
projects: [{ name: 'A', timeout: 5_000 }, { name: 'B', timeout: 6_000 }],
689+
});
690+
const derivedConfig = defineConfig(baseConfig, {
691+
projects: [{ name: 'A', timeout: 7_000 }, { name: 'C', timeout: 8_000 }],
692+
});
693+
694+
expect(derivedConfig).toEqual(expect.objectContaining({
695+
projects: [
696+
{ name: 'A', timeout: 7_000, use: {} },
697+
{ name: 'B', timeout: 6_000 },
698+
{ name: 'C', timeout: 8_000 },
699+
],
700+
}));
701+
`,
702+
'a.test.ts': `
703+
import { test } from '@playwright/test';
704+
test('pass', async ({}) => {});
705+
`
706+
});
707+
expect(result.exitCode).toBe(0);
708+
});
709+
683710
test('should merge ct configs', async ({ runInlineTest }) => {
684711
const result = await runInlineTest({
685712
'playwright.config.ts': `

0 commit comments

Comments
 (0)