@@ -2,7 +2,7 @@ import { defineConfig, devices, type ReporterDescription } from '@playwright/tes
22import os from 'node:os' ;
33
44import { config } from '#pkg/config.js' ;
5- import { playwrightBrowserConfig } from '#pkg/constants.js' ;
5+ import { playwrightBrowser , playwrightServerPortEnvVarName } from '#pkg/constants.js' ;
66
77const countOfCpus = os . cpus ( ) . length ;
88const workers = countOfCpus
@@ -41,7 +41,7 @@ export default defineConfig({
4141 // fail a Playwright run in CI if some test.only is in the source code
4242 forbidOnly : ! ! config . CI ,
4343
44- snapshotPathTemplate : `{testDir}/../snapshots/{testFilePath}/{arg}-{projectName}-${ playwrightBrowserConfig . browser === 'docker' ? 'docker' : '{platform}' } {ext}` ,
44+ snapshotPathTemplate : `{testDir}/../snapshots/{testFilePath}/{arg}-{projectName}-${ playwrightBrowser === 'docker' ? 'docker' : '{platform}' } {ext}` ,
4545
4646 expect : {
4747 toHaveScreenshot : {
@@ -59,14 +59,30 @@ export default defineConfig({
5959
6060 // always capture video (seems to not have any performance impact)
6161 video : 'on' ,
62+
63+ connectOptions :
64+ playwrightBrowser === 'docker'
65+ ? {
66+ wsEndpoint : `ws://127.0.0.1:${
67+ // eslint-disable-next-line n/no-process-env -- port provided by Playwright server stdout via regex (see webServer.wait.stdout)
68+ process . env [ playwrightServerPortEnvVarName ]
69+ } /`,
70+ }
71+ : undefined ,
6272 } ,
6373
6474 webServer :
65- playwrightBrowserConfig . browser === 'docker'
75+ playwrightBrowser === 'docker'
6676 ? {
6777 // start the Playwright server in a docker container
68- command : createDockerRunCommand ( playwrightBrowserConfig . port ) ,
69- url : `http://127.0.0.1:${ playwrightBrowserConfig . port } /` ,
78+ command : `docker run --rm --init --workdir /home/pwuser --user pwuser --network host mcr.microsoft.com/playwright:v1.57.0-noble /bin/sh -c "npx -y playwright@1.57.0 run-server --host 0.0.0.0"` ,
79+ wait : {
80+ // Capture the Playwright Server port from stdout via regex (https://playwright.dev/docs/api/class-testconfig#test-config-web-server)
81+ // eslint-disable-next-line prefer-regex-literals
82+ stdout : new RegExp (
83+ String . raw `Listening on ws:\/\/0\.0\.0\.0:(?<${ playwrightServerPortEnvVarName } >\d+)` ,
84+ ) ,
85+ } ,
7086 stdout : 'pipe' ,
7187 stderr : 'pipe' ,
7288 timeout : 30_000 ,
@@ -78,14 +94,3 @@ export default defineConfig({
7894 }
7995 : undefined ,
8096} ) ;
81-
82- function createDockerRunCommand ( port : number ) {
83- let dockerRunCommand = `docker run --rm --init --workdir /home/pwuser --user pwuser --network host` ;
84- if ( ! config . CI ) {
85- // on development machines, we forward the X11 socket to the host system to allow GUI applications to run from within the container
86- dockerRunCommand += ` -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix` ;
87- }
88- dockerRunCommand += ` mcr.microsoft.com/playwright:v1.57.0-noble /bin/sh -c "npx -y playwright@1.57.0 run-server --port ${ port } --host 0.0.0.0"` ;
89-
90- return dockerRunCommand ;
91- }
0 commit comments