2024-10-11 21:23:02 +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'
|
|
|
|
import net from 'net'
|
2024-11-28 00:20:36 +03:00
|
|
|
import path from 'path'
|
2024-10-11 21:23:02 +03:00
|
|
|
|
2024-11-27 17:09:59 +03:00
|
|
|
const DEBUG = process.env.DEBUG_TEST === 'true'
|
2024-11-15 15:12:55 +03:00
|
|
|
const isCI = process.env.CI === 'true'
|
|
|
|
const isProd = process.env.PROD === 'true'
|
|
|
|
|
|
|
|
const TIMEOUT_MS =
|
|
|
|
DEBUG ? 100_000_000
|
2024-11-22 19:07:34 +03:00
|
|
|
: isCI ? 25_000
|
2024-11-15 15:12:55 +03:00
|
|
|
: 15_000
|
|
|
|
|
|
|
|
// We tend to use less CPU on CI to reduce the number of failures due to timeouts.
|
2024-11-21 13:52:20 +03:00
|
|
|
// Instead of using workers on CI, we use shards to run tests in parallel.
|
|
|
|
const WORKERS = isCI ? 2 : '35%'
|
2024-10-11 21:23:02 +03:00
|
|
|
|
2024-11-28 00:20:36 +03:00
|
|
|
const dirName = path.dirname(new URL(import.meta.url).pathname)
|
|
|
|
|
2024-10-11 21:23:02 +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 portsFromEnv = {
|
|
|
|
projectView: parseInt(process.env.PLAYWRIGHT_PORT_PV ?? '', 10),
|
|
|
|
dashboard: parseInt(process.env.PLAYWRIGHT_PORT ?? '', 10),
|
|
|
|
}
|
|
|
|
const ports = {
|
|
|
|
projectView:
|
|
|
|
Number.isFinite(portsFromEnv.projectView) ?
|
|
|
|
portsFromEnv.projectView
|
|
|
|
: await findFreePortInRange(4300, 4999),
|
|
|
|
dashboard:
|
|
|
|
Number.isFinite(portsFromEnv.dashboard) ?
|
|
|
|
portsFromEnv.dashboard
|
|
|
|
: await findFreePortInRange(4300, 4999),
|
|
|
|
}
|
|
|
|
console.log(`Selected playwright servers' ports: ${ports.projectView} and ${ports.dashboard}`)
|
|
|
|
// 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 = `${ports.dashboard}`
|
|
|
|
process.env.PLAYWRIGHT_PORT_PV = `${ports.projectView}`
|
|
|
|
|
|
|
|
export default defineConfig({
|
|
|
|
fullyParallel: true,
|
2024-11-15 15:12:55 +03:00
|
|
|
...(WORKERS ? { workers: WORKERS } : {}),
|
2024-11-21 13:52:20 +03:00
|
|
|
forbidOnly: isCI,
|
2024-11-28 17:40:29 +03:00
|
|
|
reporter: isCI ? [['list'], ['blob']] : [['html']],
|
2024-11-21 13:52:20 +03:00
|
|
|
retries: isCI ? 3 : 0,
|
2024-10-11 21:23:02 +03:00
|
|
|
use: {
|
|
|
|
headless: !DEBUG,
|
|
|
|
actionTimeout: 5000,
|
2024-11-21 13:52:20 +03:00
|
|
|
|
2024-10-11 21:23:02 +03:00
|
|
|
trace: 'retain-on-failure',
|
|
|
|
...(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',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
projects: [
|
2024-11-15 15:12:55 +03:00
|
|
|
// Setup project
|
|
|
|
{
|
|
|
|
name: 'Setup Dashboard',
|
2024-11-27 17:09:59 +03:00
|
|
|
testDir: './integration-test/dashboard',
|
2024-11-15 15:12:55 +03:00
|
|
|
testMatch: /.*\.setup\.ts/,
|
|
|
|
timeout: TIMEOUT_MS,
|
|
|
|
use: {
|
|
|
|
baseURL: `http://localhost:${ports.dashboard}`,
|
|
|
|
actionTimeout: TIMEOUT_MS,
|
2024-12-09 23:43:41 +03:00
|
|
|
offline: false,
|
2024-11-15 15:12:55 +03:00
|
|
|
},
|
|
|
|
},
|
2024-10-11 21:23:02 +03:00
|
|
|
{
|
|
|
|
name: 'Dashboard',
|
2024-11-27 17:09:59 +03:00
|
|
|
testDir: './integration-test/dashboard',
|
2024-11-15 15:12:55 +03:00
|
|
|
testMatch: /.*\.spec\.ts/,
|
|
|
|
dependencies: ['Setup Dashboard'],
|
|
|
|
expect: {
|
|
|
|
toHaveScreenshot: { threshold: 0 },
|
|
|
|
timeout: TIMEOUT_MS,
|
|
|
|
},
|
|
|
|
timeout: TIMEOUT_MS,
|
|
|
|
use: {
|
|
|
|
baseURL: `http://localhost:${ports.dashboard}`,
|
|
|
|
actionTimeout: TIMEOUT_MS,
|
2024-12-09 23:43:41 +03:00
|
|
|
offline: false,
|
2024-11-28 00:20:36 +03:00
|
|
|
storageState: path.join(dirName, './playwright/.auth/user.json'),
|
2024-11-15 15:12:55 +03:00
|
|
|
},
|
|
|
|
},
|
2024-10-11 21:23:02 +03:00
|
|
|
{
|
|
|
|
name: 'Setup Tests for Project View',
|
2024-11-27 17:09:59 +03:00
|
|
|
testMatch: /integration-test\/project-view\/setup\.ts/,
|
2024-10-11 21:23:02 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Project View',
|
|
|
|
dependencies: ['Setup Tests for Project View'],
|
2024-11-27 17:09:59 +03:00
|
|
|
testDir: './integration-test/project-view',
|
2024-10-11 21:23:02 +03:00
|
|
|
timeout: 60000,
|
2024-11-27 17:09:59 +03:00
|
|
|
repeatEach: 3,
|
|
|
|
retries: 0,
|
2024-10-11 21:23:02 +03:00
|
|
|
expect: {
|
|
|
|
timeout: 5000,
|
|
|
|
toHaveScreenshot: { threshold: 0 },
|
|
|
|
},
|
|
|
|
use: {
|
|
|
|
viewport: { width: 1920, height: 1750 },
|
|
|
|
baseURL: `http://localhost:${ports.projectView}`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
webServer: [
|
|
|
|
{
|
2024-11-27 17:09:59 +03:00
|
|
|
env: { INTEGRATION_TEST: 'true' },
|
2024-10-11 21:23:02 +03:00
|
|
|
command:
|
2024-11-15 15:12:55 +03:00
|
|
|
isCI || isProd ?
|
2024-10-11 21:23:02 +03:00
|
|
|
`corepack pnpm build && corepack pnpm exec vite preview --port ${ports.projectView} --strictPort`
|
|
|
|
: `corepack pnpm exec vite dev --port ${ports.projectView}`,
|
|
|
|
// Build from scratch apparently can take a while on CI machines.
|
|
|
|
timeout: 240 * 1000,
|
|
|
|
port: ports.projectView,
|
|
|
|
// We use our special, mocked version of server, thus do not want to re-use user's one.
|
|
|
|
reuseExistingServer: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
command:
|
2024-11-15 15:12:55 +03:00
|
|
|
isCI || isProd ?
|
2024-10-11 21:23:02 +03:00
|
|
|
`corepack pnpm exec vite -c vite.test.config.ts build && vite -c vite.test.config.ts preview --port ${ports.dashboard} --strictPort`
|
|
|
|
: `corepack pnpm exec vite -c vite.test.config.ts --port ${ports.dashboard}`,
|
|
|
|
timeout: 240 * 1000,
|
|
|
|
port: ports.dashboard,
|
|
|
|
reuseExistingServer: false,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
})
|