Skip to content

Commit

Permalink
test: multi compiler mode
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Sep 10, 2021
1 parent 458bd21 commit d34171f
Show file tree
Hide file tree
Showing 2 changed files with 349 additions and 0 deletions.
78 changes: 78 additions & 0 deletions test/e2e/__snapshots__/magic-html.test.js.snap.webpack5
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,33 @@ exports[`magicHtml option enabled filename bundle.other.js should not handle GET
"
`;

exports[`magicHtml option enabled multi compiler mode should handle GET request to magic async html (/main): 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[`magicHtml option enabled multi compiler mode should handle GET request to magic async html (/main): page errors 1`] = `Array []`;

exports[`magicHtml option enabled multi compiler mode should handle GET request to magic async html (/main): response headers content-type 1`] = `"text/html; charset=utf-8"`;

exports[`magicHtml option enabled multi compiler mode should handle GET request to magic async html (/main): response status 1`] = `200`;

exports[`magicHtml option enabled multi compiler mode should handle GET request to magic async html (/main): response text 1`] = `"<!DOCTYPE html><html><head><meta charset=\\"utf-8\\"/></head><body><script type=\\"text/javascript\\" charset=\\"utf-8\\" src=\\"/main.js\\"></script></body></html>"`;

exports[`magicHtml option enabled multi compiler mode should handle HEAD request to magic async html (/main): console messages 1`] = `Array []`;

exports[`magicHtml option enabled multi compiler mode should handle HEAD request to magic async html (/main): page errors 1`] = `Array []`;

exports[`magicHtml option enabled multi compiler mode should handle HEAD request to magic async html (/main): response headers content-type 1`] = `"text/html; charset=utf-8"`;

exports[`magicHtml option enabled multi compiler mode should handle HEAD request to magic async html (/main): response status 1`] = `200`;

exports[`magicHtml option enabled multi compiler mode should handle HEAD request to magic async html (/main): response text 1`] = `""`;

exports[`magicHtml option enabled with experiments.outputModule: false filename bundle.js should handle GET request to magic async html (/bundle): console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
Expand Down Expand Up @@ -346,6 +373,57 @@ exports[`magicHtml option enabled with experiments.outputModule: true and .js ex
"
`;

exports[`magicHtml option enabled with experiments.outputModule: true and .js extension multi compiler mode should handle GET request to magic async html (/bundle): console messages 1`] = `Array []`;

exports[`magicHtml option enabled with experiments.outputModule: true and .js extension multi compiler mode should handle GET request to magic async html (/bundle): page errors 1`] = `
Array [
[Error: SyntaxError: Cannot use 'import.meta' outside a module],
]
`;

exports[`magicHtml option enabled with experiments.outputModule: true and .js extension multi compiler mode should handle GET request to magic async html (/bundle): response headers content-type 1`] = `"text/html; charset=utf-8"`;

exports[`magicHtml option enabled with experiments.outputModule: true and .js extension multi compiler mode should handle GET request to magic async html (/bundle): response status 1`] = `200`;

exports[`magicHtml option enabled with experiments.outputModule: true and .js extension multi compiler mode should handle GET request to magic async html (/bundle): response text 1`] = `"<!DOCTYPE html><html><head><meta charset=\\"utf-8\\"/></head><body><script type=\\"text/javascript\\" charset=\\"utf-8\\" src=\\"/bundle.js\\"></script></body></html>"`;

exports[`magicHtml option enabled with experiments.outputModule: true and .js extension multi compiler mode should handle HEAD request to magic async html (/bundle): console messages 1`] = `Array []`;

exports[`magicHtml option enabled with experiments.outputModule: true and .js extension multi compiler mode should handle HEAD request to magic async html (/bundle): page errors 1`] = `Array []`;

exports[`magicHtml option enabled with experiments.outputModule: true and .js extension multi compiler mode should handle HEAD request to magic async html (/bundle): response headers content-type 1`] = `"text/html; charset=utf-8"`;

exports[`magicHtml option enabled with experiments.outputModule: true and .js extension multi compiler mode should handle HEAD request to magic async html (/bundle): response status 1`] = `200`;

exports[`magicHtml option enabled with experiments.outputModule: true and .js extension multi compiler mode should handle HEAD request to magic async html (/bundle): response text 1`] = `""`;

exports[`magicHtml option enabled with experiments.outputModule: true in multi compiler mode should handle GET request to magic async html (/main): 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[`magicHtml option enabled with experiments.outputModule: true in multi compiler mode should handle GET request to magic async html (/main): page errors 1`] = `Array []`;

exports[`magicHtml option enabled with experiments.outputModule: true in multi compiler mode should handle GET request to magic async html (/main): response headers content-type 1`] = `"text/html; charset=utf-8"`;

exports[`magicHtml option enabled with experiments.outputModule: true in multi compiler mode should handle GET request to magic async html (/main): response status 1`] = `200`;

exports[`magicHtml option enabled with experiments.outputModule: true in multi compiler mode should handle GET request to magic async html (/main): response text 1`] = `"<!DOCTYPE html><html><head><meta charset=\\"utf-8\\"/></head><body><script type=\\"module\\" charset=\\"utf-8\\" src=\\"/main.mjs\\"></script></body></html>"`;

exports[`magicHtml option enabled with experiments.outputModule: true in multi compiler mode should handle HEAD request to magic async html (/main): console messages 1`] = `Array []`;

exports[`magicHtml option enabled with experiments.outputModule: true in multi compiler mode should handle HEAD request to magic async html (/main): page errors 1`] = `Array []`;

exports[`magicHtml option enabled with experiments.outputModule: true in multi compiler mode should handle HEAD request to magic async html (/main): response headers content-type 1`] = `"text/html; charset=utf-8"`;

exports[`magicHtml option enabled with experiments.outputModule: true in multi compiler mode should handle HEAD request to magic async html (/main): response status 1`] = `200`;

exports[`magicHtml option enabled with experiments.outputModule: true in multi compiler mode should handle HEAD request to magic async html (/main): response text 1`] = `""`;

exports[`magicHtml option enabled with experiments.outputModule: true should handle GET request to magic async html (/main): console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
Expand Down
271 changes: 271 additions & 0 deletions test/e2e/magic-html.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const webpack = require("webpack");
const Server = require("../../lib/Server");
const config = require("../fixtures/client-config/webpack.config");
const multiCompilerConfig = require("../fixtures/multi-compiler-config/webpack.config");
const runBrowser = require("../helpers/run-browser");
const isWebpack5 = require("../helpers/isWebpack5");
const port = require("../ports-map")["magic-html-option"];
Expand Down Expand Up @@ -223,6 +224,86 @@ describe("magicHtml option", () => {
expect(pageErrors).toMatchSnapshot("page errors");
});
});

describe("multi compiler mode", () => {
beforeEach(async () => {
compiler = webpack(multiCompilerConfig);
server = new Server({ port, magicHtml: true }, compiler);

await server.start();

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

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

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

it("should handle GET request to magic async html (/main)", async () => {
page
.on("console", (message) => {
consoleMessages.push(message);
})
.on("pageerror", (error) => {
pageErrors.push(error);
});

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

expect(response.headers()["content-type"]).toMatchSnapshot(
"response headers content-type"
);

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

expect(await response.text()).toMatchSnapshot("response text");

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

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

it("should handle HEAD request to magic async html (/main)", async () => {
await page.setRequestInterception(true);

page
.on("console", (message) => {
consoleMessages.push(message);
})
.on("pageerror", (error) => {
pageErrors.push(error);
})
.on("request", (interceptedRequest) => {
interceptedRequest.continue({ method: "HEAD" });
});

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

expect(response.headers()["content-type"]).toMatchSnapshot(
"response headers content-type"
);

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

expect(await response.text()).toMatchSnapshot("response text");

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

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

webpack5Test("enabled with experiments.outputModule: true", () => {
Expand Down Expand Up @@ -317,6 +398,104 @@ describe("magicHtml option", () => {
});
});

webpack5Test(
"enabled with experiments.outputModule: true in multi compiler mode",
() => {
let compiler;
let server;
let page;
let browser;
let pageErrors;
let consoleMessages;

beforeEach(async () => {
compiler = webpack([
{
...multiCompilerConfig[0],
experiments: {
outputModule: true,
},
},
config,
]);
server = new Server({ port, magicHtml: true }, compiler);

await server.start();

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

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

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

it("should handle GET request to magic async html (/main)", async () => {
page
.on("console", (message) => {
consoleMessages.push(message);
})
.on("pageerror", (error) => {
pageErrors.push(error);
});

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

expect(response.headers()["content-type"]).toMatchSnapshot(
"response headers content-type"
);

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

expect(await response.text()).toMatchSnapshot("response text");

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

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

it("should handle HEAD request to magic async html (/main)", async () => {
await page.setRequestInterception(true);

page
.on("console", (message) => {
consoleMessages.push(message);
})
.on("pageerror", (error) => {
pageErrors.push(error);
})
.on("request", (interceptedRequest) => {
interceptedRequest.continue({ method: "HEAD" });
});

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

expect(response.headers()["content-type"]).toMatchSnapshot(
"response headers content-type"
);

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

expect(await response.text()).toMatchSnapshot("response text");

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

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

webpack5Test(
"enabled with experiments.outputModule: true and .js extension",
() => {
Expand Down Expand Up @@ -538,6 +717,98 @@ describe("magicHtml option", () => {
expect(pageErrors).toMatchSnapshot("page errors");
});
});

describe("multi compiler mode", () => {
beforeEach(async () => {
compiler = webpack([
{
...multiCompilerConfig[0],
output: {
path: "/",
filename: "bundle.js",
},
experiments: {
outputModule: true,
},
},
config,
]);
server = new Server({ port, magicHtml: true }, compiler);

await server.start();

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

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

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

it("should handle GET request to magic async html (/bundle)", async () => {
page
.on("console", (message) => {
consoleMessages.push(message);
})
.on("pageerror", (error) => {
pageErrors.push(error);
});

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

expect(response.headers()["content-type"]).toMatchSnapshot(
"response headers content-type"
);

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

expect(await response.text()).toMatchSnapshot("response text");

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

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

it("should handle HEAD request to magic async html (/bundle)", async () => {
await page.setRequestInterception(true);

page
.on("console", (message) => {
consoleMessages.push(message);
})
.on("pageerror", (error) => {
pageErrors.push(error);
})
.on("request", (interceptedRequest) => {
interceptedRequest.continue({ method: "HEAD" });
});

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

expect(response.headers()["content-type"]).toMatchSnapshot(
"response headers content-type"
);

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

expect(await response.text()).toMatchSnapshot("response text");

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

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

Expand Down

0 comments on commit d34171f

Please sign in to comment.