Skip to content

Commit c4678bc

Browse files
fix: legacy API (#3660)
1 parent d8bdd03 commit c4678bc

File tree

4 files changed

+117
-6
lines changed

4 files changed

+117
-6
lines changed

Diff for: lib/Server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Server {
2525
"DEP_WEBPACK_DEV_SERVER_CONSTRUCTOR"
2626
)();
2727

28-
[options, compiler] = [compiler, options];
28+
[options = {}, compiler] = [compiler, options];
2929
}
3030

3131
validate(schema, options, "webpack Dev Server");

Diff for: test/e2e/__snapshots__/api.test.js.snap.webpack4

+24-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Array [
2222

2323
exports[`API should work with callback API: page errors 1`] = `Array []`;
2424

25-
exports[`API should work with deprecated API: console messages 1`] = `
25+
exports[`API should work with deprecated API ('listen' and \`close\` methods): console messages 1`] = `
2626
Array [
2727
"[HMR] Waiting for update signal from WDS...",
2828
"Hey.",
@@ -31,4 +31,26 @@ Array [
3131
]
3232
`;
3333

34-
exports[`API should work with deprecated API: page errors 1`] = `Array []`;
34+
exports[`API should work with deprecated API ('listen' and \`close\` methods): page errors 1`] = `Array []`;
35+
36+
exports[`API should work with deprecated API (only compiler in constructor): console messages 1`] = `
37+
Array [
38+
"[HMR] Waiting for update signal from WDS...",
39+
"Hey.",
40+
"[webpack-dev-server] Hot Module Replacement enabled.",
41+
"[webpack-dev-server] Live Reloading enabled.",
42+
]
43+
`;
44+
45+
exports[`API should work with deprecated API (only compiler in constructor): page errors 1`] = `Array []`;
46+
47+
exports[`API should work with deprecated API (the order of the arguments in the constructor): console messages 1`] = `
48+
Array [
49+
"[HMR] Waiting for update signal from WDS...",
50+
"Hey.",
51+
"[webpack-dev-server] Hot Module Replacement enabled.",
52+
"[webpack-dev-server] Live Reloading enabled.",
53+
]
54+
`;
55+
56+
exports[`API should work with deprecated API (the order of the arguments in the constructor): page errors 1`] = `Array []`;

Diff for: test/e2e/__snapshots__/api.test.js.snap.webpack5

+24-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Array [
2222

2323
exports[`API should work with callback API: page errors 1`] = `Array []`;
2424

25-
exports[`API should work with deprecated API: console messages 1`] = `
25+
exports[`API should work with deprecated API ('listen' and \`close\` methods): console messages 1`] = `
2626
Array [
2727
"[HMR] Waiting for update signal from WDS...",
2828
"Hey.",
@@ -31,4 +31,26 @@ Array [
3131
]
3232
`;
3333

34-
exports[`API should work with deprecated API: page errors 1`] = `Array []`;
34+
exports[`API should work with deprecated API ('listen' and \`close\` methods): page errors 1`] = `Array []`;
35+
36+
exports[`API should work with deprecated API (only compiler in constructor): console messages 1`] = `
37+
Array [
38+
"[HMR] Waiting for update signal from WDS...",
39+
"Hey.",
40+
"[webpack-dev-server] Hot Module Replacement enabled.",
41+
"[webpack-dev-server] Live Reloading enabled.",
42+
]
43+
`;
44+
45+
exports[`API should work with deprecated API (only compiler in constructor): page errors 1`] = `Array []`;
46+
47+
exports[`API should work with deprecated API (the order of the arguments in the constructor): console messages 1`] = `
48+
Array [
49+
"[HMR] Waiting for update signal from WDS...",
50+
"Hey.",
51+
"[webpack-dev-server] Hot Module Replacement enabled.",
52+
"[webpack-dev-server] Live Reloading enabled.",
53+
]
54+
`;
55+
56+
exports[`API should work with deprecated API (the order of the arguments in the constructor): page errors 1`] = `Array []`;

Diff for: test/e2e/api.test.js

+68-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ describe("API", () => {
7979
});
8080
});
8181

82-
it(`should work with deprecated API`, async () => {
82+
it("should work with deprecated API ('listen' and `close` methods)", async () => {
8383
const compiler = webpack(config);
8484
const devServerOptions = { port };
8585
const server = new Server(devServerOptions, compiler);
@@ -125,4 +125,71 @@ describe("API", () => {
125125
});
126126
});
127127
});
128+
129+
it(`should work with deprecated API (the order of the arguments in the constructor)`, async () => {
130+
const compiler = webpack(config);
131+
const devServerOptions = { port };
132+
const server = new Server(compiler, devServerOptions);
133+
134+
await server.start();
135+
136+
const { page, browser } = await runBrowser();
137+
138+
const pageErrors = [];
139+
const consoleMessages = [];
140+
141+
page
142+
.on("console", (message) => {
143+
consoleMessages.push(message);
144+
})
145+
.on("pageerror", (error) => {
146+
pageErrors.push(error);
147+
});
148+
149+
await page.goto(`http://127.0.0.1:${port}/main`, {
150+
waitUntil: "networkidle0",
151+
});
152+
153+
expect(consoleMessages.map((message) => message.text())).toMatchSnapshot(
154+
"console messages"
155+
);
156+
expect(pageErrors).toMatchSnapshot("page errors");
157+
158+
await browser.close();
159+
await server.stop();
160+
});
161+
162+
it(`should work with deprecated API (only compiler in constructor)`, async () => {
163+
const compiler = webpack(config);
164+
const server = new Server(compiler);
165+
166+
server.options.port = port;
167+
168+
await server.start();
169+
170+
const { page, browser } = await runBrowser();
171+
172+
const pageErrors = [];
173+
const consoleMessages = [];
174+
175+
page
176+
.on("console", (message) => {
177+
consoleMessages.push(message);
178+
})
179+
.on("pageerror", (error) => {
180+
pageErrors.push(error);
181+
});
182+
183+
await page.goto(`http://127.0.0.1:${port}/main`, {
184+
waitUntil: "networkidle0",
185+
});
186+
187+
expect(consoleMessages.map((message) => message.text())).toMatchSnapshot(
188+
"console messages"
189+
);
190+
expect(pageErrors).toMatchSnapshot("page errors");
191+
192+
await browser.close();
193+
await server.stop();
194+
});
128195
});

0 commit comments

Comments
 (0)