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

playwright.config.ts

54 lines1.4 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 distDir = process.env.E2E_DIST_DIR
7const viteConfig = process.env.VITE_CONFIG // 'nitro' | 'basepath' | 'cloudflare' | undefined
8const PORT = Number(process.env.E2E_APP_PORT ?? 0)
9​
10// When using basepath config, the app is served at /my-app
11const basePath = viteConfig === 'basepath' ? '/my-app' : ''
12const baseURL = `http://localhost:${PORT}${basePath}`
13​
14// Select the appropriate dev command based on VITE_CONFIG
15const devCommand = viteConfig
16 ? `pnpm dev:e2e:${viteConfig}`
17 : 'pnpm dev:e2e --port 0'
18​
19export default defineConfig({
20 testDir: './tests',
21 testMatch: isDev ? '**/*.dev.spec.ts' : '**/*.prod.spec.ts',
22 workers: 1,
23 reporter: [['line']],
24​
25 globalSetup: './tests/setup/global.setup.ts',
26​
27 use: {
28 baseURL,
29 },
30​
31 webServer: {
32 command: isDev
33 ? devCommand
34 : distDir
35 ? `pnpm exec srvx --prod --dir=. -s ${distDir}/client --entry ${distDir}/server/server.js`
36 : `pnpm build && PORT=${PORT} pnpm start`,
37 wait: appServerReady,
38 reuseExistingServer: false,
39 stdout: 'pipe',
40 env: {
41 VITE_NODE_ENV: 'test',
42 PORT: String(PORT),
43 },
44 },
45​
46 projects: [
47 {
48 name: 'chromium',
49 use: {
50 ...devices['Desktop Chrome'],
51 },
52 },
53 ],
54})