| 1 | /** |
| 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | * |
| 4 | * This source code is licensed under the MIT license found in the |
| 5 | * LICENSE file in the root directory of this source tree. |
| 6 | */ |
| 7 | |
| 8 | import {defineConfig, devices} from '@playwright/test'; |
| 9 | import path from 'path'; |
| 10 | |
| 11 | // Use process.env.PORT by default and fallback to port 3000 |
| 12 | const PORT = process.env.PORT || 3000; |
| 13 | |
| 14 | // Set webServer.url and use.baseURL with the location of the WebServer respecting the correct set port |
| 15 | const baseURL = `http://localhost:${PORT}`; |
| 16 | |
| 17 | // Reference: https://playwright.dev/docs/test-configuration |
| 18 | export default defineConfig({ |
| 19 | // Timeout per test |
| 20 | timeout: 30 * 1000, |
| 21 | // Run all tests in parallel. |
| 22 | fullyParallel: true, |
| 23 | // Test directory |
| 24 | testDir: path.join(__dirname, '__tests__/e2e'), |
| 25 | // If a test fails, retry it additional 2 times |
| 26 | retries: 5, |
| 27 | // Artifacts folder where screenshots, videos, and traces are stored. |
| 28 | outputDir: 'test-results/', |
| 29 | // Note: we only use text snapshots, so its safe to omit the host environment name |
| 30 | snapshotPathTemplate: '{testDir}/__snapshots__/{testFilePath}/{arg}{ext}', |
| 31 | |
| 32 | // Run your local dev server before starting the tests: |
| 33 | // https://playwright.dev/docs/test-advanced#launching-a-development-web-server-during-the-tests |
| 34 | webServer: { |
| 35 | command: 'yarn dev', |
| 36 | url: baseURL, |
| 37 | timeout: 300 * 1000, |
| 38 | reuseExistingServer: !process.env.CI, |
| 39 | }, |
| 40 | |
| 41 | // 'github' for GitHub Actions CI to generate annotations, plus a concise 'dot' |
| 42 | // default 'list' when running locally |
| 43 | reporter: process.env.CI ? 'github' : 'list', |
| 44 | |
| 45 | use: { |
| 46 | // Use baseURL so to make navigations relative. |
| 47 | // More information: https://playwright.dev/docs/api/class-testoptions#test-options-base-url |
| 48 | baseURL, |
| 49 | |
| 50 | // Retry a test if its failing with enabled tracing. This allows you to analyze the DOM, console logs, network traffic etc. |
| 51 | // More information: https://playwright.dev/docs/trace-viewer |
| 52 | trace: 'retry-with-trace', |
| 53 | |
| 54 | // All available context options: https://playwright.dev/docs/api/class-browser#browser-new-context |
| 55 | // contextOptions: { |
| 56 | // ignoreHTTPSErrors: true, |
| 57 | // }, |
| 58 | viewport: {width: 1920, height: 1080}, |
| 59 | }, |
| 60 | |
| 61 | projects: [ |
| 62 | { |
| 63 | name: 'chromium', |
| 64 | use: { |
| 65 | ...devices['Desktop Chrome'], |
| 66 | viewport: {width: 1920, height: 1080}, |
| 67 | }, |
| 68 | }, |
| 69 | // { |
| 70 | // name: 'Desktop Firefox', |
| 71 | // use: { |
| 72 | // ...devices['Desktop Firefox'], |
| 73 | // }, |
| 74 | // }, |
| 75 | // { |
| 76 | // name: 'Desktop Safari', |
| 77 | // use: { |
| 78 | // ...devices['Desktop Safari'], |
| 79 | // }, |
| 80 | // }, |
| 81 | // Test against mobile viewports. |
| 82 | // { |
| 83 | // name: "Mobile Chrome", |
| 84 | // use: { |
| 85 | // ...devices["Pixel 5"], |
| 86 | // }, |
| 87 | // }, |
| 88 | // { |
| 89 | // name: "Mobile Safari", |
| 90 | // use: devices["iPhone 12"], |
| 91 | // }, |
| 92 | ], |
| 93 | }); |