Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: legacy API #3660

Merged
merged 1 commit into from
Aug 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Server {
"DEP_WEBPACK_DEV_SERVER_CONSTRUCTOR"
)();

[options, compiler] = [compiler, options];
[options = {}, compiler] = [compiler, options];
}

validate(schema, options, "webpack Dev Server");
Expand Down
26 changes: 24 additions & 2 deletions test/e2e/__snapshots__/api.test.js.snap.webpack4
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Array [

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

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

exports[`API should work with deprecated API: page errors 1`] = `Array []`;
exports[`API should work with deprecated API ('listen' and \`close\` methods): page errors 1`] = `Array []`;

exports[`API should work with deprecated API (only compiler in constructor): console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hey.",
"[webpack-dev-server] Hot Module Replacement enabled.",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`API should work with deprecated API (only compiler in constructor): page errors 1`] = `Array []`;

exports[`API should work with deprecated API (the order of the arguments in the constructor): console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hey.",
"[webpack-dev-server] Hot Module Replacement enabled.",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`API should work with deprecated API (the order of the arguments in the constructor): page errors 1`] = `Array []`;
26 changes: 24 additions & 2 deletions test/e2e/__snapshots__/api.test.js.snap.webpack5
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Array [

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

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

exports[`API should work with deprecated API: page errors 1`] = `Array []`;
exports[`API should work with deprecated API ('listen' and \`close\` methods): page errors 1`] = `Array []`;

exports[`API should work with deprecated API (only compiler in constructor): console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hey.",
"[webpack-dev-server] Hot Module Replacement enabled.",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`API should work with deprecated API (only compiler in constructor): page errors 1`] = `Array []`;

exports[`API should work with deprecated API (the order of the arguments in the constructor): console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hey.",
"[webpack-dev-server] Hot Module Replacement enabled.",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`API should work with deprecated API (the order of the arguments in the constructor): page errors 1`] = `Array []`;
69 changes: 68 additions & 1 deletion test/e2e/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe("API", () => {
});
});

it(`should work with deprecated API`, async () => {
it("should work with deprecated API ('listen' and `close` methods)", async () => {
const compiler = webpack(config);
const devServerOptions = { port };
const server = new Server(devServerOptions, compiler);
Expand Down Expand Up @@ -125,4 +125,71 @@ describe("API", () => {
});
});
});

it(`should work with deprecated API (the order of the arguments in the constructor)`, async () => {
const compiler = webpack(config);
const devServerOptions = { port };
const server = new Server(compiler, devServerOptions);

await server.start();

const { page, browser } = await runBrowser();

const pageErrors = [];
const consoleMessages = [];

page
.on("console", (message) => {
consoleMessages.push(message);
})
.on("pageerror", (error) => {
pageErrors.push(error);
});

await page.goto(`http://127.0.0.1:${port}/main`, {
waitUntil: "networkidle0",
});

expect(consoleMessages.map((message) => message.text())).toMatchSnapshot(
"console messages"
);
expect(pageErrors).toMatchSnapshot("page errors");

await browser.close();
await server.stop();
});

it(`should work with deprecated API (only compiler in constructor)`, async () => {
const compiler = webpack(config);
const server = new Server(compiler);

server.options.port = port;

await server.start();

const { page, browser } = await runBrowser();

const pageErrors = [];
const consoleMessages = [];

page
.on("console", (message) => {
consoleMessages.push(message);
})
.on("pageerror", (error) => {
pageErrors.push(error);
});

await page.goto(`http://127.0.0.1:${port}/main`, {
waitUntil: "networkidle0",
});

expect(consoleMessages.map((message) => message.text())).toMatchSnapshot(
"console messages"
);
expect(pageErrors).toMatchSnapshot("page errors");

await browser.close();
await server.stop();
});
});