Skip to content

Commit 61e572e

Browse files
authored
test: add case for custom server implementation (#4000)
1 parent 2b42431 commit 61e572e

File tree

4 files changed

+87
-0
lines changed

4 files changed

+87
-0
lines changed

test/e2e/__snapshots__/server.test.js.snap.webpack4

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,17 @@ exports[`server option as object spdy server with options should handle GET requ
624624
"
625625
`;
626626

627+
exports[`server option as string custom-http should handle GET request to index route (/): console messages 1`] = `Array []`;
628+
629+
exports[`server option as string custom-http should handle GET request to index route (/): page errors 1`] = `Array []`;
630+
631+
exports[`server option as string custom-http should handle GET request to index route (/): response status 1`] = `200`;
632+
633+
exports[`server option as string custom-http should handle GET request to index route (/): response text 1`] = `
634+
"Heyo.
635+
"
636+
`;
637+
627638
exports[`server option as string http should handle GET request to index route (/): console messages 1`] = `Array []`;
628639

629640
exports[`server option as string http should handle GET request to index route (/): page errors 1`] = `Array []`;

test/e2e/__snapshots__/server.test.js.snap.webpack5

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,17 @@ exports[`server option as object spdy server with options should handle GET requ
624624
"
625625
`;
626626

627+
exports[`server option as string custom-http should handle GET request to index route (/): console messages 1`] = `Array []`;
628+
629+
exports[`server option as string custom-http should handle GET request to index route (/): page errors 1`] = `Array []`;
630+
631+
exports[`server option as string custom-http should handle GET request to index route (/): response status 1`] = `200`;
632+
633+
exports[`server option as string custom-http should handle GET request to index route (/): response text 1`] = `
634+
"Heyo.
635+
"
636+
`;
637+
627638
exports[`server option as string http should handle GET request to index route (/): console messages 1`] = `Array []`;
628639

629640
exports[`server option as string http should handle GET request to index route (/): page errors 1`] = `Array []`;

test/e2e/server.test.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,66 @@ describe("server option", () => {
9292
});
9393
});
9494

95+
describe("custom-http", () => {
96+
beforeEach(async () => {
97+
compiler = webpack(config);
98+
99+
server = new Server(
100+
{
101+
static: {
102+
directory: staticDirectory,
103+
watch: false,
104+
},
105+
server: path.resolve(__dirname, "../helpers/custom-http.js"),
106+
port,
107+
},
108+
compiler
109+
);
110+
111+
await server.start();
112+
113+
({ page, browser } = await runBrowser());
114+
115+
pageErrors = [];
116+
consoleMessages = [];
117+
});
118+
119+
afterEach(async () => {
120+
await browser.close();
121+
await server.stop();
122+
});
123+
124+
it("should handle GET request to index route (/)", async () => {
125+
page
126+
.on("console", (message) => {
127+
consoleMessages.push(message);
128+
})
129+
.on("pageerror", (error) => {
130+
pageErrors.push(error);
131+
});
132+
133+
const response = await page.goto(`http://127.0.0.1:${port}/`, {
134+
waitUntil: "networkidle0",
135+
});
136+
137+
const HTTPVersion = await page.evaluate(
138+
() => performance.getEntries()[0].nextHopProtocol
139+
);
140+
141+
expect(HTTPVersion).not.toEqual("h2");
142+
143+
expect(response.status()).toMatchSnapshot("response status");
144+
145+
expect(await response.text()).toMatchSnapshot("response text");
146+
147+
expect(
148+
consoleMessages.map((message) => message.text())
149+
).toMatchSnapshot("console messages");
150+
151+
expect(pageErrors).toMatchSnapshot("page errors");
152+
});
153+
});
154+
95155
describe("https", () => {
96156
beforeEach(async () => {
97157
compiler = webpack(config);

test/helpers/custom-http.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"use strict";
2+
3+
const customHTTP = require("http");
4+
5+
module.exports = customHTTP;

0 commit comments

Comments
 (0)