Skip to content

Commit c5804d1

Browse files
committed
test: move lazy-compilation.test.js to Playwright
1 parent a9f7e90 commit c5804d1

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
"use strict";
2+
3+
const webpack = require("webpack");
4+
const { test } = require("@playwright/test");
5+
const { expect } = require("@playwright/test");
6+
const { describe } = require("@playwright/test");
7+
const Server = require("../../lib/Server");
8+
const lazyCompilationSingleEntryConfig = require("../fixtures/lazy-compilation-single-entry/webpack.config");
9+
const lazyCompilationMultipleEntriesConfig = require("../fixtures/lazy-compilation-multiple-entries/webpack.config");
10+
const port = require("../ports-map")["lazy-compilation"];
11+
12+
describe("lazy compilation", () => {
13+
// TODO jest freeze due webpack do not close `eventsource`, we should uncomment this after fix it on webpack side
14+
test.skip(`should work with single entry`, async ({ page }) => {
15+
const compiler = webpack(lazyCompilationSingleEntryConfig);
16+
const server = new Server({ port }, compiler);
17+
18+
await server.start();
19+
20+
try {
21+
const pageErrors = [];
22+
const consoleMessages = [];
23+
24+
page
25+
.on("console", (message) => {
26+
consoleMessages.push(message.text());
27+
})
28+
.on("pageerror", (error) => {
29+
pageErrors.push(error);
30+
});
31+
32+
await page.goto(`http://127.0.0.1:${port}/test.html`, {
33+
waitUntil: "domcontentloaded",
34+
});
35+
await new Promise((resolve) => {
36+
const interval = setInterval(() => {
37+
if (consoleMessages.includes("Hey.")) {
38+
clearInterval(interval);
39+
40+
resolve();
41+
}
42+
}, 100);
43+
});
44+
45+
expect(JSON.stringify(consoleMessages)).toMatchSnapshot();
46+
expect(JSON.stringify(pageErrors)).toMatchSnapshot();
47+
} catch (error) {
48+
throw error;
49+
} finally {
50+
await server.stop();
51+
}
52+
});
53+
54+
test.skip(`should work with multiple entries`, async ({ page }) => {
55+
const compiler = webpack(lazyCompilationMultipleEntriesConfig);
56+
const server = new Server({ port }, compiler);
57+
58+
await server.start();
59+
60+
try {
61+
const pageErrors = [];
62+
const consoleMessages = [];
63+
64+
page
65+
.on("console", (message) => {
66+
consoleMessages.push(message.text());
67+
})
68+
.on("pageerror", (error) => {
69+
pageErrors.push(error);
70+
});
71+
72+
await page.goto(`http://127.0.0.1:${port}/test-one.html`, {
73+
waitUntil: "domcontentloaded",
74+
});
75+
await new Promise((resolve) => {
76+
const interval = setInterval(() => {
77+
console.log(consoleMessages);
78+
if (consoleMessages.includes("One.")) {
79+
clearInterval(interval);
80+
81+
resolve();
82+
}
83+
}, 100);
84+
});
85+
86+
await page.goto(`http://127.0.0.1:${port}/test-two.html`, {
87+
waitUntil: "domcontentloaded",
88+
});
89+
await new Promise((resolve) => {
90+
const interval = setInterval(() => {
91+
console.log(consoleMessages);
92+
if (consoleMessages.includes("Two.")) {
93+
clearInterval(interval);
94+
95+
resolve();
96+
}
97+
}, 100);
98+
});
99+
100+
expect(JSON.stringify(consoleMessages)).toMatchSnapshot();
101+
expect(JSON.stringify(pageErrors)).toMatchSnapshot();
102+
} catch (error) {
103+
throw error;
104+
} finally {
105+
await server.stop();
106+
}
107+
});
108+
});

0 commit comments

Comments
 (0)