|
| 1 | +// @ts-check |
| 2 | +import process from "node:process"; |
| 3 | +import { devices } from "@playwright/test"; |
| 4 | +import { |
| 5 | + installBrowsersForNpmInstall, |
| 6 | + registry, |
| 7 | +} from "playwright-core/lib/server"; |
| 8 | + |
| 9 | +async function setup() { |
| 10 | + const browsersToInstall = []; |
| 11 | + if (!process.env.FIREFOX_BIN) { |
| 12 | + browsersToInstall.push("firefox"); |
| 13 | + browsersToInstall.push("ffmpeg"); |
| 14 | + } |
| 15 | + if (!process.env.CHROMIUM_BIN) { |
| 16 | + browsersToInstall.push("chromium"); |
| 17 | + browsersToInstall.push("ffmpeg"); |
| 18 | + } |
| 19 | + if (browsersToInstall.length > 0) { |
| 20 | + await installBrowsersForNpmInstall(browsersToInstall); |
| 21 | + } |
| 22 | + if (!process.env.FIREFOX_BIN) { |
| 23 | + process.env.FIREFOX_BIN = registry |
| 24 | + .findExecutable("firefox") |
| 25 | + .executablePath(); |
| 26 | + } |
| 27 | + if (!process.env.CHROMIUM_BIN) { |
| 28 | + process.env.CHROMIUM_BIN = registry |
| 29 | + .findExecutable("chromium") |
| 30 | + .executablePath(); |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +// In CI things can take longer in case there is too much load on the system. |
| 35 | +let timeoutMultiplier = process.env.CI ? 3 : 1; |
| 36 | + |
| 37 | +await setup(); |
| 38 | + |
| 39 | +/** |
| 40 | + * @see https://playwright.dev/docs/test-configuration |
| 41 | + * @type {import('@playwright/test').PlaywrightTestConfig} |
| 42 | + */ |
| 43 | +const config = { |
| 44 | + testDir: "./", |
| 45 | + /* Maximum time one test can run for. */ |
| 46 | + timeout: 30 * 1000 * timeoutMultiplier, |
| 47 | + expect: { |
| 48 | + /** |
| 49 | + * Maximum time expect() should wait for the condition to be met. |
| 50 | + * For example in `await expect(locator).toHaveText();` |
| 51 | + */ |
| 52 | + timeout: 5 * 1000 * timeoutMultiplier, |
| 53 | + }, |
| 54 | + /* Run tests in files in parallel */ |
| 55 | + fullyParallel: false, |
| 56 | + /* Fail the build on CI if you accidentally left test.only in the source code. */ |
| 57 | + forbidOnly: !!process.env.CI, |
| 58 | + /* Retry on CI only */ |
| 59 | + retries: process.env.CI ? 2 : 0, |
| 60 | + workers: 1, |
| 61 | + /* Reporter to use. See https://playwright.dev/docs/test-reporters */ |
| 62 | + reporter: "html", |
| 63 | + /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ |
| 64 | + use: { |
| 65 | + /* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */ |
| 66 | + actionTimeout: 0, |
| 67 | + /* Base URL to use in actions like `await page.goto('/')`. */ |
| 68 | + // baseURL: 'http://localhost:3000', |
| 69 | + // ignoreHTTPSErrors: true, |
| 70 | + |
| 71 | + /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ |
| 72 | + trace: "on-first-retry", |
| 73 | + video: "on-first-retry", |
| 74 | + }, |
| 75 | + |
| 76 | + /* Configure projects for major browsers */ |
| 77 | + projects: [ |
| 78 | + { |
| 79 | + name: "chromium", |
| 80 | + use: { |
| 81 | + ...devices["Desktop Chrome"], |
| 82 | + launchOptions: { |
| 83 | + executablePath: process.env.CHROMIUM_BIN, |
| 84 | + args: [ |
| 85 | + "--ignore-certificate-errors", |
| 86 | + "--allow-file-access-from-files", |
| 87 | + "--use-fake-ui-for-media-stream", |
| 88 | + "--use-fake-device-for-media-stream", |
| 89 | + "--force-color-profile=srgb", |
| 90 | + ], |
| 91 | + }, |
| 92 | + }, |
| 93 | + }, |
| 94 | + { |
| 95 | + name: "firefox", |
| 96 | + use: { |
| 97 | + ...devices["Desktop Firefox"], |
| 98 | + launchOptions: { |
| 99 | + executablePath: process.env.FIREFOX_BIN, |
| 100 | + }, |
| 101 | + }, |
| 102 | + }, |
| 103 | + ], |
| 104 | + |
| 105 | + /* Folder for test artifacts such as screenshots, videos, traces, etc. */ |
| 106 | + outputDir: "test-results/", |
| 107 | +}; |
| 108 | + |
| 109 | +export default config; |
0 commit comments