| 
									
										
										
										
											2021-04-01 16:35:26 -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. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-11 15:12:25 -08:00
										 |  |  | import { config as loadEnv } from 'dotenv'; | 
					
						
							| 
									
										
										
										
											2023-08-08 18:46:32 -07:00
										 |  |  | loadEnv({ path: path.join(__dirname, '..', '..', '.env'), override: true }); | 
					
						
							| 
									
										
										
										
											2022-03-11 15:12:25 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-09 17:23:34 -07:00
										 |  |  | import { type Config, type PlaywrightTestOptions, type PlaywrightWorkerOptions, type ReporterDescription } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-04-01 16:35:26 -07:00
										 |  |  | import * as path from 'path'; | 
					
						
							| 
									
										
										
										
											2022-04-06 13:57:14 -08:00
										 |  |  | import type { TestModeWorkerOptions } from '../config/testModeFixtures'; | 
					
						
							| 
									
										
										
										
											2022-09-14 15:05:18 -07:00
										 |  |  | import type { TestModeName } from '../config/testMode'; | 
					
						
							| 
									
										
										
										
											2022-04-06 13:57:14 -08:00
										 |  |  | import type { CoverageWorkerOptions } from '../config/coverageFixtures'; | 
					
						
							| 
									
										
										
										
											2021-10-27 07:28:53 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | type BrowserName = 'chromium' | 'firefox' | 'webkit'; | 
					
						
							| 
									
										
										
										
											2021-04-01 16:35:26 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | const getExecutablePath = (browserName: BrowserName) => { | 
					
						
							|  |  |  |   if (browserName === 'chromium' && process.env.CRPATH) | 
					
						
							|  |  |  |     return process.env.CRPATH; | 
					
						
							|  |  |  |   if (browserName === 'firefox' && process.env.FFPATH) | 
					
						
							|  |  |  |     return process.env.FFPATH; | 
					
						
							|  |  |  |   if (browserName === 'webkit' && process.env.WKPATH) | 
					
						
							|  |  |  |     return process.env.WKPATH; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-25 16:47:04 -07:00
										 |  |  | const mode = (process.env.PWTEST_MODE ?? 'default') as TestModeName; | 
					
						
							| 
									
										
										
										
											2022-05-10 10:03:47 -06:00
										 |  |  | const headed = process.argv.includes('--headed'); | 
					
						
							| 
									
										
										
										
											2021-05-28 17:03:18 -07:00
										 |  |  | const channel = process.env.PWTEST_CHANNEL as any; | 
					
						
							|  |  |  | const video = !!process.env.PWTEST_VIDEO; | 
					
						
							| 
									
										
										
										
											2021-08-19 19:09:19 -07:00
										 |  |  | const trace = !!process.env.PWTEST_TRACE; | 
					
						
							| 
									
										
										
										
											2021-05-11 06:40:06 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-07 15:25:55 -07:00
										 |  |  | const outputDir = path.join(__dirname, '..', '..', 'test-results'); | 
					
						
							|  |  |  | const testDir = path.join(__dirname, '..'); | 
					
						
							| 
									
										
										
										
											2023-05-17 09:10:31 -07:00
										 |  |  | const reporters = () => { | 
					
						
							|  |  |  |   const result: ReporterDescription[] = process.env.CI ? [ | 
					
						
							|  |  |  |     ['dot'], | 
					
						
							|  |  |  |     ['json', { outputFile: path.join(outputDir, 'report.json') }], | 
					
						
							| 
									
										
										
										
											2023-07-28 15:49:31 -07:00
										 |  |  |     ['blob'], | 
					
						
							| 
									
										
										
										
											2023-05-17 09:10:31 -07:00
										 |  |  |   ] : [ | 
					
						
							|  |  |  |     ['html', { open: 'on-failure' }] | 
					
						
							|  |  |  |   ]; | 
					
						
							|  |  |  |   return result; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2023-07-25 16:47:04 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-26 14:32:48 -07:00
										 |  |  | const os: 'linux' | 'windows' = (process.env.PLAYWRIGHT_SERVICE_OS as 'linux' | 'windows') || 'linux'; | 
					
						
							| 
									
										
										
										
											2023-07-26 18:36:33 -07:00
										 |  |  | const runId = process.env.PLAYWRIGHT_SERVICE_RUN_ID || new Date().toISOString(); // name the test run
 | 
					
						
							| 
									
										
										
										
											2023-07-25 16:47:04 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | let connectOptions: any; | 
					
						
							| 
									
										
										
										
											2023-08-04 08:38:07 -07:00
										 |  |  | let webServer: any; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if (mode === 'service') { | 
					
						
							| 
									
										
										
										
											2023-07-25 16:47:04 -07:00
										 |  |  |   connectOptions = { wsEndpoint: 'ws://localhost:3333/' }; | 
					
						
							| 
									
										
										
										
											2023-08-04 08:38:07 -07:00
										 |  |  |   webServer = { | 
					
						
							|  |  |  |     command: 'npx playwright run-server --port=3333', | 
					
						
							|  |  |  |     url: 'http://localhost:3333', | 
					
						
							|  |  |  |     reuseExistingServer: !process.env.CI, | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2023-07-25 16:47:04 -07:00
										 |  |  | if (mode === 'service2') { | 
					
						
							| 
									
										
										
										
											2023-07-31 11:24:04 -07:00
										 |  |  |   process.env.PW_VERSION_OVERRIDE = '1.37'; | 
					
						
							| 
									
										
										
										
											2023-07-25 16:47:04 -07:00
										 |  |  |   connectOptions = { | 
					
						
							| 
									
										
										
										
											2023-08-10 13:43:16 -07:00
										 |  |  |     wsEndpoint: `${process.env.PLAYWRIGHT_SERVICE_URL}?cap=${JSON.stringify({ os, runId })}`, | 
					
						
							| 
									
										
										
										
											2023-07-25 16:47:04 -07:00
										 |  |  |     timeout: 3 * 60 * 1000, | 
					
						
							| 
									
										
										
										
											2023-07-26 17:29:31 -07:00
										 |  |  |     exposeNetwork: '<loopback>', | 
					
						
							| 
									
										
										
										
											2023-08-10 13:43:16 -07:00
										 |  |  |     headers: { | 
					
						
							|  |  |  |       'x-mpt-access-key': process.env.PLAYWRIGHT_SERVICE_ACCESS_KEY! | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-07-25 16:47:04 -07:00
										 |  |  |   }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												feat(test runner): replace declare/define with "options" (#10293)
1. Fixtures defined in test.extend() can now have `{ option: true }` configuration that makes them overridable in the config. Options support all other properties of fixtures - value/function, scope, auto.
```
const test = base.extend<MyOptions>({
  foo: ['default', { option: true }],
});
```
2. test.declare() and project.define are removed.
3. project.use applies overrides to default option values and nothing else. Any test.extend() and test.use() calls take priority over config options.
Required user changes: if someone used to define fixture options with test.extend(), overriding them in config will stop working. The solution is to add `{ option: true }`.
```
// Old code
export const test = base.extend<{ myOption: number, myFixture: number }>({
  myOption: 123,
  myFixture: ({ myOption }, use) => use(2 * myOption),
});
// New code
export const test = base.extend<{ myOption: number, myFixture: number }>({
  myOption: [123, { option: true }],
  myFixture: ({ myOption }, use) => use(2 * myOption),
});
```
											
										 
											2021-11-18 15:45:52 -08:00
										 |  |  | const config: Config<CoverageWorkerOptions & PlaywrightWorkerOptions & PlaywrightTestOptions & TestModeWorkerOptions> = { | 
					
						
							| 
									
										
										
										
											2021-05-07 15:25:55 -07:00
										 |  |  |   testDir, | 
					
						
							|  |  |  |   outputDir, | 
					
						
							| 
									
										
										
										
											2021-11-17 11:56:24 -08:00
										 |  |  |   expect: { | 
					
						
							|  |  |  |     timeout: 10000, | 
					
						
							| 
									
										
										
										
											2023-02-13 11:11:44 -08:00
										 |  |  |     toHaveScreenshot: { _comparator: 'ssim-cie94' } as any, | 
					
						
							|  |  |  |     toMatchSnapshot: { _comparator: 'ssim-cie94' } as any, | 
					
						
							| 
									
										
										
										
											2021-11-17 11:56:24 -08:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2023-07-25 16:47:04 -07:00
										 |  |  |   maxFailures: 200, | 
					
						
							| 
									
										
										
										
											2021-08-19 19:09:19 -07:00
										 |  |  |   timeout: video ? 60000 : 30000, | 
					
						
							| 
									
										
										
										
											2021-05-07 15:25:55 -07:00
										 |  |  |   globalTimeout: 5400000, | 
					
						
							| 
									
										
										
										
											2022-06-23 15:55:12 -07:00
										 |  |  |   workers: process.env.CI ? 2 : undefined, | 
					
						
							| 
									
										
										
										
											2022-03-01 18:12:21 -08:00
										 |  |  |   fullyParallel: !process.env.CI, | 
					
						
							| 
									
										
										
										
											2021-05-07 15:25:55 -07:00
										 |  |  |   forbidOnly: !!process.env.CI, | 
					
						
							|  |  |  |   retries: process.env.CI ? 3 : 0, | 
					
						
							| 
									
										
										
										
											2023-05-17 09:10:31 -07:00
										 |  |  |   reporter: reporters(), | 
					
						
							| 
									
										
										
										
											2021-05-07 15:25:55 -07:00
										 |  |  |   projects: [], | 
					
						
							| 
									
										
										
										
											2022-12-13 16:03:53 -08:00
										 |  |  |   use: { | 
					
						
							| 
									
										
										
										
											2023-07-25 16:47:04 -07:00
										 |  |  |     connectOptions, | 
					
						
							| 
									
										
										
										
											2022-12-13 16:03:53 -08:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2023-08-04 08:38:07 -07:00
										 |  |  |   webServer, | 
					
						
							| 
									
										
										
										
											2022-02-10 16:36:23 -08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-08 17:45:04 -07:00
										 |  |  | const browserNames = ['chromium', 'webkit', 'firefox'] as BrowserName[]; | 
					
						
							|  |  |  | for (const browserName of browserNames) { | 
					
						
							| 
									
										
										
										
											2021-04-01 16:35:26 -07:00
										 |  |  |   const executablePath = getExecutablePath(browserName); | 
					
						
							| 
									
										
										
										
											2021-06-04 18:43:54 -07:00
										 |  |  |   if (executablePath && !process.env.TEST_WORKER_INDEX) | 
					
						
							| 
									
										
										
										
											2021-04-05 09:19:39 -07:00
										 |  |  |     console.error(`Using executable at ${executablePath}`); | 
					
						
							| 
									
										
										
										
											2021-10-26 12:45:53 -08:00
										 |  |  |   const devtools = process.env.DEVTOOLS === '1'; | 
					
						
							| 
									
										
										
										
											2021-05-08 17:45:04 -07:00
										 |  |  |   const testIgnore: RegExp[] = browserNames.filter(b => b !== browserName).map(b => new RegExp(b)); | 
					
						
							| 
									
										
										
										
											2022-03-25 22:09:02 -08:00
										 |  |  |   for (const folder of ['library', 'page']) { | 
					
						
							|  |  |  |     config.projects.push({ | 
					
						
							|  |  |  |       name: browserName, | 
					
						
							|  |  |  |       testDir: path.join(testDir, folder), | 
					
						
							|  |  |  |       testIgnore, | 
					
						
							| 
									
										
										
										
											2022-11-10 17:23:57 -08:00
										 |  |  |       snapshotPathTemplate: '{testDir}/{testFileDir}/{testFileName}-snapshots/{arg}{-projectName}{ext}', | 
					
						
							| 
									
										
										
										
											2022-03-25 22:09:02 -08:00
										 |  |  |       use: { | 
					
						
							|  |  |  |         mode, | 
					
						
							|  |  |  |         browserName, | 
					
						
							|  |  |  |         headless: !headed, | 
					
						
							|  |  |  |         channel, | 
					
						
							|  |  |  |         video: video ? 'on' : undefined, | 
					
						
							|  |  |  |         launchOptions: { | 
					
						
							|  |  |  |           executablePath, | 
					
						
							|  |  |  |           devtools | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         trace: trace ? 'on' : undefined, | 
					
						
							|  |  |  |         coverageName: browserName, | 
					
						
							| 
									
										
										
										
											2021-10-26 12:45:53 -08:00
										 |  |  |       }, | 
					
						
							| 
									
										
										
										
											2022-03-25 22:09:02 -08:00
										 |  |  |       metadata: { | 
					
						
							|  |  |  |         platform: process.platform, | 
					
						
							|  |  |  |         docker: !!process.env.INSIDE_DOCKER, | 
					
						
							|  |  |  |         headful: !!headed, | 
					
						
							|  |  |  |         browserName, | 
					
						
							|  |  |  |         channel, | 
					
						
							|  |  |  |         mode, | 
					
						
							|  |  |  |         video: !!video, | 
					
						
							|  |  |  |         trace: !!trace, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-04-01 16:35:26 -07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2021-05-07 15:25:55 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | export default config; |