Skip to content

Commit 4972bd1

Browse files
committed
test: add e2e test for universal compiler
1 parent 1923132 commit 4972bd1

File tree

4 files changed

+121
-50
lines changed

4 files changed

+121
-50
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Universal compiler client bundle should have the inlined the client runtime: console messages 1`] = `Array []`;
4+
5+
exports[`Universal compiler client bundle should have the inlined the client runtime: page errors 1`] = `Array []`;
6+
7+
exports[`Universal compiler server bundle should NOT have the inlined the client runtime: console messages 1`] = `Array []`;
8+
9+
exports[`Universal compiler server bundle should NOT have the inlined the client runtime: page errors 1`] = `Array []`;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Universal compiler client bundle should have the inlined the client runtime: console messages 1`] = `Array []`;
4+
5+
exports[`Universal compiler client bundle should have the inlined the client runtime: page errors 1`] = `Array []`;
6+
7+
exports[`Universal compiler server bundle should NOT have the inlined the client runtime: console messages 1`] = `Array []`;
8+
9+
exports[`Universal compiler server bundle should NOT have the inlined the client runtime: page errors 1`] = `Array []`;

test/e2e/universal-compiler.test.js

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
"use strict";
2+
3+
const webpack = require("webpack");
4+
const Server = require("../../lib/Server");
5+
const config = require("../fixtures/universal-compiler-config/webpack.config");
6+
const runBrowser = require("../helpers/run-browser");
7+
const port = require("../ports-map")["universal-compiler"];
8+
9+
describe("Universal compiler", () => {
10+
it("client bundle should have the inlined the client runtime", async () => {
11+
const compiler = webpack(config);
12+
const devServerOptions = {
13+
host: "127.0.0.1",
14+
port,
15+
};
16+
const server = new Server(devServerOptions, compiler);
17+
18+
await server.start();
19+
20+
const { page, browser } = await runBrowser();
21+
22+
const pageErrors = [];
23+
const consoleMessages = [];
24+
25+
page
26+
.on("console", (message) => {
27+
consoleMessages.push(message);
28+
})
29+
.on("pageerror", (error) => {
30+
pageErrors.push(error);
31+
});
32+
33+
await page.goto(`http://127.0.0.1:${port}/client.js`, {
34+
waitUntil: "networkidle0",
35+
});
36+
37+
const bodyHandle = await page.$("body");
38+
const htmlContent = await page.evaluate(
39+
(body) => body.innerHTML,
40+
bodyHandle
41+
);
42+
43+
expect(htmlContent).toContain("Hello from the client");
44+
expect(htmlContent).toContain("WebsocketClient");
45+
46+
expect(consoleMessages.map((message) => message.text())).toMatchSnapshot(
47+
"console messages"
48+
);
49+
50+
expect(pageErrors).toMatchSnapshot("page errors");
51+
52+
await browser.close();
53+
await server.close();
54+
});
55+
56+
it("server bundle should NOT have the inlined the client runtime", async () => {
57+
// we wouldn't normally request a server bundle
58+
// but we'll do it here to check the contents
59+
const compiler = webpack(config);
60+
const devServerOptions = {
61+
host: "127.0.0.1",
62+
port,
63+
};
64+
const server = new Server(devServerOptions, compiler);
65+
66+
await server.start();
67+
68+
const { page, browser } = await runBrowser();
69+
70+
const pageErrors = [];
71+
const consoleMessages = [];
72+
73+
page
74+
.on("console", (message) => {
75+
consoleMessages.push(message);
76+
})
77+
.on("pageerror", (error) => {
78+
pageErrors.push(error);
79+
});
80+
81+
await page.goto(`http://127.0.0.1:${port}/server.js`, {
82+
waitUntil: "networkidle0",
83+
});
84+
85+
const bodyHandle = await page.$("body");
86+
const htmlContent = await page.evaluate(
87+
(body) => body.innerHTML,
88+
bodyHandle
89+
);
90+
91+
expect(htmlContent).toContain("Hello from the server");
92+
expect(htmlContent).not.toContain("WebsocketServer");
93+
94+
expect(consoleMessages.map((message) => message.text())).toMatchSnapshot(
95+
"console messages"
96+
);
97+
98+
expect(pageErrors).toMatchSnapshot("page errors");
99+
100+
await browser.close();
101+
await server.close();
102+
});
103+
});

test/integration/UniversalCompiler.test.js

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)