Skip to content

Commit

Permalink
test: rerun dev server (#3824)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait authored Sep 9, 2021
1 parent 011bcf1 commit 5e6a387
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
22 changes: 22 additions & 0 deletions test/e2e/__snapshots__/api.test.js.snap.webpack4
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`API should work and allow to rerun dev server multiple times: 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 and allow to rerun dev server multiple times: console messages 2`] = `
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 and allow to rerun dev server multiple times: page errors 1`] = `Array []`;

exports[`API should work and allow to rerun dev server multiple times: page errors 2`] = `Array []`;

exports[`API should work when using configured manually: console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
Expand Down
22 changes: 22 additions & 0 deletions test/e2e/__snapshots__/api.test.js.snap.webpack5
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`API should work and allow to rerun dev server multiple times: 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 and allow to rerun dev server multiple times: console messages 2`] = `
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 and allow to rerun dev server multiple times: page errors 1`] = `Array []`;

exports[`API should work and allow to rerun dev server multiple times: page errors 2`] = `Array []`;

exports[`API should work when using configured manually: console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
Expand Down
57 changes: 57 additions & 0 deletions test/e2e/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,63 @@ describe("API", () => {
await server.stop();
});

it(`should work and allow to rerun dev server multiple times`, async () => {
const compiler = webpack(config);
const server = new Server({ port }, compiler);

await server.start();

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

const firstPageErrors = [];
const firstConsoleMessages = [];

firstPage
.on("console", (message) => {
firstConsoleMessages.push(message);
})
.on("pageerror", (error) => {
firstPageErrors.push(error);
});

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

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

await server.stop();
await server.start();

const secondPage = await browser.newPage();

const secondPageErrors = [];
const secondConsoleMessages = [];

secondPage
.on("console", (message) => {
secondConsoleMessages.push(message);
})
.on("pageerror", (error) => {
secondPageErrors.push(error);
});

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

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

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

it("should work with deprecated API ('listen' and `close` methods)", async () => {
const compiler = webpack(config);
const devServerOptions = { port };
Expand Down

0 comments on commit 5e6a387

Please sign in to comment.