2023-11-27 18:48:37 +03:00
|
|
|
/** @file Playwright browser testing configuration. */
|
|
|
|
/** Note that running Playwright in CI poses a number of issues:
|
|
|
|
* - `backdrop-filter: blur` is disabled, due to issues with Chromium's `--disable-gpu` flag
|
|
|
|
* (see below).
|
|
|
|
* - System validation dialogs are not reliable between computers, as they may have different
|
|
|
|
* default fonts. */
|
|
|
|
import { defineConfig } from '@playwright/test'
|
2024-01-18 16:13:31 +03:00
|
|
|
import net from 'net'
|
2023-09-05 01:27:33 +03:00
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
const DEBUG = process.env.DEBUG_E2E === 'true'
|
2023-09-05 01:27:33 +03:00
|
|
|
|
2024-01-18 16:13:31 +03:00
|
|
|
async function findFreePortInRange(min: number, max: number) {
|
|
|
|
for (let i = 0; i < 50; i++) {
|
|
|
|
const portToCheck = Math.floor(Math.random() * (max - min + 1)) + min
|
|
|
|
if (await checkAvailablePort(portToCheck)) return portToCheck
|
|
|
|
}
|
|
|
|
throw new Error('Failed to find a free port.')
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkAvailablePort(port: number) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const server = net.createServer()
|
|
|
|
server
|
|
|
|
.unref()
|
|
|
|
.on('error', (e: any) => ('EADDRINUSE' === e.code ? resolve(false) : reject(e)))
|
|
|
|
.listen({ host: '0.0.0.0', port }, () => server.close(() => resolve(true)))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const portFromEnv = parseInt(process.env.PLAYWRIGHT_PORT ?? '', 10)
|
|
|
|
const PORT = Number.isFinite(portFromEnv) ? portFromEnv : await findFreePortInRange(4300, 4999)
|
|
|
|
// Make sure to set the env to actual port that is being used. This is necessary for workers to
|
|
|
|
// pick up the same configuration.
|
|
|
|
process.env.PLAYWRIGHT_PORT = `${PORT}`
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
export default defineConfig({
|
|
|
|
globalSetup: './e2e/setup.ts',
|
2023-09-05 01:27:33 +03:00
|
|
|
testDir: './e2e',
|
|
|
|
forbidOnly: !!process.env.CI,
|
2024-02-13 14:43:56 +03:00
|
|
|
repeatEach: process.env.CI ? 3 : 1,
|
2023-11-27 18:48:37 +03:00
|
|
|
...(process.env.CI ? { workers: 1 } : {}),
|
2024-03-05 10:06:11 +03:00
|
|
|
timeout: 60000,
|
2023-11-27 18:48:37 +03:00
|
|
|
expect: {
|
|
|
|
timeout: 5000,
|
|
|
|
toHaveScreenshot: { threshold: 0 },
|
|
|
|
},
|
2024-03-05 10:06:11 +03:00
|
|
|
reporter: 'html',
|
2023-09-05 01:27:33 +03:00
|
|
|
use: {
|
2023-11-27 18:48:37 +03:00
|
|
|
headless: !DEBUG,
|
2024-07-12 13:45:57 +03:00
|
|
|
actionTimeout: 5000,
|
2024-03-05 10:06:11 +03:00
|
|
|
trace: 'retain-on-failure',
|
2024-04-24 14:40:42 +03:00
|
|
|
viewport: { width: 1920, height: 1750 },
|
2024-03-06 18:34:07 +03:00
|
|
|
...(DEBUG ?
|
|
|
|
{}
|
|
|
|
: {
|
|
|
|
launchOptions: {
|
|
|
|
ignoreDefaultArgs: ['--headless'],
|
|
|
|
args: [
|
|
|
|
// Much closer to headful Chromium than classic headless.
|
|
|
|
'--headless=new',
|
|
|
|
// Required for `backdrop-filter: blur` to work.
|
|
|
|
'--use-angle=swiftshader',
|
|
|
|
// FIXME: `--disable-gpu` disables `backdrop-filter: blur`, which is not handled by
|
|
|
|
// the software (CPU) compositor. This SHOULD be fixed eventually, but this flag
|
|
|
|
// MUST stay as CI does not have a GPU.
|
|
|
|
'--disable-gpu',
|
|
|
|
// Fully disable GPU process.
|
|
|
|
'--disable-software-rasterizer',
|
|
|
|
// Disable text subpixel antialiasing.
|
|
|
|
'--font-render-hinting=none',
|
|
|
|
'--disable-skia-runtime-opts',
|
|
|
|
'--disable-system-font-check',
|
|
|
|
'--disable-font-subpixel-positioning',
|
|
|
|
'--disable-lcd-text',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
}),
|
2023-09-05 01:27:33 +03:00
|
|
|
},
|
2023-11-27 18:48:37 +03:00
|
|
|
// projects: [
|
|
|
|
// {
|
|
|
|
// name: 'chromium',
|
|
|
|
// use: {
|
|
|
|
// ...devices['Desktop Chrome'],
|
|
|
|
// },
|
|
|
|
// },
|
|
|
|
// {
|
|
|
|
// name: 'firefox',
|
|
|
|
// use: {
|
|
|
|
// ...devices['Desktop Firefox'],
|
|
|
|
// },
|
|
|
|
// },
|
|
|
|
// {
|
|
|
|
// name: 'webkit',
|
|
|
|
// use: {
|
|
|
|
// ...devices['Desktop Safari'],
|
|
|
|
// },
|
|
|
|
// },
|
|
|
|
// {
|
|
|
|
// name: 'Mobile Chrome',
|
|
|
|
// use: {
|
|
|
|
// ...devices['Pixel 5'],
|
|
|
|
// },
|
|
|
|
// },
|
|
|
|
// {
|
|
|
|
// name: 'Mobile Safari',
|
|
|
|
// use: {
|
|
|
|
// ...devices['iPhone 12'],
|
|
|
|
// },
|
|
|
|
// },
|
|
|
|
// ],
|
2023-09-05 01:27:33 +03:00
|
|
|
webServer: {
|
2023-12-22 13:59:57 +03:00
|
|
|
env: {
|
|
|
|
E2E: 'true',
|
|
|
|
},
|
2024-02-05 17:20:24 +03:00
|
|
|
command:
|
2024-03-06 18:34:07 +03:00
|
|
|
process.env.CI || process.env.PROD ?
|
|
|
|
`npx vite build && npx vite preview --port ${PORT} --strictPort`
|
|
|
|
: `npx vite dev --port ${PORT}`,
|
2024-01-18 16:13:31 +03:00
|
|
|
// Build from scratch apparently can take a while on CI machines.
|
|
|
|
timeout: 120 * 1000,
|
|
|
|
port: PORT,
|
2023-12-12 17:27:40 +03:00
|
|
|
// We use our special, mocked version of server, thus do not want to re-use user's one.
|
|
|
|
reuseExistingServer: false,
|
2023-09-05 01:27:33 +03:00
|
|
|
},
|
2023-11-27 18:48:37 +03:00
|
|
|
})
|