this repo has no description
at main 2.8 kB view raw
1import { defineConfig, devices } from "@playwright/test"; 2import { minutesToMilliseconds } from "date-fns"; 3 4/** 5 * @see https://playwright.dev/docs/test-configuration 6 */ 7export default defineConfig({ 8 /* Leave some time before github actions makes the job time out (1 hour), so the report can be deployed */ 9 globalTimeout: minutesToMilliseconds(9), 10 timeout: minutesToMilliseconds(1.2), 11 testDir: "./tests", 12 /* Run tests in files in parallel */ 13 fullyParallel: true, 14 /* Fail the build on CI if you accidentally left test.only in the source code. */ 15 forbidOnly: !!process.env.CI, 16 /* Retry on CI only */ 17 retries: 0, 18 /* Opt out of parallel tests on CI. */ 19 workers: process.env.CI ? 1 : undefined, 20 /* Reporter to use. See https://playwright.dev/docs/test-reporters */ 21 reporter: process.env.CI 22 ? [ 23 ["json", { outputFile: "test-results.json" }], 24 [process.env.SHARDING ? "blob" : "html"], 25 ["github"], 26 ["list"], 27 ] 28 : [], 29 /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ 30 use: { 31 /* Base URL to use in actions like `await page.goto('/')`. */ 32 baseURL: dependsOnTarget({ 33 live: process.env.BASE_URL, 34 dev: "http://localhost:5173", 35 built: "http://localhost:4173", 36 }), 37 38 // See https://github.com/microsoft/playwright/issues/16357 39 bypassCSP: dependsOnTarget({ 40 live: true, 41 dev: false, 42 built: false, 43 }), 44 45 /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ 46 trace: "on-first-retry", 47 48 locale: "fr-FR", 49 50 // Ensure no TZ issues for assertions that depend on time 51 timezoneId: "Etc/UTC", 52 }, 53 54 snapshotPathTemplate: "screenshots/{testName}/{projectName}{ext}", 55 56 /* Configure projects for major browsers */ 57 projects: [ 58 { name: "desktop", use: devices["Desktop Chrome"] }, 59 { name: "mobile", use: devices["iPhone SE (3rd gen)"] }, 60 ], 61 62 /* Run your local dev server before starting the tests */ 63 webServer: dependsOnTarget({ 64 live: undefined, 65 dev: { 66 command: "bun run dev", 67 port: 5173, 68 reuseExistingServer: true, 69 }, 70 built: { 71 command: "bun run preview", 72 port: 4173, 73 reuseExistingServer: false, 74 }, 75 }), 76}); 77 78/** 79 * 80 * @param param0.live - Value to return if we're checking against a live URL (meaning $BASE_URL is set) 81 * @param param0.dev - Value to return if we're checking against a dev server (meaning $CI is not set) 82 * @param param0.built - Value to return if we're checking against a built version (meaning $CI is set) 83 */ 84function dependsOnTarget<L, B, D>({ 85 live, 86 dev, 87 built, 88}: { 89 live: L; 90 dev: D; 91 built: B; 92}): L | B | D { 93 if (process.env.BASE_URL) return live; 94 if (process.env.CI) return built; 95 return dev; 96}