Skip to content

Commit d34171f

Browse files
committed
test: multi compiler mode
1 parent 458bd21 commit d34171f

File tree

2 files changed

+349
-0
lines changed

2 files changed

+349
-0
lines changed

test/e2e/__snapshots__/magic-html.test.js.snap.webpack5

+78
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,33 @@ exports[`magicHtml option enabled filename bundle.other.js should not handle GET
186186
"
187187
`;
188188

189+
exports[`magicHtml option enabled multi compiler mode should handle GET request to magic async html (/main): console messages 1`] = `
190+
Array [
191+
"[HMR] Waiting for update signal from WDS...",
192+
"Hey.",
193+
"[webpack-dev-server] Hot Module Replacement enabled.",
194+
"[webpack-dev-server] Live Reloading enabled.",
195+
]
196+
`;
197+
198+
exports[`magicHtml option enabled multi compiler mode should handle GET request to magic async html (/main): page errors 1`] = `Array []`;
199+
200+
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"`;
201+
202+
exports[`magicHtml option enabled multi compiler mode should handle GET request to magic async html (/main): response status 1`] = `200`;
203+
204+
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>"`;
205+
206+
exports[`magicHtml option enabled multi compiler mode should handle HEAD request to magic async html (/main): console messages 1`] = `Array []`;
207+
208+
exports[`magicHtml option enabled multi compiler mode should handle HEAD request to magic async html (/main): page errors 1`] = `Array []`;
209+
210+
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"`;
211+
212+
exports[`magicHtml option enabled multi compiler mode should handle HEAD request to magic async html (/main): response status 1`] = `200`;
213+
214+
exports[`magicHtml option enabled multi compiler mode should handle HEAD request to magic async html (/main): response text 1`] = `""`;
215+
189216
exports[`magicHtml option enabled with experiments.outputModule: false filename bundle.js should handle GET request to magic async html (/bundle): console messages 1`] = `
190217
Array [
191218
"[HMR] Waiting for update signal from WDS...",
@@ -346,6 +373,57 @@ exports[`magicHtml option enabled with experiments.outputModule: true and .js ex
346373
"
347374
`;
348375

376+
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 []`;
377+
378+
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`] = `
379+
Array [
380+
[Error: SyntaxError: Cannot use 'import.meta' outside a module],
381+
]
382+
`;
383+
384+
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"`;
385+
386+
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`;
387+
388+
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>"`;
389+
390+
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 []`;
391+
392+
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 []`;
393+
394+
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"`;
395+
396+
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`;
397+
398+
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`] = `""`;
399+
400+
exports[`magicHtml option enabled with experiments.outputModule: true in multi compiler mode should handle GET request to magic async html (/main): console messages 1`] = `
401+
Array [
402+
"[HMR] Waiting for update signal from WDS...",
403+
"Hey.",
404+
"[webpack-dev-server] Hot Module Replacement enabled.",
405+
"[webpack-dev-server] Live Reloading enabled.",
406+
]
407+
`;
408+
409+
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 []`;
410+
411+
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"`;
412+
413+
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`;
414+
415+
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>"`;
416+
417+
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 []`;
418+
419+
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 []`;
420+
421+
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"`;
422+
423+
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`;
424+
425+
exports[`magicHtml option enabled with experiments.outputModule: true in multi compiler mode should handle HEAD request to magic async html (/main): response text 1`] = `""`;
426+
349427
exports[`magicHtml option enabled with experiments.outputModule: true should handle GET request to magic async html (/main): console messages 1`] = `
350428
Array [
351429
"[HMR] Waiting for update signal from WDS...",

test/e2e/magic-html.test.js

+271
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const webpack = require("webpack");
44
const Server = require("../../lib/Server");
55
const config = require("../fixtures/client-config/webpack.config");
6+
const multiCompilerConfig = require("../fixtures/multi-compiler-config/webpack.config");
67
const runBrowser = require("../helpers/run-browser");
78
const isWebpack5 = require("../helpers/isWebpack5");
89
const port = require("../ports-map")["magic-html-option"];
@@ -223,6 +224,86 @@ describe("magicHtml option", () => {
223224
expect(pageErrors).toMatchSnapshot("page errors");
224225
});
225226
});
227+
228+
describe("multi compiler mode", () => {
229+
beforeEach(async () => {
230+
compiler = webpack(multiCompilerConfig);
231+
server = new Server({ port, magicHtml: true }, compiler);
232+
233+
await server.start();
234+
235+
({ page, browser } = await runBrowser());
236+
237+
pageErrors = [];
238+
consoleMessages = [];
239+
});
240+
241+
afterEach(async () => {
242+
await browser.close();
243+
await server.stop();
244+
});
245+
246+
it("should handle GET request to magic async html (/main)", async () => {
247+
page
248+
.on("console", (message) => {
249+
consoleMessages.push(message);
250+
})
251+
.on("pageerror", (error) => {
252+
pageErrors.push(error);
253+
});
254+
255+
const response = await page.goto(`http://127.0.0.1:${port}/main`, {
256+
waitUntil: "networkidle0",
257+
});
258+
259+
expect(response.headers()["content-type"]).toMatchSnapshot(
260+
"response headers content-type"
261+
);
262+
263+
expect(response.status()).toMatchSnapshot("response status");
264+
265+
expect(await response.text()).toMatchSnapshot("response text");
266+
267+
expect(
268+
consoleMessages.map((message) => message.text())
269+
).toMatchSnapshot("console messages");
270+
271+
expect(pageErrors).toMatchSnapshot("page errors");
272+
});
273+
274+
it("should handle HEAD request to magic async html (/main)", async () => {
275+
await page.setRequestInterception(true);
276+
277+
page
278+
.on("console", (message) => {
279+
consoleMessages.push(message);
280+
})
281+
.on("pageerror", (error) => {
282+
pageErrors.push(error);
283+
})
284+
.on("request", (interceptedRequest) => {
285+
interceptedRequest.continue({ method: "HEAD" });
286+
});
287+
288+
const response = await page.goto(`http://127.0.0.1:${port}/main`, {
289+
waitUntil: "networkidle0",
290+
});
291+
292+
expect(response.headers()["content-type"]).toMatchSnapshot(
293+
"response headers content-type"
294+
);
295+
296+
expect(response.status()).toMatchSnapshot("response status");
297+
298+
expect(await response.text()).toMatchSnapshot("response text");
299+
300+
expect(
301+
consoleMessages.map((message) => message.text())
302+
).toMatchSnapshot("console messages");
303+
304+
expect(pageErrors).toMatchSnapshot("page errors");
305+
});
306+
});
226307
});
227308

