|
1 | 1 | "use strict";
|
2 | 2 |
|
| 3 | +const path = require("path"); |
3 | 4 | const webpack = require("webpack");
|
4 | 5 | const Server = require("../../lib/Server");
|
5 | 6 | const config = require("../fixtures/client-config/webpack.config");
|
6 | 7 | const workerConfig = require("../fixtures/worker-config/webpack.config");
|
| 8 | +const workerConfigDevServerFalse = require("../fixtures/worker-config-dev-server-false/webpack.config"); |
7 | 9 | const runBrowser = require("../helpers/run-browser");
|
8 | 10 | const port = require("../ports-map").target;
|
9 | 11 |
|
@@ -35,10 +37,7 @@ describe("target", () => {
|
35 | 37 | }
|
36 | 38 | : {}),
|
37 | 39 | });
|
38 |
| - const devServerOptions = { |
39 |
| - port, |
40 |
| - }; |
41 |
| - const server = new Server(devServerOptions, compiler); |
| 40 | + const server = new Server({ port }, compiler); |
42 | 41 |
|
43 | 42 | await server.start();
|
44 | 43 |
|
@@ -93,10 +92,55 @@ describe("target", () => {
|
93 | 92 |
|
94 | 93 | it("should work using multi compiler mode with `web` and `webworker` targets", async () => {
|
95 | 94 | const compiler = webpack(workerConfig);
|
96 |
| - const devServerOptions = { |
97 |
| - port, |
98 |
| - }; |
99 |
| - const server = new Server(devServerOptions, compiler); |
| 95 | + const server = new Server({ port }, compiler); |
| 96 | + |
| 97 | + await server.start(); |
| 98 | + |
| 99 | + const { page, browser } = await runBrowser(); |
| 100 | + |
| 101 | + try { |
| 102 | + const pageErrors = []; |
| 103 | + const consoleMessages = []; |
| 104 | + |
| 105 | + page |
| 106 | + .on("console", (message) => { |
| 107 | + consoleMessages.push(message); |
| 108 | + }) |
| 109 | + .on("pageerror", (error) => { |
| 110 | + pageErrors.push(error); |
| 111 | + }); |
| 112 | + |
| 113 | + await page.goto(`http://127.0.0.1:${port}/`, { |
| 114 | + waitUntil: "networkidle0", |
| 115 | + }); |
| 116 | + |
| 117 | + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( |
| 118 | + "console messages", |
| 119 | + ); |
| 120 | + |
| 121 | + expect(pageErrors).toMatchSnapshot("page errors"); |
| 122 | + } catch (error) { |
| 123 | + throw error; |
| 124 | + } finally { |
| 125 | + await browser.close(); |
| 126 | + await server.stop(); |
| 127 | + } |
| 128 | + }); |
| 129 | + |
| 130 | + it("should work using multi compiler mode with `web` and `webworker` targets with `devServer: false`", async () => { |
| 131 | + const compiler = webpack(workerConfigDevServerFalse); |
| 132 | + const server = new Server( |
| 133 | + { |
| 134 | + port, |
| 135 | + static: { |
| 136 | + directory: path.resolve( |
| 137 | + __dirname, |
| 138 | + "../fixtures/worker-config-dev-server-false/public/", |
| 139 | + ), |
| 140 | + }, |
| 141 | + }, |
| 142 | + compiler, |
| 143 | + ); |
100 | 144 |
|
101 | 145 | await server.start();
|
102 | 146 |
|
|
0 commit comments