Skip to content

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

fix: properly merge projects in defineConfig (#36898)

Yury Semikhatsky5f7db5bab4be
diff --git a/packages/playwright/src/common/configLoader.ts b/packages/playwright/src/common/configLoader.ts
index 4833197773..4d35f4087a 100644
--- a/packages/playwright/src/common/configLoader.ts
+++ b/packages/playwright/src/common/configLoader.ts
@@ -34,6 +34,7 @@ export const defineConfig = (...configs: any[]) => {
let result = configs[0];
for (let i = 1; i < configs.length; ++i) {
const config = configs[i];
+ const prevProjects = result.projects;
result = {
...result,
...config,
@@ -63,7 +64,7 @@ export const defineConfig = (...configs: any[]) => {
projectOverrides.set(project.name, project);
const projects = [];
- for (const project of result.projects || []) {
+ for (const project of prevProjects || []) {
const projectOverride = projectOverrides.get(project.name);
if (projectOverride) {
projects.push({
diff --git a/tests/playwright-test/config.spec.ts b/tests/playwright-test/config.spec.ts
index 30945fdc1e..2c6342f001 100644
--- a/tests/playwright-test/config.spec.ts
+++ b/tests/playwright-test/config.spec.ts
@@ -661,8 +661,8 @@ test('should merge configs', async ({ runInlineTest }) => {
use: { foo: 1, bar: 2 },
expect: { timeout: 12 },
projects: [
- { name: 'B', timeout: 40, use: {} },
- { name: 'A', timeout: 50, use: {} }
+ { name: 'A', timeout: 50, use: {} },
+ { name: 'B', timeout: 40 },
],
webServer: [{
command: 'echo 123',
@@ -680,6 +680,33 @@ test('should merge configs', async ({ runInlineTest }) => {
expect(result.exitCode).toBe(0);
});
+test('should merge projects in the config', async ({ runInlineTest }) => {
+ const result = await runInlineTest({
+ 'playwright.config.ts': `
+ import { defineConfig, expect } from '@playwright/test';
+ const baseConfig = defineConfig({
+ projects: [{ name: 'A', timeout: 5_000 }, { name: 'B', timeout: 6_000 }],
+ });
+ const derivedConfig = defineConfig(baseConfig, {
+ projects: [{ name: 'A', timeout: 7_000 }, { name: 'C', timeout: 8_000 }],
+ });
+
+ expect(derivedConfig).toEqual(expect.objectContaining({
+ projects: [
+ { name: 'A', timeout: 7_000, use: {} },
+ { name: 'B', timeout: 6_000 },
+ { name: 'C', timeout: 8_000 },
+ ],
+ }));
+ `,
+ 'a.test.ts': `
+ import { test } from '@playwright/test';
+ test('pass', async ({}) => {});
+ `
+ });
+ expect(result.exitCode).toBe(0);
+});
+
test('should merge ct configs', async ({ runInlineTest }) => {
const result = await runInlineTest({
'playwright.config.ts': `