Skip to content

Commit 599d8ad

Browse files
committed
test: temporarily ignore hmr port error for custom servers
1 parent 8a1993e commit 599d8ad

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

.tests/test.netlify.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { expect, Page } from "@playwright/test";
22
import getPort from "get-port";
33

4-
import { matchLine, testTemplate, urlRegex } from "./utils";
4+
import {
5+
matchLine,
6+
testTemplate,
7+
urlRegex,
8+
withoutHmrPortError,
9+
} from "./utils";
510

611
const test = testTemplate("netlify");
712

@@ -15,7 +20,7 @@ test("dev", async ({ page, $ }) => {
1520

1621
const url = await matchLine(dev.stdout, urlRegex.custom);
1722
await workflow({ page, url });
18-
expect(dev.buffer.stderr).toBe("");
23+
expect(withoutHmrPortError(dev.buffer.stderr)).toBe("");
1924
});
2025

2126
test("build", async ({ $ }) => {

.tests/test.node-custom-server.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { expect, Page } from "@playwright/test";
22
import getPort from "get-port";
33

4-
import { matchLine, testTemplate, urlRegex } from "./utils";
4+
import {
5+
matchLine,
6+
testTemplate,
7+
urlRegex,
8+
withoutHmrPortError,
9+
} from "./utils";
510

611
const test = testTemplate("node-custom-server");
712

@@ -15,7 +20,8 @@ test("dev", async ({ page, $ }) => {
1520

1621
const url = await matchLine(dev.stdout, urlRegex.custom);
1722
await workflow({ page, url });
18-
expect(dev.buffer.stderr).toBe("");
23+
24+
expect(withoutHmrPortError(dev.buffer.stderr)).toBe("");
1925
});
2026

2127
test("build + start", async ({ page, $ }) => {

.tests/test.vercel.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { expect, Page } from "@playwright/test";
22
import getPort from "get-port";
33

4-
import { matchLine, testTemplate, urlRegex } from "./utils";
4+
import {
5+
matchLine,
6+
testTemplate,
7+
urlRegex,
8+
withoutHmrPortError,
9+
} from "./utils";
510

611
const test = testTemplate("vercel");
712

@@ -15,7 +20,7 @@ test("dev", async ({ page, $ }) => {
1520

1621
const url = await matchLine(dev.stdout, urlRegex.custom);
1722
await workflow({ page, url });
18-
expect(dev.buffer.stderr).toBe("");
23+
expect(withoutHmrPortError(dev.buffer.stderr)).toBe("");
1924
});
2025

2126
test("build", async ({ $ }) => {

.tests/utils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,10 @@ export const urlRegex = {
143143
netlify: urlMatch({ prefix: / Server now ready on / }),
144144
wrangler: urlMatch({ prefix: /Ready on / }),
145145
};
146+
147+
// `vite.createServer` always tries to use the same HMR port
148+
// unless `server.hmr.port` is configured.
149+
// Ultimately, we should provide better primitives for building custom servers
150+
// something like `createRequestHandler(pathToBuild)`.
151+
export const withoutHmrPortError = (stderr: string) =>
152+
stderr.replace(/WebSocket server error: Port is already in use/, "").trim();

0 commit comments

Comments
 (0)