Skip to content

Commit

Permalink
fix(examples): set baseURL and url for webserver respecting PORT env …
Browse files Browse the repository at this point in the history
…variable
  • Loading branch information
Marcos Bérgamo authored and Marcos Bérgamo committed Jun 29, 2022
1 parent 44664e4 commit 6576637
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: process.env.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 6576637

Please sign in to comment.