Skip to content

test: add e2e test for WEBPACK_SERVE env variable #4125

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

Merged
merged 1 commit into from
Dec 21, 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
13 changes: 13 additions & 0 deletions test/e2e/__snapshots__/api.test.js.snap.webpack4
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,19 @@ exports[`API Server.getFreePort should return the port when the port is undefine

exports[`API Server.getFreePort should throw the error when the port isn't found 1`] = `"busy"`;

exports[`API WEBPACK_SERVE environment variable should be present: 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 WEBPACK_SERVE environment variable should be present: page errors 1`] = `Array []`;

exports[`API WEBPACK_SERVE environment variable should be present: response status 1`] = `200`;

exports[`API deprecated API should log warning when the "port" and "host" options from options different from arguments ('listen' method): console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
Expand Down
13 changes: 13 additions & 0 deletions test/e2e/__snapshots__/api.test.js.snap.webpack5
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,19 @@ exports[`API Server.getFreePort should return the port when the port is undefine

exports[`API Server.getFreePort should throw the error when the port isn't found 1`] = `"busy"`;

exports[`API WEBPACK_SERVE environment variable should be present: 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 WEBPACK_SERVE environment variable should be present: page errors 1`] = `Array []`;

exports[`API WEBPACK_SERVE environment variable should be present: response status 1`] = `200`;

exports[`API deprecated API should log warning when the "port" and "host" options from options different from arguments ('listen' method): console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
Expand Down
62 changes: 62 additions & 0 deletions test/e2e/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,68 @@ const runBrowser = require("../helpers/run-browser");
const port = require("../ports-map").api;

describe("API", () => {
describe("WEBPACK_SERVE environment variable", () => {
const OLD_ENV = process.env;
let server;
let page;
let browser;
let pageErrors;
let consoleMessages;

beforeEach(async () => {
// this is important - it clears the cache
jest.resetModules();

process.env = { ...OLD_ENV };

delete process.env.WEBPACK_SERVE;

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

pageErrors = [];
consoleMessages = [];
});

afterEach(async () => {
await browser.close();
await server.stop();
process.env = OLD_ENV;
});

it("should be present", async () => {
expect(process.env.WEBPACK_SERVE).toBeUndefined();

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

const WebpackDevServer = require("../../lib/Server");

const compiler = webpack(config);
server = new WebpackDevServer({ port }, compiler);

await server.start();

expect(process.env.WEBPACK_SERVE).toBe(true);

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

expect(response.status()).toMatchSnapshot("response status");

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

expect(pageErrors).toMatchSnapshot("page errors");
});
});

describe("latest async API", () => {
it(`should work with async API`, async () => {
const compiler = webpack(config);
Expand Down
25 changes: 0 additions & 25 deletions test/server/Server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,29 +161,4 @@ describe("Server", () => {
await server.stop();
});
});

describe("WEBPACK_SERVE environment variable", () => {
const OLD_ENV = process.env;

beforeEach(() => {
// this is important - it clears the cache
jest.resetModules();

process.env = { ...OLD_ENV };

delete process.env.WEBPACK_SERVE;
});

afterEach(() => {
process.env = OLD_ENV;
});

it("should be present", () => {
expect(process.env.WEBPACK_SERVE).toBeUndefined();

require("../../lib/Server");

expect(process.env.WEBPACK_SERVE).toBe(true);
});
});
});