Skip to content

Commit

Permalink
fix: legacy API (#3660)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Aug 17, 2021
1 parent d8bdd03 commit c4678bc
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/Server.js
Expand Up @@ -25,7 +25,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
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
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
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();
});
});

0 comments on commit c4678bc

Please sign in to comment.