Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

playwright.config.ts

48 lines1.2 KB

1import { defineConfig, devices } from '@playwright/test'
2import { appServerReady } from '@tanstack/router-e2e-utils'
3​
4const mode = process.env.MODE ?? 'prod'
5const isDev = mode === 'dev'
6const viteConfig = process.env.VITE_CONFIG // 'nitro' | 'basepath' | 'cloudflare' | undefined
7const PORT = Number(process.env.E2E_APP_PORT ?? 0)
8​
9// When using basepath config, the app is served at /my-app
10const basePath = viteConfig === 'basepath' ? '/my-app' : ''
11const baseURL = `http://localhost:${PORT}${basePath}`
12​
13// Select the appropriate dev command based on VITE_CONFIG
14const devCommand = viteConfig
15 ? `pnpm dev:e2e:${viteConfig}`
16 : 'pnpm dev:e2e --port 0'
17​
18export default defineConfig({
19 testDir: './tests',
20 workers: 1,
21 reporter: [['line']],
22​
23 globalSetup: './tests/setup/global.setup.ts',
24​
25 use: {
26 baseURL,
27 },
28​
29 webServer: {
30 command: isDev ? devCommand : `pnpm build && PORT=${PORT} pnpm start`,
31 wait: appServerReady,
32 reuseExistingServer: false,
33 stdout: 'pipe',
34 env: {
35 VITE_NODE_ENV: 'test',
36 PORT: String(PORT),
37 },
38 },
39​
40 projects: [
41 {
42 name: 'chromium',
43 use: {
44 ...devices['Desktop Chrome'],
45 },
46 },
47 ],
48})