Skip to content

Commit 27d0e8e

Browse files
test: added
1 parent 68970bd commit 27d0e8e

File tree

7 files changed

+129
-9
lines changed

7 files changed

+129
-9
lines changed

.cspell.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@
6666
"hoge",
6767
"subsubcomain",
6868
"noselect",
69-
"commitlint"
69+
"commitlint",
70+
"eslintcache"
7071
],
7172
"ignorePaths": [
7273
"CHANGELOG.md",

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ test/fixtures/static-config/public/assets/non-exist.txt
2020
test/fixtures/watch-files-config/public/assets/non-exist.txt
2121
test/fixtures/reload-config/main.css
2222
test/fixtures/reload-config-2/main.css
23+
test/fixtures/worker-config-dev-server-false/public
2324
!/test/fixtures/static-config/public/node_modules

test/e2e/__snapshots__/target.test.js.snap.webpack5

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ exports[`target should work using "webworker" target: console messages 1`] = `
7272

7373
exports[`target should work using "webworker" target: page errors 1`] = `[]`;
7474

75+
exports[`target should work using multi compiler mode with \`web\` and \`webworker\` targets with \`devServer: false\`: console messages 1`] = `
76+
[
77+
"[webpack-dev-server] Server started: Hot Module Replacement enabled, Live Reloading enabled, Progress disabled, Overlay enabled.",
78+
"[HMR] Waiting for update signal from WDS...",
79+
"Worker said: I'm working before postMessage",
80+
"Worker said: Message sent: message",
81+
]
82+
`;
83+
84+
exports[`target should work using multi compiler mode with \`web\` and \`webworker\` targets with \`devServer: false\`: page errors 1`] = `[]`;
85+
7586
exports[`target should work using multi compiler mode with \`web\` and \`webworker\` targets: console messages 1`] = `
7687
[
7788
"[webpack-dev-server] Server started: Hot Module Replacement enabled, Live Reloading enabled, Progress disabled, Overlay enabled.",

test/e2e/target.test.js

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
"use strict";
22

3+
const path = require("path");
34
const webpack = require("webpack");
45
const Server = require("../../lib/Server");
56
const config = require("../fixtures/client-config/webpack.config");
67
const workerConfig = require("../fixtures/worker-config/webpack.config");
8+
const workerConfigDevServerFalse = require("../fixtures/worker-config-dev-server-false/webpack.config");
79
const runBrowser = require("../helpers/run-browser");
810
const port = require("../ports-map").target;
911

@@ -35,10 +37,7 @@ describe("target", () => {
3537
}
3638
: {}),
3739
});
38-
const devServerOptions = {
39-
port,
40-
};
41-
const server = new Server(devServerOptions, compiler);
40+
const server = new Server({ port }, compiler);
4241

4342
await server.start();
4443

@@ -93,10 +92,55 @@ describe("target", () => {
9392

9493
it("should work using multi compiler mode with `web` and `webworker` targets", async () => {
9594
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+
);
100144

101145
await server.start();
102146

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"use strict";
2+
3+
const myWorker = new Worker("./worker-bundle.js");
4+
5+
myWorker.onmessage = (event) => {
6+
console.log(`Worker said: ${event.data}`);
7+
};
8+
9+
myWorker.postMessage("message");
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"use strict";
2+
3+
const path = require("path");
4+
const HTMLGeneratorPlugin = require("../../helpers/html-generator-plugin");
5+
6+
module.exports = [
7+
{
8+
name: "app",
9+
// dependencies: ["worker"],
10+
devtool: false,
11+
target: "web",
12+
entry: "./index.js",
13+
mode: "development",
14+
context: __dirname,
15+
stats: "none",
16+
output: {
17+
path: path.resolve(__dirname, "./dist/"),
18+
},
19+
infrastructureLogging: {
20+
level: "info",
21+
stream: {
22+
write: () => {},
23+
},
24+
},
25+
plugins: [new HTMLGeneratorPlugin()],
26+
},
27+
{
28+
name: "worker",
29+
devtool: false,
30+
target: "webworker",
31+
entry: "./worker.js",
32+
mode: "development",
33+
context: __dirname,
34+
stats: "none",
35+
output: {
36+
path: path.resolve(__dirname, "public"),
37+
filename: "worker-bundle.js",
38+
},
39+
infrastructureLogging: {
40+
level: "info",
41+
stream: {
42+
write: () => {},
43+
},
44+
},
45+
devServer: false,
46+
},
47+
];
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"use strict";
2+
3+
postMessage("I'm working before postMessage");
4+
5+
onmessage = (event) => {
6+
postMessage(`Message sent: ${event.data}`);
7+
};

0 commit comments

Comments
 (0)