228309
webpack5Test("enabled with experiments.outputModule: true", () => {
@@ -317,6 +398,104 @@ describe("magicHtml option", () => {
317398
});
318399
});
319400

401+
webpack5Test(
402+
"enabled with experiments.outputModule: true in multi compiler mode",
403+
() => {
404+
let compiler;
405+
let server;
406+
let page;
407+
let browser;
408+
let pageErrors;
409+
let consoleMessages;
410+
411+
beforeEach(async () => {
412+
compiler = webpack([
413+
{
414+
...multiCompilerConfig[0],
415+
experiments: {
416+
outputModule: true,
417+
},
418+
},
419+
config,
420+
]);
421+
server = new Server({ port, magicHtml: true }, compiler);
422+
423+
await server.start();
424+
425+
({ page, browser } = await runBrowser());
426+
427+
pageErrors = [];
428+
consoleMessages = [];
429+
});
430+
431+
afterEach(async () => {
432+
await browser.close();
433+
await server.stop();
434+
});
435+
436+
it("should handle GET request to magic async html (/main)", async () => {
437+
page
438+
.on("console", (message) => {
439+
consoleMessages.push(message);
440+
})
441+
.on("pageerror", (error) => {
442+
pageErrors.push(error);
443+
});
444+
445+
const response = await page.goto(`http://127.0.0.1:${port}/main`, {
446+
waitUntil: "networkidle0",
447+
});
448+
449+
expect(response.headers()["content-type"]).toMatchSnapshot(
450+
"response headers content-type"
451+
);
452+
453+
expect(response.status()).toMatchSnapshot("response status");
454+
455+
expect(await response.text()).toMatchSnapshot("response text");
456+
457+
expect(
458+
consoleMessages.map((message) => message.text())
459+
).toMatchSnapshot("console messages");
460+
461+
expect(pageErrors).toMatchSnapshot("page errors");
462+
});
463+
464+
it("should handle HEAD request to magic async html (/main)", async () => {
465+
await page.setRequestInterception(true);
466+
467+
page
468+
.on("console", (message) => {
469+
consoleMessages.push(message);
470+
})
471+
.on("pageerror", (error) => {
472+
pageErrors.push(error);
473+
})
474+
.on("request", (interceptedRequest) => {
475+
interceptedRequest.continue({ method: "HEAD" });
476+
});
477+
478+
const response = await page.goto(`http://127.0.0.1:${port}/main`, {
479+
waitUntil: "networkidle0",
480+
});
481+
482+
expect(response.headers()["content-type"]).toMatchSnapshot(
483+
"response headers content-type"
484+
);
485+
486+
expect(response.status()).toMatchSnapshot("response status");
487+
488+
expect(await response.text()).toMatchSnapshot("response text");
489+
490+
expect(
491+
consoleMessages.map((message) => message.text())
492+
).toMatchSnapshot("console messages");
493+
494+
expect(pageErrors).toMatchSnapshot("page errors");
495+
});
496+
}
497+
);
498+
320499
webpack5Test(
321500
"enabled with experiments.outputModule: true and .js extension",
322501
() => {
@@ -538,6 +717,98 @@ describe("magicHtml option", () => {
538717
expect(pageErrors).toMatchSnapshot("page errors");
539718
});
540719
});
720+
721+
describe("multi compiler mode", () => {
722+
beforeEach(async () => {
723+
compiler = webpack([
724+
{
725+
...multiCompilerConfig[0],
726+
output: {
727+
path: "/",
728+
filename: "bundle.js",
729+
},
730+
experiments: {
731+
outputModule: true,
732+
},
733+
},
734+
config,
735+
]);
736+
server = new Server({ port, magicHtml: true }, compiler);
737+
738+
await server.start();
739+
740+
({ page, browser } = await runBrowser());
741+
742+
pageErrors = [];
743+
consoleMessages = [];
744+
});
745+
746+
afterEach(async () => {
747+
await browser.close();
748+
await server.stop();
749+
});
750+
751+
it("should handle GET request to magic async html (/bundle)", async () => {
752+
page
753+
.on("console", (message) => {
754+
consoleMessages.push(message);
755+
})
756+
.on("pageerror", (error) => {
757+
pageErrors.push(error);
758+
});
759+
760+
const response = await page.goto(`http://127.0.0.1:${port}/bundle`, {
761+
waitUntil: "networkidle0",
762+
});
763+
764+
expect(response.headers()["content-type"]).toMatchSnapshot(
765+
"response headers content-type"
766+
);
767+
768+
expect(response.status()).toMatchSnapshot("response status");
769+
770+
expect(await response.text()).toMatchSnapshot("response text");
771+
772+
expect(
773+
consoleMessages.map((message) => message.text())
774+
).toMatchSnapshot("console messages");
775+
776+
expect(pageErrors).toMatchSnapshot("page errors");
777+
});
778+
779+
it("should handle HEAD request to magic async html (/bundle)", async () => {
780+
await page.setRequestInterception(true);
781+
782+
page
783+
.on("console", (message) => {
784+
consoleMessages.push(message);
785+
})
786+
.on("pageerror", (error) => {
787+
pageErrors.push(error);
788+
})
789+
.on("request", (interceptedRequest) => {
790+
interceptedRequest.continue({ method: "HEAD" });
791+
});
792+
793+
const response = await page.goto(`http://127.0.0.1:${port}/bundle`, {
794+
waitUntil: "networkidle0",
795+
});
796+
797+
expect(response.headers()["content-type"]).toMatchSnapshot(
798+
"response headers content-type"
799+
);
800+
801+
expect(response.status()).toMatchSnapshot("response status");
802+
803+
expect(await response.text()).toMatchSnapshot("response text");
804+
805+
expect(
806+
consoleMessages.map((message) => message.text())
807+
).toMatchSnapshot("console messages");
808+
809+
expect(pageErrors).toMatchSnapshot("page errors");
810+
});
811+
});
541812
}
542813
);
543814

0 commit comments

Comments
 (0)