| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  |  | /** | 
					
						
							|  |  |  |  |  * Copyright (c) Microsoft Corporation. | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * Licensed under the Apache License, Version 2.0 (the "License"); | 
					
						
							|  |  |  |  |  * you may not use this file except in compliance with the License. | 
					
						
							|  |  |  |  |  * You may obtain a copy of the License at | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * http://www.apache.org/licenses/LICENSE-2.0
 | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * Unless required by applicable law or agreed to in writing, software | 
					
						
							|  |  |  |  |  * distributed under the License is distributed on an "AS IS" BASIS, | 
					
						
							|  |  |  |  |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
					
						
							|  |  |  |  |  * See the License for the specific language governing permissions and | 
					
						
							|  |  |  |  |  * limitations under the License. | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | import * as fs from 'fs'; | 
					
						
							|  |  |  |  | import * as path from 'path'; | 
					
						
							|  |  |  |  | import { test, expect } from './playwright-test-fixtures'; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | test('should be able to define config', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |  |     'playwright.config.ts': `
 | 
					
						
							|  |  |  |  |       module.exports = { timeout: 12345 }; | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |     'a.test.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  |  |       test('pass', async ({}, testInfo) => { | 
					
						
							|  |  |  |  |         expect(testInfo.timeout).toBe(12345); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `
 | 
					
						
							|  |  |  |  |   }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |  |   expect(result.passed).toBe(1); | 
					
						
							|  |  |  |  | }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | test('should prioritize project timeout', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |  |     'playwright.config.ts': `
 | 
					
						
							|  |  |  |  |       module.exports = { timeout: 500, projects: [{ timeout: 10000}, {}] }; | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |     'a.test.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  |  |       test('pass', async ({}, testInfo) => { | 
					
						
							|  |  |  |  |         await new Promise(f => setTimeout(f, 1500)); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `
 | 
					
						
							|  |  |  |  |   }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   expect(result.exitCode).toBe(1); | 
					
						
							|  |  |  |  |   expect(result.passed).toBe(1); | 
					
						
							|  |  |  |  |   expect(result.failed).toBe(1); | 
					
						
							| 
									
										
										
										
											2022-06-30 17:05:08 -07:00
										 |  |  |  |   expect(result.output).toContain('Test timeout of 500ms exceeded.'); | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  |  | }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | test('should prioritize command line timeout over project timeout', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |  |     'playwright.config.ts': `
 | 
					
						
							|  |  |  |  |       module.exports = { projects: [{ timeout: 10000}] }; | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |     'a.test.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  |  |       test('pass', async ({}, testInfo) => { | 
					
						
							|  |  |  |  |         await new Promise(f => setTimeout(f, 1500)); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `
 | 
					
						
							|  |  |  |  |   }, { timeout: '500' }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   expect(result.exitCode).toBe(1); | 
					
						
							|  |  |  |  |   expect(result.failed).toBe(1); | 
					
						
							| 
									
										
										
										
											2022-06-30 17:05:08 -07:00
										 |  |  |  |   expect(result.output).toContain('Test timeout of 500ms exceeded.'); | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  |  | }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | test('should read config from --config, resolve relative testDir', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |  |     'my.config.ts': `
 | 
					
						
							|  |  |  |  |       import * as path from 'path'; | 
					
						
							|  |  |  |  |       module.exports = { | 
					
						
							|  |  |  |  |         testDir: 'dir', | 
					
						
							|  |  |  |  |       }; | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |     'a.test.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  |  |       test('ignored', async ({}) => { | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |     'dir/b.test.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  |  |       test('run', async ({}) => { | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |   }, { config: 'my.config.ts' }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |  |   expect(result.passed).toBe(1); | 
					
						
							|  |  |  |  |   expect(result.report.suites.length).toBe(1); | 
					
						
							|  |  |  |  |   expect(result.report.suites[0].file).toBe('b.test.ts'); | 
					
						
							|  |  |  |  | }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | test('should default testDir to the config file', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |  |     'dir/my.config.ts': `
 | 
					
						
							|  |  |  |  |       module.exports = {}; | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |     'a.test.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  |  |       test('ignored', async ({}) => { | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |     'dir/b.test.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  |  |       test('run', async ({}) => { | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |   }, { config: path.join('dir', 'my.config.ts') }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |  |   expect(result.passed).toBe(1); | 
					
						
							|  |  |  |  |   expect(result.report.suites.length).toBe(1); | 
					
						
							|  |  |  |  |   expect(result.report.suites[0].file).toBe('b.test.ts'); | 
					
						
							|  |  |  |  | }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | test('should be able to set reporters', async ({ runInlineTest }, testInfo) => { | 
					
						
							|  |  |  |  |   const reportFile = testInfo.outputPath('my-report.json'); | 
					
						
							|  |  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |  |     'playwright.config.ts': `
 | 
					
						
							|  |  |  |  |       module.exports = { | 
					
						
							|  |  |  |  |         reporter: [ | 
					
						
							|  |  |  |  |           ['json', { outputFile: ${JSON.stringify(reportFile)} }], | 
					
						
							|  |  |  |  |           ['list'], | 
					
						
							|  |  |  |  |         ] | 
					
						
							|  |  |  |  |       }; | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |     'a.test.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  |  |       test('pass', async () => { | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `
 | 
					
						
							|  |  |  |  |   }, { reporter: '' }); | 
					
						
							|  |  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |  |   expect(result.passed).toBe(1); | 
					
						
							|  |  |  |  |   const report = JSON.parse(fs.readFileSync(reportFile).toString()); | 
					
						
							|  |  |  |  |   expect(report.suites[0].file).toBe('a.test.ts'); | 
					
						
							|  |  |  |  | }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | test('should support different testDirs', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |  |     'playwright.config.ts': `
 | 
					
						
							|  |  |  |  |       import * as path from 'path'; | 
					
						
							|  |  |  |  |       module.exports = { projects: [ | 
					
						
							|  |  |  |  |         { testDir: __dirname }, | 
					
						
							|  |  |  |  |         { testDir: 'dir' }, | 
					
						
							|  |  |  |  |       ] }; | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |     'a.test.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  |  |       test('runs once', async ({}) => { | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |     'dir/b.test.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  |  |       test('runs twice', async ({}) => { | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |   }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |  |   expect(result.passed).toBe(3); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   expect(result.report.suites[0].specs[0].tests.length).toBe(1); | 
					
						
							|  |  |  |  |   expect(result.report.suites[0].specs[0].title).toBe('runs once'); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   expect(result.report.suites[1].specs[0].tests.length).toBe(2); | 
					
						
							|  |  |  |  |   expect(result.report.suites[1].specs[0].title).toBe('runs twice'); | 
					
						
							|  |  |  |  | }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | test('should allow root testDir and use it for relative paths', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |  |     'config/config.ts': `
 | 
					
						
							|  |  |  |  |       import * as path from 'path'; | 
					
						
							|  |  |  |  |       module.exports = { | 
					
						
							|  |  |  |  |         testDir: path.join(__dirname, '..'), | 
					
						
							|  |  |  |  |         projects: [{ testDir: path.join(__dirname, '..', 'dir') }] | 
					
						
							|  |  |  |  |       }; | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |     'a.test.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  |  |       test('fails', async ({}, testInfo) => { | 
					
						
							|  |  |  |  |         expect(1 + 1).toBe(3); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |     'dir/a.test.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  |  |       test('fails', async ({}, testInfo) => { | 
					
						
							|  |  |  |  |         expect(1 + 1).toBe(3); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |   }, { config: path.join('config', 'config.ts') }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   expect(result.exitCode).toBe(1); | 
					
						
							|  |  |  |  |   expect(result.passed).toBe(0); | 
					
						
							|  |  |  |  |   expect(result.skipped).toBe(0); | 
					
						
							|  |  |  |  |   expect(result.failed).toBe(1); | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |  |   expect(result.output).toContain(`1) ${path.join('dir', 'a.test.ts')}:3:11 › fails`); | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  |  | }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | test('should throw when test() is called in config file', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |  |     'playwright.config.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							|  |  |  |  |       test('hey', () => {}); | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  |  |       module.exports = {}; | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |     'a.test.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  |  |       test('test', async ({}) => { | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2022-02-18 18:25:18 -08:00
										 |  |  |  |   expect(result.output).toContain('Playwright Test did not expect test() to be called here'); | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  |  | }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | test('should filter by project, case-insensitive', async ({ runInlineTest }) => { | 
					
						
							| 
									
										
										
										
											2024-02-02 23:05:20 +01:00
										 |  |  |  |   const { passed, failed, outputLines, skipped } = await runInlineTest({ | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  |  |     'playwright.config.ts': `
 | 
					
						
							|  |  |  |  |       module.exports = { projects: [ | 
					
						
							|  |  |  |  |         { name: 'suite1' }, | 
					
						
							|  |  |  |  |         { name: 'suite2' }, | 
					
						
							|  |  |  |  |       ] }; | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |     'a.test.ts': `
 | 
					
						
							| 
									
										
										
										
											2024-02-02 23:05:20 +01:00
										 |  |  |  |       import { test } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  |  |       test('pass', async ({}, testInfo) => { | 
					
						
							| 
									
										
										
										
											2024-02-02 23:05:20 +01:00
										 |  |  |  |         console.log('%%' + test.info().project.name); | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  |  |       }); | 
					
						
							|  |  |  |  |     `
 | 
					
						
							|  |  |  |  |   }, { project: 'SUite2' }); | 
					
						
							|  |  |  |  |   expect(passed).toBe(1); | 
					
						
							|  |  |  |  |   expect(failed).toBe(0); | 
					
						
							|  |  |  |  |   expect(skipped).toBe(0); | 
					
						
							| 
									
										
										
										
											2024-02-02 23:05:20 +01:00
										 |  |  |  |   expect(new Set(outputLines)).toEqual(new Set([ | 
					
						
							|  |  |  |  |     'suite2', | 
					
						
							|  |  |  |  |   ])); | 
					
						
							|  |  |  |  | }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-16 19:18:00 -08:00
										 |  |  |  | test('should filter by project wildcard', async ({ runInlineTest }) => { | 
					
						
							| 
									
										
										
										
											2024-02-02 23:05:20 +01:00
										 |  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |  |     'playwright.config.js': `
 | 
					
						
							|  |  |  |  |       module.exports = { | 
					
						
							|  |  |  |  |         projects: [ | 
					
						
							| 
									
										
										
										
											2024-02-10 11:19:00 -08:00
										 |  |  |  |          { name: 'project-name' }, | 
					
						
							|  |  |  |  |          { name: 'foobar' } | 
					
						
							| 
									
										
										
										
											2024-02-02 23:05:20 +01:00
										 |  |  |  |         ] | 
					
						
							|  |  |  |  |       }; | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |     'a.test.js': `
 | 
					
						
							|  |  |  |  |       const { test } = require('@playwright/test'); | 
					
						
							|  |  |  |  |       test('one', async ({}) => { | 
					
						
							|  |  |  |  |         console.log('%%' + test.info().project.name); | 
					
						
							|  |  |  |  |       });    `
 | 
					
						
							| 
									
										
										
										
											2024-02-16 19:18:00 -08:00
										 |  |  |  |   }, { '--project': '*oj*t-Na*e' }); | 
					
						
							| 
									
										
										
										
											2024-02-02 23:05:20 +01:00
										 |  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |  |   expect(result.output).toContain('Running 1 test using 1 worker'); | 
					
						
							|  |  |  |  |   expect(new Set(result.outputLines)).toEqual(new Set([ | 
					
						
							|  |  |  |  |     'project-name', | 
					
						
							|  |  |  |  |   ])); | 
					
						
							|  |  |  |  | }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-16 19:18:00 -08:00
										 |  |  |  | test('should print nice error when the project wildcard does not match anything', async ({ runInlineTest }) => { | 
					
						
							| 
									
										
										
										
											2024-02-10 11:19:00 -08:00
										 |  |  |  |   const { output, exitCode } = await runInlineTest({ | 
					
						
							|  |  |  |  |     'playwright.config.ts': `
 | 
					
						
							|  |  |  |  |       module.exports = { projects: [ | 
					
						
							|  |  |  |  |         { name: 'suite1' }, | 
					
						
							|  |  |  |  |         { name: 'suite2' }, | 
					
						
							|  |  |  |  |       ] }; | 
					
						
							| 
									
										
										
										
											2024-02-02 23:05:20 +01:00
										 |  |  |  |     `,
 | 
					
						
							| 
									
										
										
										
											2024-02-10 11:19:00 -08:00
										 |  |  |  |     'a.test.ts': `
 | 
					
						
							|  |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							|  |  |  |  |       test('pass', async ({}, testInfo) => { | 
					
						
							|  |  |  |  |         console.log(testInfo.project.name); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `
 | 
					
						
							| 
									
										
										
										
											2024-02-16 19:18:00 -08:00
										 |  |  |  |   }, { '--project': ['not*found'] }); | 
					
						
							| 
									
										
										
										
											2024-02-10 11:19:00 -08:00
										 |  |  |  |   expect(exitCode).toBe(1); | 
					
						
							| 
									
										
										
										
											2024-02-16 19:18:00 -08:00
										 |  |  |  |   expect(output).toContain('Error: No projects matched. Available projects: "suite1", "suite2"'); | 
					
						
							| 
									
										
										
										
											2024-02-10 11:19:00 -08:00
										 |  |  |  | }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-16 19:18:00 -08:00
										 |  |  |  | test('should filter by project wildcard and exact name', async ({ runInlineTest }) => { | 
					
						
							| 
									
										
										
										
											2024-02-02 23:05:20 +01:00
										 |  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |  |     'playwright.config.js': `
 | 
					
						
							|  |  |  |  |       module.exports = { | 
					
						
							|  |  |  |  |         projects: [ | 
					
						
							| 
									
										
										
										
											2024-02-16 19:18:00 -08:00
										 |  |  |  |          { name: 'first' }, | 
					
						
							| 
									
										
										
										
											2024-02-02 23:05:20 +01:00
										 |  |  |  |          { name: 'fooBar' }, | 
					
						
							| 
									
										
										
										
											2024-02-16 19:18:00 -08:00
										 |  |  |  |          { name: 'foobarBaz' }, | 
					
						
							|  |  |  |  |          { name: 'prefix' }, | 
					
						
							|  |  |  |  |          { name: 'prefixEnd' }, | 
					
						
							| 
									
										
										
										
											2024-02-02 23:05:20 +01:00
										 |  |  |  |         ] | 
					
						
							|  |  |  |  |       }; | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |     'a.test.js': `
 | 
					
						
							|  |  |  |  |       const { test } = require('@playwright/test'); | 
					
						
							|  |  |  |  |       test('one', async ({}) => { | 
					
						
							|  |  |  |  |         console.log('%%' + test.info().project.name); | 
					
						
							|  |  |  |  |       });    `
 | 
					
						
							| 
									
										
										
										
											2024-02-16 19:18:00 -08:00
										 |  |  |  |   }, { '--project': ['first', '*bar', 'pref*x'] }); | 
					
						
							| 
									
										
										
										
											2024-02-02 23:05:20 +01:00
										 |  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							| 
									
										
										
										
											2024-02-16 19:18:00 -08:00
										 |  |  |  |   expect(new Set(result.outputLines)).toEqual(new Set(['first', 'fooBar', 'prefix'])); | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  |  | }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | test('should print nice error when project is unknown', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |  |   const { output, exitCode } = await runInlineTest({ | 
					
						
							|  |  |  |  |     'playwright.config.ts': `
 | 
					
						
							|  |  |  |  |       module.exports = { projects: [ | 
					
						
							|  |  |  |  |         { name: 'suite1' }, | 
					
						
							|  |  |  |  |         { name: 'suite2' }, | 
					
						
							|  |  |  |  |       ] }; | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |     'a.test.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2024-02-02 23:05:20 +01:00
										 |  |  |  |       test('pass', async ({}, testInfo) => {}); | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  |  |     `
 | 
					
						
							|  |  |  |  |   }, { project: 'suite3' }); | 
					
						
							|  |  |  |  |   expect(exitCode).toBe(1); | 
					
						
							| 
									
										
										
										
											2024-02-10 11:19:00 -08:00
										 |  |  |  |   expect(output).toContain('Project(s) "suite3" not found. Available projects: "suite1", "suite2"'); | 
					
						
							| 
									
										
										
										
											2021-09-02 09:29:55 -07:00
										 |  |  |  | }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | test('should filter by project list, case-insensitive', async ({ runInlineTest }) => { | 
					
						
							| 
									
										
										
										
											2024-02-02 23:05:20 +01:00
										 |  |  |  |   const { passed, failed, outputLines, skipped } = await runInlineTest({ | 
					
						
							| 
									
										
										
										
											2021-09-02 09:29:55 -07:00
										 |  |  |  |     'playwright.config.ts': `
 | 
					
						
							|  |  |  |  |       module.exports = { projects: [ | 
					
						
							|  |  |  |  |         { name: 'suite1' }, | 
					
						
							|  |  |  |  |         { name: 'suite2' }, | 
					
						
							|  |  |  |  |         { name: 'suite3' }, | 
					
						
							|  |  |  |  |         { name: 'suite4' }, | 
					
						
							|  |  |  |  |       ] }; | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |     'a.test.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-09-02 09:29:55 -07:00
										 |  |  |  |       test('pass', async ({}, testInfo) => { | 
					
						
							| 
									
										
										
										
											2024-02-02 23:05:20 +01:00
										 |  |  |  |         console.log('%%' + test.info().project.name); | 
					
						
							| 
									
										
										
										
											2021-09-02 09:29:55 -07:00
										 |  |  |  |       }); | 
					
						
							|  |  |  |  |     `
 | 
					
						
							|  |  |  |  |   }, { project: ['SUite2',  'Suite3'] }); | 
					
						
							|  |  |  |  |   expect(passed).toBe(2); | 
					
						
							|  |  |  |  |   expect(failed).toBe(0); | 
					
						
							|  |  |  |  |   expect(skipped).toBe(0); | 
					
						
							| 
									
										
										
										
											2024-02-02 23:05:20 +01:00
										 |  |  |  |   expect(new Set(outputLines)).toEqual(new Set(['suite3', 'suite2'])); | 
					
						
							| 
									
										
										
										
											2021-09-02 09:29:55 -07:00
										 |  |  |  | }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | test('should filter when duplicate project names exist', async ({ runInlineTest }) => { | 
					
						
							| 
									
										
										
										
											2024-02-02 23:05:20 +01:00
										 |  |  |  |   const { passed, failed, outputLines, skipped } = await runInlineTest({ | 
					
						
							| 
									
										
										
										
											2021-09-02 09:29:55 -07:00
										 |  |  |  |     'playwright.config.ts': `
 | 
					
						
							|  |  |  |  |       module.exports = { projects: [ | 
					
						
							|  |  |  |  |         { name: 'suite1' }, | 
					
						
							|  |  |  |  |         { name: 'suite2' }, | 
					
						
							|  |  |  |  |         { name: 'suite1' }, | 
					
						
							|  |  |  |  |         { name: 'suite4' }, | 
					
						
							|  |  |  |  |       ] }; | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |     'a.test.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-09-02 09:29:55 -07:00
										 |  |  |  |       test('pass', async ({}, testInfo) => { | 
					
						
							| 
									
										
										
										
											2024-02-02 23:05:20 +01:00
										 |  |  |  |         console.log('%%' + test.info().project.name); | 
					
						
							| 
									
										
										
										
											2021-09-02 09:29:55 -07:00
										 |  |  |  |       }); | 
					
						
							|  |  |  |  |     `
 | 
					
						
							|  |  |  |  |   }, { project: ['suite1',  'sUIte4'] }); | 
					
						
							|  |  |  |  |   expect(passed).toBe(3); | 
					
						
							|  |  |  |  |   expect(failed).toBe(0); | 
					
						
							|  |  |  |  |   expect(skipped).toBe(0); | 
					
						
							| 
									
										
										
										
											2024-02-02 23:05:20 +01:00
										 |  |  |  |   expect(new Set(outputLines)).toEqual(new Set(['suite1', 'suite1', 'suite4'])); | 
					
						
							| 
									
										
										
										
											2021-09-02 09:29:55 -07:00
										 |  |  |  | }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | test('should print nice error when some of the projects are unknown', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |  |   const { output, exitCode } = await runInlineTest({ | 
					
						
							|  |  |  |  |     'playwright.config.ts': `
 | 
					
						
							|  |  |  |  |       module.exports = { projects: [ | 
					
						
							|  |  |  |  |         { name: 'suite1' }, | 
					
						
							|  |  |  |  |         { name: 'suite2' }, | 
					
						
							|  |  |  |  |       ] }; | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |     'a.test.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-09-02 09:29:55 -07:00
										 |  |  |  |       test('pass', async ({}, testInfo) => { | 
					
						
							|  |  |  |  |         console.log(testInfo.project.name); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `
 | 
					
						
							|  |  |  |  |   }, { project: ['suitE1', 'suIte3', 'SUite4'] }); | 
					
						
							|  |  |  |  |   expect(exitCode).toBe(1); | 
					
						
							| 
									
										
										
										
											2024-02-10 11:19:00 -08:00
										 |  |  |  |   expect(output).toContain('Project(s) "suIte3", "SUite4" not found. Available projects: "suite1", "suite2"'); | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  |  | }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | test('should work without config file', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |  |   const { exitCode, passed, failed, skipped } = await runInlineTest({ | 
					
						
							|  |  |  |  |     'playwright.config.ts': `
 | 
					
						
							|  |  |  |  |       throw new Error('This file should not be required'); | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |     'dir/a.test.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  |  |       test('pass', async ({}) => { | 
					
						
							|  |  |  |  |         test.expect(1 + 1).toBe(2); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `
 | 
					
						
							|  |  |  |  |   }, { config: 'dir' }); | 
					
						
							|  |  |  |  |   expect(exitCode).toBe(0); | 
					
						
							|  |  |  |  |   expect(passed).toBe(1); | 
					
						
							|  |  |  |  |   expect(failed).toBe(0); | 
					
						
							|  |  |  |  |   expect(skipped).toBe(0); | 
					
						
							|  |  |  |  | }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-30 09:53:28 +01:00
										 |  |  |  | test('should inherit use options in projects', async ({ runInlineTest }) => { | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |  |     'playwright.config.ts': `
 | 
					
						
							|  |  |  |  |       module.exports = { | 
					
						
							|  |  |  |  |         use: { foo: 'config' }, | 
					
						
							|  |  |  |  |         projects: [{ | 
					
						
							|  |  |  |  |           use: { bar: 'project' }, | 
					
						
							|  |  |  |  |         }] | 
					
						
							|  |  |  |  |       }; | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |     'a.test.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |  |       import { test as base, expect } from '@playwright/test'; | 
					
						
							|  |  |  |  |       const test = base.extend({ foo: ['', {option:true}], bar: ['', {option: true}] }); | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  |  |       test('pass', async ({ foo, bar  }, testInfo) => { | 
					
						
							|  |  |  |  |         test.expect(foo).toBe('config'); | 
					
						
							|  |  |  |  |         test.expect(bar).toBe('project'); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `
 | 
					
						
							|  |  |  |  |   }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |  |   expect(result.passed).toBe(1); | 
					
						
							|  |  |  |  | }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-01 05:34:36 -07:00
										 |  |  |  | test('should support ignoreSnapshots config option', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |  |     'playwright.config.ts': `
 | 
					
						
							|  |  |  |  |       module.exports = { | 
					
						
							|  |  |  |  |         ignoreSnapshots: true, | 
					
						
							| 
									
										
										
										
											2024-04-22 16:16:38 -07:00
										 |  |  |  |         projects: [ | 
					
						
							|  |  |  |  |           { name: 'p1' }, | 
					
						
							|  |  |  |  |           { name: 'p2', ignoreSnapshots: false }, | 
					
						
							|  |  |  |  |         ] | 
					
						
							| 
									
										
										
										
											2022-09-01 05:34:36 -07:00
										 |  |  |  |       }; | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |     'a.test.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2022-09-01 05:34:36 -07:00
										 |  |  |  |       test('pass', async ({}, testInfo) => { | 
					
						
							| 
									
										
										
										
											2024-04-22 16:16:38 -07:00
										 |  |  |  |         testInfo.snapshotSuffix = ''; | 
					
						
							|  |  |  |  |         expect(testInfo.project.name).toMatchSnapshot(); | 
					
						
							| 
									
										
										
										
											2022-09-01 05:34:36 -07:00
										 |  |  |  |       }); | 
					
						
							|  |  |  |  |     `
 | 
					
						
							|  |  |  |  |   }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-22 16:16:38 -07:00
										 |  |  |  |   expect(result.exitCode).toBe(1); | 
					
						
							| 
									
										
										
										
											2022-09-01 05:34:36 -07:00
										 |  |  |  |   expect(result.passed).toBe(1); | 
					
						
							| 
									
										
										
										
											2024-04-22 16:16:38 -07:00
										 |  |  |  |   expect(result.failed).toBe(1); | 
					
						
							|  |  |  |  |   expect(result.output).not.toContain(`pass-1-p1.txt, writing actual.`); | 
					
						
							|  |  |  |  |   expect(result.output).toContain(`pass-1-p2.txt, writing actual.`); | 
					
						
							| 
									
										
										
										
											2022-09-01 05:34:36 -07:00
										 |  |  |  | }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-21 20:17:36 +02:00
										 |  |  |  | test('should validate workers option set to percent', async ({ runInlineTest }, testInfo) => { | 
					
						
							|  |  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |  |     'playwright.config.ts': `
 | 
					
						
							|  |  |  |  |       module.exports = { | 
					
						
							|  |  |  |  |         workers: '50%' | 
					
						
							|  |  |  |  |       }; | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |     'a.test.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2022-09-21 20:17:36 +02:00
										 |  |  |  |       test('pass', async () => { | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `
 | 
					
						
							|  |  |  |  |   }); | 
					
						
							|  |  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |  |   expect(result.passed).toBe(1); | 
					
						
							|  |  |  |  | }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | test('should throw when workers option is invalid', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |  |     'playwright.config.ts': `
 | 
					
						
							|  |  |  |  |         module.exports = { | 
					
						
							|  |  |  |  |           workers: '' | 
					
						
							|  |  |  |  |         }; | 
					
						
							|  |  |  |  |       `,
 | 
					
						
							|  |  |  |  |     'a.test.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |  |         import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2022-09-21 20:17:36 +02:00
										 |  |  |  |         test('pass', async () => { | 
					
						
							|  |  |  |  |         }); | 
					
						
							|  |  |  |  |       `
 | 
					
						
							|  |  |  |  |   }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   expect(result.exitCode).toBe(1); | 
					
						
							|  |  |  |  |   expect(result.output).toContain('config.workers must be a number or percentage'); | 
					
						
							|  |  |  |  | }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  |  | test('should work with undefined values and base', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |  |     'playwright.config.ts': `
 | 
					
						
							|  |  |  |  |       module.exports = { | 
					
						
							|  |  |  |  |         updateSnapshots: undefined, | 
					
						
							|  |  |  |  |       }; | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |     'a.test.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  |  |       test('pass', async ({}, testInfo) => { | 
					
						
							| 
									
										
										
										
											2021-06-16 07:51:54 -07:00
										 |  |  |  |         expect(testInfo.config.updateSnapshots).toBe('missing'); | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  |  |       }); | 
					
						
							|  |  |  |  |     `
 | 
					
						
							| 
									
										
										
										
											2022-02-24 12:39:28 -08:00
										 |  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |  |   expect(result.passed).toBe(1); | 
					
						
							|  |  |  |  | }); | 
					
						
							| 
									
										
										
										
											2022-07-25 10:39:06 +02:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | test('should have correct types for the config', async ({ runTSC }) => { | 
					
						
							|  |  |  |  |   const result = await runTSC({ | 
					
						
							|  |  |  |  |     'playwright.config.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-01-12 13:12:02 -08:00
										 |  |  |  |       import { defineConfig } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2022-07-25 10:39:06 +02:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-12 13:12:02 -08:00
										 |  |  |  |       export default defineConfig({ | 
					
						
							| 
									
										
										
										
											2022-07-25 10:39:06 +02:00
										 |  |  |  |         webServer: [ | 
					
						
							|  |  |  |  |           { | 
					
						
							|  |  |  |  |             command: 'echo 123', | 
					
						
							|  |  |  |  |             env: { PORT: '123' }, | 
					
						
							|  |  |  |  |             port: 123, | 
					
						
							|  |  |  |  |           }, | 
					
						
							|  |  |  |  |           { | 
					
						
							|  |  |  |  |             command: 'echo 123', | 
					
						
							|  |  |  |  |             env: { NODE_ENV: 'test' }, | 
					
						
							|  |  |  |  |             port: 8082, | 
					
						
							|  |  |  |  |           }, | 
					
						
							|  |  |  |  |         ], | 
					
						
							| 
									
										
										
										
											2022-08-01 09:01:23 -07:00
										 |  |  |  |         globalSetup: './globalSetup', | 
					
						
							|  |  |  |  |         // @ts-expect-error
 | 
					
						
							|  |  |  |  |         globalTeardown: null, | 
					
						
							|  |  |  |  |         projects: [ | 
					
						
							|  |  |  |  |           { | 
					
						
							|  |  |  |  |             name: 'project name', | 
					
						
							|  |  |  |  |           } | 
					
						
							|  |  |  |  |         ], | 
					
						
							| 
									
										
										
										
											2023-01-12 13:12:02 -08:00
										 |  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2022-07-25 10:39:06 +02:00
										 |  |  |  |   `
 | 
					
						
							|  |  |  |  |   }); | 
					
						
							|  |  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |  | }); | 
					
						
							| 
									
										
										
										
											2023-07-06 13:31:44 -07:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | test('should not allow tracesDir in launchOptions', async ({ runTSC }) => { | 
					
						
							|  |  |  |  |   const result = await runTSC({ | 
					
						
							|  |  |  |  |     'playwright.config.ts': `
 | 
					
						
							|  |  |  |  |       import { defineConfig } from '@playwright/test'; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       export default defineConfig({ | 
					
						
							|  |  |  |  |         use: { | 
					
						
							|  |  |  |  |           launchOptions: { | 
					
						
							|  |  |  |  |             tracesDir: 'foo', | 
					
						
							|  |  |  |  |           }, | 
					
						
							|  |  |  |  |         }, | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |   `
 | 
					
						
							|  |  |  |  |   }); | 
					
						
							|  |  |  |  |   expect(result.exitCode).not.toBe(0); | 
					
						
							|  |  |  |  | }); | 
					
						
							| 
									
										
										
										
											2023-08-09 17:23:34 -07:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | test('should merge configs', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |  |     'playwright.config.ts': `
 | 
					
						
							|  |  |  |  |       import { defineConfig, expect } from '@playwright/test'; | 
					
						
							|  |  |  |  |       const baseConfig = defineConfig({ | 
					
						
							|  |  |  |  |         timeout: 10, | 
					
						
							|  |  |  |  |         use: { | 
					
						
							|  |  |  |  |           foo: 1, | 
					
						
							|  |  |  |  |         }, | 
					
						
							|  |  |  |  |         expect: { | 
					
						
							|  |  |  |  |           timeout: 11, | 
					
						
							|  |  |  |  |         }, | 
					
						
							|  |  |  |  |         projects: [ | 
					
						
							|  |  |  |  |           { | 
					
						
							|  |  |  |  |             name: 'A', | 
					
						
							|  |  |  |  |             timeout: 20, | 
					
						
							|  |  |  |  |           } | 
					
						
							|  |  |  |  |         ], | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |       const derivedConfig = defineConfig(baseConfig, { | 
					
						
							|  |  |  |  |         timeout: 30, | 
					
						
							|  |  |  |  |         use: { | 
					
						
							|  |  |  |  |           bar: 2, | 
					
						
							|  |  |  |  |         }, | 
					
						
							|  |  |  |  |         expect: { | 
					
						
							|  |  |  |  |           timeout: 12, | 
					
						
							|  |  |  |  |         }, | 
					
						
							|  |  |  |  |         projects: [ | 
					
						
							|  |  |  |  |           { name: 'B', timeout: 40 }, | 
					
						
							|  |  |  |  |           { name: 'A', timeout: 50 }, | 
					
						
							|  |  |  |  |         ], | 
					
						
							|  |  |  |  |         webServer: { | 
					
						
							|  |  |  |  |           command: 'echo 123', | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       expect(derivedConfig).toEqual(expect.objectContaining({ | 
					
						
							|  |  |  |  |         timeout: 30, | 
					
						
							|  |  |  |  |         use: { foo: 1, bar: 2 }, | 
					
						
							|  |  |  |  |         expect: { timeout: 12 }, | 
					
						
							|  |  |  |  |         projects: [ | 
					
						
							|  |  |  |  |           { name: 'B', timeout: 40, use: {} }, | 
					
						
							|  |  |  |  |           { name: 'A', timeout: 50, use: {} } | 
					
						
							|  |  |  |  |         ], | 
					
						
							|  |  |  |  |         webServer: [{ | 
					
						
							|  |  |  |  |           command: 'echo 123', | 
					
						
							|  |  |  |  |         }] | 
					
						
							|  |  |  |  |       })); | 
					
						
							| 
									
										
										
										
											2023-11-17 13:36:50 -08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |       // Should not add an empty project list.
 | 
					
						
							|  |  |  |  |       expect(defineConfig({}, {}).projects).toBeUndefined(); | 
					
						
							| 
									
										
										
										
											2023-08-09 17:23:34 -07:00
										 |  |  |  |     `,
 | 
					
						
							|  |  |  |  |     'a.test.ts': `
 | 
					
						
							|  |  |  |  |       import { test } from '@playwright/test'; | 
					
						
							|  |  |  |  |       test('pass', async ({}) => {}); | 
					
						
							|  |  |  |  |     `
 | 
					
						
							|  |  |  |  |   }); | 
					
						
							|  |  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |  | }); | 
					
						
							| 
									
										
										
										
											2023-12-12 14:01:01 -08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 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', | 
					
						
							| 
									
										
										
										
											2024-02-13 09:34:03 -08:00
										 |  |  |  |         '@playwright/test': expect.objectContaining({ | 
					
						
							| 
									
										
										
										
											2024-04-22 16:16:38 -07:00
										 |  |  |  |           babelPlugins: [[expect.stringContaining('tsxTransform.js')]] | 
					
						
							| 
									
										
										
										
											2024-02-13 09:34:03 -08:00
										 |  |  |  |         }), | 
					
						
							|  |  |  |  |         '@playwright/experimental-ct-core': expect.objectContaining({ | 
					
						
							|  |  |  |  |           registerSourceFile: expect.stringContaining('registerSource'), | 
					
						
							|  |  |  |  |         }), | 
					
						
							| 
									
										
										
										
											2023-12-12 14:01:01 -08:00
										 |  |  |  |       })); | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |     'a.test.ts': `
 | 
					
						
							|  |  |  |  |       import { test } from '@playwright/experimental-ct-react'; | 
					
						
							|  |  |  |  |       test('pass', async ({}) => {}); | 
					
						
							|  |  |  |  |     `
 | 
					
						
							|  |  |  |  |   }); | 
					
						
							|  |  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |  | }); |