···11+import { defineConfig, devices } from "@playwright/test";
22+import { minutesToMilliseconds } from "date-fns";
33+44+/**
55+ * @see https://playwright.dev/docs/test-configuration
66+ */
77+export default defineConfig({
88+ /* Leave some time before github actions makes the job time out (1 hour), so the report can be deployed */
99+ globalTimeout: minutesToMilliseconds(9),
1010+ timeout: minutesToMilliseconds(1.2),
1111+ testDir: "./tests",
1212+ /* Run tests in files in parallel */
1313+ fullyParallel: true,
1414+ /* Fail the build on CI if you accidentally left test.only in the source code. */
1515+ forbidOnly: !!process.env.CI,
1616+ /* Retry on CI only */
1717+ retries: 0,
1818+ /* Opt out of parallel tests on CI. */
1919+ workers: process.env.CI ? 1 : undefined,
2020+ /* Reporter to use. See https://playwright.dev/docs/test-reporters */
2121+ reporter: process.env.CI
2222+ ? [
2323+ ["json", { outputFile: "test-results.json" }],
2424+ [process.env.SHARDING ? "blob" : "html"],
2525+ ["github"],
2626+ ["list"],
2727+ ]
2828+ : [],
2929+ /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
3030+ use: {
3131+ /* Base URL to use in actions like `await page.goto('/')`. */
3232+ baseURL: dependsOnTarget({
3333+ live: process.env.BASE_URL,
3434+ dev: "http://localhost:5173",
3535+ built: "http://localhost:4173",
3636+ }),
3737+3838+ // See https://github.com/microsoft/playwright/issues/16357
3939+ bypassCSP: dependsOnTarget({
4040+ live: true,
4141+ dev: false,
4242+ built: false,
4343+ }),
4444+4545+ /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
4646+ trace: "on-first-retry",
4747+4848+ locale: "fr-FR",
4949+5050+ // Ensure no TZ issues for assertions that depend on time
5151+ timezoneId: "Etc/UTC",
5252+ },
5353+5454+ snapshotPathTemplate: "screenshots/{testName}/{projectName}{ext}",
5555+5656+ /* Configure projects for major browsers */
5757+ projects: [
5858+ { name: "desktop", use: devices["Desktop Chrome"] },
5959+ { name: "mobile", use: devices["iPhone SE (3rd gen)"] },
6060+ ],
6161+6262+ /* Run your local dev server before starting the tests */
6363+ webServer: dependsOnTarget({
6464+ live: undefined,
6565+ dev: {
6666+ command: "bun run dev",
6767+ port: 5173,
6868+ reuseExistingServer: true,
6969+ },
7070+ built: {
7171+ command: "bun run preview",
7272+ port: 4173,
7373+ reuseExistingServer: false,
7474+ },
7575+ }),
7676+});
7777+7878+/**
7979+ *
8080+ * @param param0.live - Value to return if we're checking against a live URL (meaning $BASE_URL is set)
8181+ * @param param0.dev - Value to return if we're checking against a dev server (meaning $CI is not set)
8282+ * @param param0.built - Value to return if we're checking against a built version (meaning $CI is set)
8383+ */
8484+function dependsOnTarget<L, B, D>({
8585+ live,
8686+ dev,
8787+ built,
8888+}: {
8989+ live: L;
9090+ dev: D;
9191+ built: B;
9292+}): L | B | D {
9393+ if (process.env.BASE_URL) return live;
9494+ if (process.env.CI) return built;
9595+ return dev;
9696+}