Skip to content

Commit fc8bed9

Browse files
authoredDec 15, 2021
fix: allow to pass options for custom server (#4110)
1 parent 2808367 commit fc8bed9

File tree

5 files changed

+123
-1
lines changed

5 files changed

+123
-1
lines changed
 

‎lib/options.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,14 @@
667667
"type": "object",
668668
"properties": {
669669
"type": {
670-
"$ref": "#/definitions/ServerType"
670+
"anyOf": [
671+
{
672+
"$ref": "#/definitions/ServerType"
673+
},
674+
{
675+
"$ref": "#/definitions/ServerString"
676+
}
677+
]
671678
},
672679
"options": {
673680
"$ref": "#/definitions/ServerOptions"

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

+17
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,23 @@ exports[`server option as object cacert, pfx, key and cert are buffer should han
511511
"
512512
`;
513513

514+
exports[`server option as object custom server with options should handle GET request to index route (/): console messages 1`] = `Array []`;
515+
516+
exports[`server option as object custom server with options should handle GET request to index route (/): http options 1`] = `
517+
Object {
518+
"maxHeaderSize": 16384,
519+
}
520+
`;
521+
522+
exports[`server option as object custom server with options should handle GET request to index route (/): page errors 1`] = `Array []`;
523+
524+
exports[`server option as object custom server with options should handle GET request to index route (/): response status 1`] = `200`;
525+
526+
exports[`server option as object custom server with options should handle GET request to index route (/): response text 1`] = `
527+
"Heyo.
528+
"
529+
`;
530+
514531
exports[`server option as object options should be prioritized over http2 options should handle GET request to index route (/): console messages 1`] = `Array []`;
515532

516533
exports[`server option as object options should be prioritized over http2 options should handle GET request to index route (/): https options 1`] = `

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

+17
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,23 @@ exports[`server option as object cacert, pfx, key and cert are buffer should han
511511
"
512512
`;
513513

514+
exports[`server option as object custom server with options should handle GET request to index route (/): console messages 1`] = `Array []`;
515+
516+
exports[`server option as object custom server with options should handle GET request to index route (/): http options 1`] = `
517+
Object {
518+
"maxHeaderSize": 16384,
519+
}
520+
`;
521+
522+
exports[`server option as object custom server with options should handle GET request to index route (/): page errors 1`] = `Array []`;
523+
524+
exports[`server option as object custom server with options should handle GET request to index route (/): response status 1`] = `200`;
525+
526+
exports[`server option as object custom server with options should handle GET request to index route (/): response text 1`] = `
527+
"Heyo.
528+
"
529+
`;
530+
514531
exports[`server option as object options should be prioritized over http2 options should handle GET request to index route (/): console messages 1`] = `Array []`;
515532

516533
exports[`server option as object options should be prioritized over http2 options should handle GET request to index route (/): https options 1`] = `

‎test/e2e/server.test.js

+77
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const Server = require("../../lib/Server");
1010
const config = require("../fixtures/static-config/webpack.config");
1111
const runBrowser = require("../helpers/run-browser");
1212
const { skipTestOnWindows } = require("../helpers/conditional-test");
13+
const customHTTP = require("../helpers/custom-http");
1314
const normalizeOptions = require("../helpers/normalize-options");
1415
const port = require("../ports-map")["server-option"];
1516

@@ -1643,5 +1644,81 @@ describe("server option", () => {
16431644
expect(pageErrors).toMatchSnapshot("page errors");
16441645
});
16451646
});
1647+
1648+
describe("custom server with options", () => {
1649+
let compiler;
1650+
let server;
1651+
let createServerSpy;
1652+
let page;
1653+
let browser;
1654+
let pageErrors;
1655+
let consoleMessages;
1656+
1657+
beforeEach(async () => {
1658+
compiler = webpack(config);
1659+
1660+
createServerSpy = jest.spyOn(customHTTP, "createServer");
1661+
1662+
server = new Server(
1663+
{
1664+
static: {
1665+
directory: staticDirectory,
1666+
watch: false,
1667+
},
1668+
server: {
1669+
type: path.join(__dirname, "../helpers/custom-http.js"),
1670+
options: {
1671+
maxHeaderSize: 16384,
1672+
},
1673+
},
1674+
port,
1675+
},
1676+
compiler
1677+
);
1678+
1679+
await server.start();
1680+
1681+
({ page, browser } = await runBrowser());
1682+
1683+
pageErrors = [];
1684+
consoleMessages = [];
1685+
});
1686+
1687+
afterEach(async () => {
1688+
createServerSpy.mockRestore();
1689+
1690+
await browser.close();
1691+
await server.stop();
1692+
});
1693+
1694+
it("should handle GET request to index route (/)", async () => {
1695+
page
1696+
.on("console", (message) => {
1697+
consoleMessages.push(message);
1698+
})
1699+
.on("pageerror", (error) => {
1700+
pageErrors.push(error);
1701+
});
1702+
1703+
const response = await page.goto(`http://127.0.0.1:${port}/`, {
1704+
waitUntil: "networkidle0",
1705+
});
1706+
1707+
const HTTPVersion = await page.evaluate(
1708+
() => performance.getEntries()[0].nextHopProtocol
1709+
);
1710+
1711+
expect(HTTPVersion).toEqual("http/1.1");
1712+
expect(
1713+
normalizeOptions(createServerSpy.mock.calls[0][0])
1714+
).toMatchSnapshot("http options");
1715+
expect(response.status()).toMatchSnapshot("response status");
1716+
expect(await response.text()).toMatchSnapshot("response text");
1717+
expect(
1718+
consoleMessages.map((message) => message.text())
1719+
).toMatchSnapshot("console messages");
1720+
expect(pageErrors).toMatchSnapshot("page errors");
1721+
});
1722+
});
16461723
});
16471724
});

‎test/validate-options.test.js

+4
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ const tests = {
393393
"http",
394394
"https",
395395
"spdy",
396+
"custom-server.js",
396397
{
397398
type: "http",
398399
},
@@ -402,6 +403,9 @@ const tests = {
402403
{
403404
type: "spdy",
404405
},
406+
{
407+
type: "custom-server.js",
408+
},
405409
{
406410
type: "https",
407411
options: {

0 commit comments

Comments
 (0)
Please sign in to comment.