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

playwright.config.ts

58 lines1.4 KB

1import { defineConfig, devices } from '@playwright/test'
2import { appServerReady } from '@tanstack/router-e2e-utils'
3import { ssrStylesMode, useNitro, viteBundledDev } from './env'
4​
5const mode = process.env.MODE ?? 'prod'
6const isDev = mode === 'dev'
7​
8// Build a unique port key per dimension combination (ssrStyles mode + nitro)
9// e.g. "...dev-ssr-styles", "...dev-ssr-styles-disabled", "...dev-ssr-styles-nitro",
10// "...dev-ssr-styles-disabled-nitro"
11​
12const PORT = Number(process.env.E2E_APP_PORT ?? 0)
13const baseURL = `http://localhost:${PORT}`
14​
15// Select the appropriate dev command based on SSR_STYLES + VITE_USE_NITRO
16function getDevCommand() {
17 const scriptParts = ['dev:e2e']
18 if (ssrStylesMode !== 'default') {
19 scriptParts.push(ssrStylesMode)
20 }
21 if (useNitro) {
22 scriptParts.push('nitro')
23 }
24 return `pnpm ${scriptParts.join(':')}`
26​
27export default defineConfig({
28 testDir: './tests',
29 workers: 1,
30 reporter: [['line']],
31​
32 globalSetup: './tests/setup/global.setup.ts',
33​
34 use: {
35 baseURL,
36 },
37​
38 webServer: {
39 command: isDev ? getDevCommand() : `pnpm build && PORT=${PORT} pnpm start`,
40 wait: appServerReady,
41 reuseExistingServer: false,
42 stdout: 'pipe',
43 env: {
44 VITE_NODE_ENV: 'test',
45 PORT: String(PORT),
46 E2E_VITE_BUNDLED_DEV: String(viteBundledDev),
47 },
48 },
49​
50 projects: [
51 {
52 name: 'chromium',
53 use: {
54 ...devices['Desktop Chrome'],
55 },
56 },
57 ],
58})