| 
									
										
										
										
											2022-10-28 09:35:21 +02:00
										 |  |  | // @ts-check
 | 
					
						
							| 
									
										
										
										
											2024-11-25 15:55:18 +01:00
										 |  |  | const path = require('path'); | 
					
						
							| 
									
										
										
										
											2022-10-28 09:35:21 +02:00
										 |  |  | const { devices } = require('@playwright/test'); | 
					
						
							| 
									
										
										
										
											2024-03-01 12:31:17 +01:00
										 |  |  | const { parseType } = require('@strapi/utils'); | 
					
						
							| 
									
										
										
										
											2022-10-28 09:35:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-19 18:12:35 +01:00
										 |  |  | const getEnvNum = (envVar, defaultValue) => { | 
					
						
							|  |  |  |   if (envVar !== undefined && envVar !== null) { | 
					
						
							|  |  |  |     return Number(envVar); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return defaultValue; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-01 12:31:17 +01:00
										 |  |  | const getEnvString = (envVar, defaultValue) => { | 
					
						
							|  |  |  |   if (envVar?.trim().length) { | 
					
						
							|  |  |  |     return envVar; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return defaultValue; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const getEnvBool = (envVar, defaultValue) => { | 
					
						
							|  |  |  |   if (!envVar || envVar === '') { | 
					
						
							|  |  |  |     return defaultValue; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return parseType({ type: 'boolean', value: envVar.toLowerCase() }); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-13 11:37:46 +01:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @typedef ConfigOptions | 
					
						
							| 
									
										
										
										
											2025-04-07 03:28:49 -07:00
										 |  |  |  * @type {{ port: number; testDir: string; appDir: string; reportFileName: string }} | 
					
						
							| 
									
										
										
										
											2023-07-13 11:37:46 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-28 09:35:21 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @see https://playwright.dev/docs/test-configuration
 | 
					
						
							| 
									
										
										
										
											2023-07-13 11:37:46 +01:00
										 |  |  |  * @type {(options: ConfigOptions) => import('@playwright/test').PlaywrightTestConfig} | 
					
						
							| 
									
										
										
										
											2022-10-28 09:35:21 +02:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2025-04-07 03:28:49 -07:00
										 |  |  | const createConfig = ({ port, testDir, appDir, reportFileName }) => ({ | 
					
						
							| 
									
										
										
										
											2023-07-13 11:37:46 +01:00
										 |  |  |   testDir, | 
					
						
							| 
									
										
										
										
											2024-01-19 18:12:35 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-07 12:46:56 +01:00
										 |  |  |   /* default timeout for a jest test */ | 
					
						
							|  |  |  |   timeout: getEnvNum(process.env.PLAYWRIGHT_TIMEOUT, 90 * 1000), | 
					
						
							| 
									
										
										
										
											2024-01-19 18:12:35 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-28 09:35:21 +02:00
										 |  |  |   expect: { | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Maximum time expect() should wait for the condition to be met. | 
					
						
							|  |  |  |      * For example in `await expect(locator).toHaveText();` | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2024-11-07 12:46:56 +01:00
										 |  |  |     timeout: getEnvNum(process.env.PLAYWRIGHT_EXPECT_TIMEOUT, 10 * 1000), | 
					
						
							| 
									
										
										
										
											2022-10-28 09:35:21 +02:00
										 |  |  |   }, | 
					
						
							|  |  |  |   /* Run tests in files in parallel */ | 
					
						
							|  |  |  |   fullyParallel: false, | 
					
						
							|  |  |  |   /* Fail the build on CI if you accidentally left test.only in the source code. */ | 
					
						
							|  |  |  |   forbidOnly: !!process.env.CI, | 
					
						
							|  |  |  |   /* Retry on CI only */ | 
					
						
							| 
									
										
										
										
											2024-09-24 12:52:57 +02:00
										 |  |  |   retries: process.env.CI ? 3 : 1, | 
					
						
							| 
									
										
										
										
											2022-10-28 09:35:21 +02:00
										 |  |  |   /* Opt out of parallel tests on CI. */ | 
					
						
							|  |  |  |   workers: 1, | 
					
						
							|  |  |  |   /* Reporter to use. See https://playwright.dev/docs/test-reporters */ | 
					
						
							| 
									
										
										
										
											2024-11-25 15:55:18 +01:00
										 |  |  |   reporter: [ | 
					
						
							|  |  |  |     ['html'], | 
					
						
							|  |  |  |     // Junit reporter for Trunk flaky test CI upload
 | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |       'junit', | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         outputFile: path.join( | 
					
						
							| 
									
										
										
										
											2025-04-07 03:28:49 -07:00
										 |  |  |           getEnvString(process.env.PLAYWRIGHT_OUTPUT_DIR, '../../junit-reports/'), | 
					
						
							|  |  |  |           reportFileName | 
					
						
							| 
									
										
										
										
											2024-11-25 15:55:18 +01:00
										 |  |  |         ), | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     ], | 
					
						
							|  |  |  |   ], | 
					
						
							| 
									
										
										
										
											2022-10-28 09:35:21 +02:00
										 |  |  |   /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ | 
					
						
							|  |  |  |   use: { | 
					
						
							|  |  |  |     /* Base URL to use in actions like `await page.goto('/')`. */ | 
					
						
							| 
									
										
										
										
											2023-07-13 11:37:46 +01:00
										 |  |  |     baseURL: `http://127.0.0.1:${port}`, | 
					
						
							| 
									
										
										
										
											2024-01-19 18:12:35 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-28 14:41:10 +01:00
										 |  |  |     /** Set timezone for consistency across any machine*/ | 
					
						
							|  |  |  |     timezoneId: 'Europe/Paris', | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-07 12:46:56 +01:00
										 |  |  |     /* Default time each action such as `click()` can take */ | 
					
						
							|  |  |  |     actionTimeout: getEnvNum(process.env.PLAYWRIGHT_ACTION_TIMEOUT, 10 * 1000), | 
					
						
							| 
									
										
										
										
											2024-11-06 10:15:29 +01:00
										 |  |  |     // Only record trace when retrying a test to optimize test performance
 | 
					
						
							| 
									
										
										
										
											2025-01-15 09:19:30 +01:00
										 |  |  |     trace: process.env.CI ? 'on-first-retry' : 'retain-on-failure', | 
					
						
							| 
									
										
										
										
											2024-03-01 12:31:17 +01:00
										 |  |  |     video: getEnvBool(process.env.PLAYWRIGHT_VIDEO, false) | 
					
						
							|  |  |  |       ? { | 
					
						
							| 
									
										
										
										
											2024-11-06 10:15:29 +01:00
										 |  |  |           mode: 'on-first-retry', // Only save videos when retrying a test
 | 
					
						
							| 
									
										
										
										
											2024-03-01 12:31:17 +01:00
										 |  |  |           size: { | 
					
						
							|  |  |  |             width: 1280, | 
					
						
							|  |  |  |             height: 720, | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       : 'off', | 
					
						
							| 
									
										
										
										
											2022-10-28 09:35:21 +02:00
										 |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* Configure projects for major browsers */ | 
					
						
							|  |  |  |   projects: [ | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       name: 'chromium', | 
					
						
							|  |  |  |       use: { | 
					
						
							|  |  |  |         ...devices['Desktop Chrome'], | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       name: 'firefox', | 
					
						
							|  |  |  |       use: { | 
					
						
							|  |  |  |         ...devices['Desktop Firefox'], | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       name: 'webkit', | 
					
						
							|  |  |  |       use: { | 
					
						
							|  |  |  |         ...devices['Desktop Safari'], | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   ], | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-04 18:55:24 +02:00
										 |  |  |   /* Folder for test artifacts such as screenshots, videos, traces, etc. | 
					
						
							|  |  |  |    * Must be outside the project itself or develop mode will restart when files are written | 
					
						
							|  |  |  |    * */ | 
					
						
							|  |  |  |   outputDir: getEnvString(process.env.PLAYWRIGHT_OUTPUT_DIR, '../test-results/'), | 
					
						
							| 
									
										
										
										
											2022-10-28 09:35:21 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* Run your local dev server before starting the tests */ | 
					
						
							|  |  |  |   webServer: { | 
					
						
							| 
									
										
										
										
											2024-03-04 16:33:15 +00:00
										 |  |  |     command: `cd ${appDir} && npm run develop -- --no-watch-admin`, | 
					
						
							| 
									
										
										
										
											2023-07-13 11:37:46 +01:00
										 |  |  |     url: `http://127.0.0.1:${port}`, | 
					
						
							| 
									
										
										
										
											2024-01-19 18:12:35 +01:00
										 |  |  |     /* default Strapi server startup timeout to 160s */ | 
					
						
							|  |  |  |     timeout: getEnvNum(process.env.PLAYWRIGHT_WEBSERVER_TIMEOUT, 160 * 1000), | 
					
						
							| 
									
										
										
										
											2023-07-19 16:34:58 +01:00
										 |  |  |     reuseExistingServer: true, | 
					
						
							|  |  |  |     stdout: 'pipe', | 
					
						
							| 
									
										
										
										
											2022-10-28 09:35:21 +02:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2023-07-13 11:37:46 +01:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2022-10-28 09:35:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-13 11:37:46 +01:00
										 |  |  | module.exports = { createConfig }; |