Skip to content

Commit

Permalink
fix(examples/with-playwritght): use PORT env variable and fall back t…
Browse files Browse the repository at this point in the history
…o 3000 (#38107)

## Documentation / Examples

- [x] Related issues linked using `fixes #37952`
- [x] Make sure the linting passes by running `pnpm lint`
- [x] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
  • Loading branch information
thebergamo committed Jul 8, 2022
1 parent 4f09f95 commit 34e296b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion examples/with-playwright/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { PlaywrightTestConfig, devices } from '@playwright/test'
import path from 'path'

// Use process.env.PORT by default and fallback to port 3000
const PORT = process.env.PORT || 3000

// Set webServer.url and use.baseURL with the location of the WebServer respecting the correct set port
const baseURL = `http://localhost:${PORT}`

// Reference: https://playwright.dev/docs/test-configuration
const config: PlaywrightTestConfig = {
// Timeout per test
Expand All @@ -16,12 +22,16 @@ const config: PlaywrightTestConfig = {
// https://playwright.dev/docs/test-advanced#launching-a-development-web-server-during-the-tests
webServer: {
command: 'npm run dev',
port: 3000,
url: baseURL,
timeout: 120 * 1000,
reuseExistingServer: !process.env.CI,
},

use: {
// Use baseURL so to make navigations relative.
// More information: https://playwright.dev/docs/api/class-testoptions#test-options-base-url
baseURL,

// Retry a test if its failing with enabled tracing. This allows you to analyse the DOM, console logs, network traffic etc.
// More information: https://playwright.dev/docs/trace-viewer
trace: 'retry-with-trace',
Expand Down

0 comments on commit 34e296b

Please sign in to comment.