Skip to content

Commit

Permalink
use host.docker.internal to access dev-server from e2e-test
Browse files Browse the repository at this point in the history
  • Loading branch information
nknapp committed Nov 3, 2024
1 parent 77ddba2 commit 40cc0fd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
services:
browsers:
build: ./playwright-docker
network_mode: host
ports:
- 3000:3000
extra_hosts:
# Access host from container for Mac, Windows and Linux
# see https://stackoverflow.com/a/43541732
- "host.docker.internal:host-gateway"
4 changes: 2 additions & 2 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default defineConfig({
workers: process.env.CI ? 1 : undefined,
reporter: "html",
use: {
baseURL: "http://127.0.0.1:5173",
baseURL: "http://host.docker.internal:5173",
trace: "on-first-retry",
},
expect: {
Expand All @@ -30,7 +30,7 @@ export default defineConfig({
},
],
webServer: {
command: "npm run dev:server -- --port 5173",
command: "npm run dev:server -- --port 5173 --host 0.0.0.0",
url: "http://localhost:5173",
stdout: "pipe",
timeout: 10000,
Expand Down
2 changes: 1 addition & 1 deletion src/manual-testing/e2e-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ function getAssociatedUrl(url: string): string {
const baseUrl = new URL("..", import.meta.url).href;
const relativePath = "./" + url.slice(baseUrl.length);
const associatedModule = relativePath.replace(/\.spec\.ts$/, ".ts");
return `http://localhost:5173?test=${encodeURIComponent(associatedModule)}&playwright=true`;
return `/?test=${encodeURIComponent(associatedModule)}&playwright=true`;
}

0 comments on commit 40cc0fd

Please sign in to comment.