|
3 | 3 | const webpack = require("webpack");
|
4 | 4 | const Server = require("../../lib/Server");
|
5 | 5 | const config = require("../fixtures/client-config/webpack.config");
|
| 6 | +const multiCompilerConfig = require("../fixtures/multi-compiler-config/webpack.config"); |
6 | 7 | const runBrowser = require("../helpers/run-browser");
|
7 | 8 | const isWebpack5 = require("../helpers/isWebpack5");
|
8 | 9 | const port = require("../ports-map")["magic-html-option"];
|
@@ -223,6 +224,86 @@ describe("magicHtml option", () => {
|
223 | 224 | expect(pageErrors).toMatchSnapshot("page errors");
|
224 | 225 | });
|
225 | 226 | });
|
| 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 | + }); |
226 | 307 | });
|
227 | 308 |
|
228 | 309 | webpack5Test("enabled with experiments.outputModule: true", () => {
|
@@ -317,6 +398,104 @@ describe("magicHtml option", () => {
|
317 | 398 | });
|
318 | 399 | });
|
319 | 400 |
|
| 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 | + |
320 | 499 | webpack5Test(
|
321 | 500 | "enabled with experiments.outputModule: true and .js extension",
|
322 | 501 | () => {
|
@@ -538,6 +717,98 @@ describe("magicHtml option", () => {
|
538 | 717 | expect(pageErrors).toMatchSnapshot("page errors");
|
539 | 718 | });
|
540 | 719 | });
|
| 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 | + }); |
541 | 812 | }
|
542 | 813 | );
|
543 | 814 |
|
|
0 commit comments