Use all available CPUs to run tests on CI (#6138)

* Use all available CPUs to run tests on CI

* Use less than 100% based on research

* Ensure proper types for worker value
This commit is contained in:
Jace Browning
2025-04-04 11:11:26 -04:00
committed by GitHub
parent 118ec28b04
commit 1aa27bd91c
3 changed files with 66 additions and 15 deletions

View File

@ -1,10 +1,29 @@
import { defineConfig, devices } from '@playwright/test'
import os from 'os'
/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();
const platform = os.platform() // 'linux' (Ubuntu), 'darwin' (macOS), 'win32' (Windows)
let workers: number | string
if (process.env.E2E_WORKERS) {
workers = process.env.E2E_WORKERS.includes('%')
? process.env.E2E_WORKERS
: parseInt(process.env.E2E_WORKERS)
} else if (!process.env.CI) {
workers = 1 // Local dev: keep things simple and deterministic by default
} else {
// On CI: adjust based on OS
switch (platform) {
case 'linux':
workers = '100%' // CI Linux runners are generally beefier
break
case 'darwin':
case 'win32':
default:
workers = '75%' // Slightly conservative for GUI-based OSes
break
}
}
/**
* See https://playwright.dev/docs/test-configuration.
@ -19,8 +38,8 @@ export default defineConfig({
forbidOnly: !!process.env.CI,
/* Do not retry */
retries: process.env.CI ? 0 : 0,
/* Different amount of parallelism on CI and local. */
workers: process.env.CI ? 1 : 4,
/* Use all available CPU cores */
workers: workers,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: [
[process.env.CI ? 'dot' : 'list'],