Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix(components): make sure defineConfig(c1, c2) works (#28608)
Dmitry Gozmand2dc8eb1e3e5
diff --git a/packages/playwright-ct-core/index.d.ts b/packages/playwright-ct-core/index.d.tsindex 397a4cdb7f..cd052db756 100644--- a/packages/playwright-ct-core/index.d.ts+++ b/packages/playwright-ct-core/index.d.ts@@ -62,5 +62,8 @@ export const test: TestType<export function defineConfig(config: PlaywrightTestConfig): PlaywrightTestConfig;export function defineConfig<T>(config: PlaywrightTestConfig<T>): PlaywrightTestConfig<T>;export function defineConfig<T, W>(config: PlaywrightTestConfig<T, W>): PlaywrightTestConfig<T, W>;+export function defineConfig(config: PlaywrightTestConfig, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig;+export function defineConfig<T>(config: PlaywrightTestConfig<T>, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig<T>;+export function defineConfig<T, W>(config: PlaywrightTestConfig<T, W>, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig<T, W>;export { expect, devices } from 'playwright/test';diff --git a/packages/playwright-ct-core/index.js b/packages/playwright-ct-core/index.jsindex c323f1c6ec..1b8fd60a2d 100644--- a/packages/playwright-ct-core/index.js+++ b/packages/playwright-ct-core/index.js@@ -17,7 +17,7 @@const { test: baseTest, expect, devices, defineConfig: originalDefineConfig } = require('playwright/test');const { fixtures } = require('./lib/mount');-const defineConfig = config => originalDefineConfig({+const defineConfig = (config, ...configs) => originalDefineConfig({...config,build: {...config.build,@@ -25,7 +25,7 @@ const defineConfig = config => originalDefineConfig({[require.resolve('./lib/tsxTransform')]],}-});+}, ...configs);const test = baseTest.extend(fixtures);diff --git a/packages/playwright-ct-react/index.d.ts b/packages/playwright-ct-react/index.d.tsindex 9c8d0a914d..3e994cf8fa 100644--- a/packages/playwright-ct-react/index.d.ts+++ b/packages/playwright-ct-react/index.d.ts@@ -62,5 +62,8 @@ export const test: TestType<export function defineConfig(config: PlaywrightTestConfig): PlaywrightTestConfig;export function defineConfig<T>(config: PlaywrightTestConfig<T>): PlaywrightTestConfig<T>;export function defineConfig<T, W>(config: PlaywrightTestConfig<T, W>): PlaywrightTestConfig<T, W>;+export function defineConfig(config: PlaywrightTestConfig, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig;+export function defineConfig<T>(config: PlaywrightTestConfig<T>, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig<T>;+export function defineConfig<T, W>(config: PlaywrightTestConfig<T, W>, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig<T, W>;export { expect, devices } from 'playwright/test';diff --git a/packages/playwright-ct-react/index.js b/packages/playwright-ct-react/index.jsindex 04d69e08f5..cc7b4fcb03 100644--- a/packages/playwright-ct-react/index.js+++ b/packages/playwright-ct-react/index.js@@ -24,6 +24,6 @@ const plugin = () => {path.join(__dirname, 'registerSource.mjs'),() => import('@vitejs/plugin-react').then(plugin => plugin.default()));};-const defineConfig = config => originalDefineConfig({ ...config, _plugins: [plugin] });+const defineConfig = (config, ...configs) => originalDefineConfig({ ...config, _plugins: [plugin] }, ...configs);module.exports = { test, expect, devices, defineConfig };diff --git a/packages/playwright-ct-react17/index.d.ts b/packages/playwright-ct-react17/index.d.tsindex 9c8d0a914d..3e994cf8fa 100644--- a/packages/playwright-ct-react17/index.d.ts+++ b/packages/playwright-ct-react17/index.d.ts@@ -62,5 +62,8 @@ export const test: TestType<export function defineConfig(config: PlaywrightTestConfig): PlaywrightTestConfig;export function defineConfig<T>(config: PlaywrightTestConfig<T>): PlaywrightTestConfig<T>;export function defineConfig<T, W>(config: PlaywrightTestConfig<T, W>): PlaywrightTestConfig<T, W>;+export function defineConfig(config: PlaywrightTestConfig, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig;+export function defineConfig<T>(config: PlaywrightTestConfig<T>, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig<T>;+export function defineConfig<T, W>(config: PlaywrightTestConfig<T, W>, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig<T, W>;export { expect, devices } from 'playwright/test';diff --git a/packages/playwright-ct-react17/index.js b/packages/playwright-ct-react17/index.jsindex 04d69e08f5..cc7b4fcb03 100644--- a/packages/playwright-ct-react17/index.js+++ b/packages/playwright-ct-react17/index.js@@ -24,6 +24,6 @@ const plugin = () => {path.join(__dirname, 'registerSource.mjs'),() => import('@vitejs/plugin-react').then(plugin => plugin.default()));};-const defineConfig = config => originalDefineConfig({ ...config, _plugins: [plugin] });+const defineConfig = (config, ...configs) => originalDefineConfig({ ...config, _plugins: [plugin] }, ...configs);module.exports = { test, expect, devices, defineConfig };diff --git a/packages/playwright-ct-solid/index.d.ts b/packages/playwright-ct-solid/index.d.tsindex 9c8d0a914d..3e994cf8fa 100644--- a/packages/playwright-ct-solid/index.d.ts+++ b/packages/playwright-ct-solid/index.d.ts@@ -62,5 +62,8 @@ export const test: TestType<export function defineConfig(config: PlaywrightTestConfig): PlaywrightTestConfig;export function defineConfig<T>(config: PlaywrightTestConfig<T>): PlaywrightTestConfig<T>;export function defineConfig<T, W>(config: PlaywrightTestConfig<T, W>): PlaywrightTestConfig<T, W>;+export function defineConfig(config: PlaywrightTestConfig, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig;+export function defineConfig<T>(config: PlaywrightTestConfig<T>, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig<T>;+export function defineConfig<T, W>(config: PlaywrightTestConfig<T, W>, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig<T, W>;export { expect, devices } from 'playwright/test';diff --git a/packages/playwright-ct-solid/index.js b/packages/playwright-ct-solid/index.jsindex 2176a7a95e..110c394255 100644--- a/packages/playwright-ct-solid/index.js+++ b/packages/playwright-ct-solid/index.js@@ -24,6 +24,6 @@ const plugin = () => {path.join(__dirname, 'registerSource.mjs'),() => import('vite-plugin-solid').then(plugin => plugin.default()));};-const defineConfig = config => originalDefineConfig({ ...config, _plugins: [plugin] });+const defineConfig = (config, ...configs) => originalDefineConfig({ ...config, _plugins: [plugin] }, ...configs);module.exports = { test, expect, devices, defineConfig };diff --git a/packages/playwright-ct-svelte/index.d.ts b/packages/playwright-ct-svelte/index.d.tsindex 0fd476f7ed..d1f7a5a07b 100644--- a/packages/playwright-ct-svelte/index.d.ts+++ b/packages/playwright-ct-svelte/index.d.ts@@ -70,5 +70,8 @@ export const test: TestType<export function defineConfig(config: PlaywrightTestConfig): PlaywrightTestConfig;export function defineConfig<T>(config: PlaywrightTestConfig<T>): PlaywrightTestConfig<T>;export function defineConfig<T, W>(config: PlaywrightTestConfig<T, W>): PlaywrightTestConfig<T, W>;+export function defineConfig(config: PlaywrightTestConfig, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig;+export function defineConfig<T>(config: PlaywrightTestConfig<T>, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig<T>;+export function defineConfig<T, W>(config: PlaywrightTestConfig<T, W>, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig<T, W>;export { expect, devices } from 'playwright/test';diff --git a/packages/playwright-ct-svelte/index.js b/packages/playwright-ct-svelte/index.jsindex 53b5b14a17..313af1b634 100644--- a/packages/playwright-ct-svelte/index.js+++ b/packages/playwright-ct-svelte/index.js@@ -24,6 +24,6 @@ const plugin = () => {path.join(__dirname, 'registerSource.mjs'),() => import('@sveltejs/vite-plugin-svelte').then(plugin => plugin.svelte()));};-const defineConfig = config => originalDefineConfig({ ...config, _plugins: [plugin] });+const defineConfig = (config, ...configs) => originalDefineConfig({ ...config, _plugins: [plugin] }, ...configs);module.exports = { test, expect, devices, defineConfig };diff --git a/packages/playwright-ct-vue/index.d.ts b/packages/playwright-ct-vue/index.d.tsindex 249fe643d7..6cb5c751b3 100644--- a/packages/playwright-ct-vue/index.d.ts+++ b/packages/playwright-ct-vue/index.d.ts@@ -90,5 +90,8 @@ export const test: TestType<export function defineConfig(config: PlaywrightTestConfig): PlaywrightTestConfig;export function defineConfig<T>(config: PlaywrightTestConfig<T>): PlaywrightTestConfig<T>;export function defineConfig<T, W>(config: PlaywrightTestConfig<T, W>): PlaywrightTestConfig<T, W>;+export function defineConfig(config: PlaywrightTestConfig, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig;+export function defineConfig<T>(config: PlaywrightTestConfig<T>, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig<T>;+export function defineConfig<T, W>(config: PlaywrightTestConfig<T, W>, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig<T, W>;export { expect, devices } from 'playwright/test';diff --git a/packages/playwright-ct-vue/index.js b/packages/playwright-ct-vue/index.jsindex cb9c629a1f..ce321f8415 100644--- a/packages/playwright-ct-vue/index.js+++ b/packages/playwright-ct-vue/index.js@@ -24,6 +24,6 @@ const plugin = () => {path.join(__dirname, 'registerSource.mjs'),() => import('@vitejs/plugin-vue').then(plugin => plugin.default()));}-const defineConfig = config => originalDefineConfig({ ...config, _plugins: [plugin] });+const defineConfig = (config, ...configs) => originalDefineConfig({ ...config, _plugins: [plugin] }, ...configs);module.exports = { test, expect, devices, defineConfig };diff --git a/packages/playwright-ct-vue2/index.d.ts b/packages/playwright-ct-vue2/index.d.tsindex 9e0a08a02c..b3a22bed84 100644--- a/packages/playwright-ct-vue2/index.d.ts+++ b/packages/playwright-ct-vue2/index.d.ts@@ -90,5 +90,8 @@ export const test: TestType<export function defineConfig(config: PlaywrightTestConfig): PlaywrightTestConfig;export function defineConfig<T>(config: PlaywrightTestConfig<T>): PlaywrightTestConfig<T>;export function defineConfig<T, W>(config: PlaywrightTestConfig<T, W>): PlaywrightTestConfig<T, W>;+export function defineConfig(config: PlaywrightTestConfig, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig;+export function defineConfig<T>(config: PlaywrightTestConfig<T>, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig<T>;+export function defineConfig<T, W>(config: PlaywrightTestConfig<T, W>, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig<T, W>;export { expect, devices } from 'playwright/test';diff --git a/packages/playwright-ct-vue2/index.js b/packages/playwright-ct-vue2/index.jsindex 9c8c71cb8e..8930a8a4f1 100644--- a/packages/playwright-ct-vue2/index.js+++ b/packages/playwright-ct-vue2/index.js@@ -24,6 +24,6 @@ const plugin = () => {path.join(__dirname, 'registerSource.mjs'),() => import('@vitejs/plugin-vue2').then(plugin => plugin.default()));};-const defineConfig = config => originalDefineConfig({ ...config, _plugins: [plugin] });+const defineConfig = (config, ...configs) => originalDefineConfig({ ...config, _plugins: [plugin] }, ...configs);module.exports = { test, expect, devices, defineConfig };diff --git a/packages/playwright/src/common/configLoader.ts b/packages/playwright/src/common/configLoader.tsindex 9d648ed0ea..7fbbed257a 100644--- a/packages/playwright/src/common/configLoader.ts+++ b/packages/playwright/src/common/configLoader.ts@@ -42,6 +42,10 @@ export const defineConfig = (...configs: any[]) => {...result.use,...config.use,},+ build: {+ ...result.build,+ ...config.build,+ },webServer: [...(Array.isArray(result.webServer) ? result.webServer : (result.webServer ? [result.webServer] : [])),...(Array.isArray(config.webServer) ? config.webServer : (config.webServer ? [config.webServer] : [])),diff --git a/tests/playwright-test/config.spec.ts b/tests/playwright-test/config.spec.tsindex fb2f1888d2..0d786de0ce 100644--- a/tests/playwright-test/config.spec.ts+++ b/tests/playwright-test/config.spec.ts@@ -557,3 +557,37 @@ test('should merge configs', async ({ runInlineTest }) => {});expect(result.exitCode).toBe(0);});++test('should merge ct configs', async ({ runInlineTest }) => {+ const result = await runInlineTest({+ 'playwright.config.ts': `+ import { defineConfig, expect } from '@playwright/experimental-ct-react';+ const baseConfig = defineConfig({+ timeout: 10,+ use: {+ foo: 1,+ },+ });+ const derivedConfig = defineConfig(baseConfig, {+ grep: 'hi',+ use: {+ bar: 2,+ },+ });++ // Make sure ct-specific properties are preserved+ // and config properties are merged.+ expect(derivedConfig).toEqual(expect.objectContaining({+ use: { foo: 1, bar: 2 },+ grep: 'hi',+ build: { babelPlugins: [expect.anything()] },+ _plugins: [expect.anything()],+ }));+ `,+ 'a.test.ts': `+ import { test } from '@playwright/experimental-ct-react';+ test('pass', async ({}) => {});+ `+ });+ expect(result.exitCode).toBe(0);+});diff --git a/tests/playwright-test/types.spec.ts b/tests/playwright-test/types.spec.tsindex ffec4f889a..4e316cbeb8 100644--- a/tests/playwright-test/types.spec.ts+++ b/tests/playwright-test/types.spec.ts@@ -268,6 +268,26 @@ test('should check types of fixtures', async ({ runTSC }) => {},});`,+ 'playwright-define-merge.config.ts': `+ import { defineConfig } from '@playwright/test';+ const config0 = defineConfig({+ timeout: 1,+ // @ts-expect-error+ grep: 23,+ }, {+ timeout: 2,+ });+ `,+ 'playwright-define-merge-ct.config.ts': `+ import { defineConfig } from '@playwright/experimental-ct-vue';+ const config0 = defineConfig({+ timeout: 1,+ // @ts-expect-error+ grep: 23,+ }, {+ timeout: 2,+ });+ `,});expect(result.exitCode).toBe(0);});