Skip to content

Commit 539c1dd

Browse files
test: fix
1 parent ae752d9 commit 539c1dd

File tree

2 files changed

+38
-38
lines changed

2 files changed

+38
-38
lines changed

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/e2e/hot-and-live-reload.test.js

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const path = require("path");
88
const WebSocket = require("ws");
99
const SockJS = require("sockjs-client");
1010
const webpack = require("webpack");
11-
const request = require("supertest");
1211
const fs = require("graceful-fs");
1312
const Server = require("../../lib/Server");
1413
const reloadConfig = require("../fixtures/reload-config/webpack.config");
@@ -302,42 +301,44 @@ describe("hot and live reload", () => {
302301
},
303302
];
304303

304+
let browser;
305+
let server;
306+
307+
beforeEach(() => {
308+
fs.writeFileSync(cssFilePath, "body { background-color: rgb(0, 0, 255); }");
309+
});
310+
311+
afterEach(async () => {
312+
if (browser) {
313+
await browser.close();
314+
}
315+
316+
if (server) {
317+
await server.stop();
318+
}
319+
320+
fs.unlinkSync(cssFilePath);
321+
});
322+
305323
modes.forEach((mode) => {
306324
const webSocketServerTitle =
307325
mode.options && mode.options.webSocketServer
308326
? mode.options.webSocketServer
309327
: "default";
310328

311329
it(`${mode.title} (${webSocketServerTitle})`, async () => {
312-
fs.writeFileSync(
313-
cssFilePath,
314-
"body { background-color: rgb(0, 0, 255); }"
315-
);
316-
317-
const webpackOptions = { ...reloadConfig, ...mode.webpackOptions };
330+
const webpackOptions = {
331+
...reloadConfig,
332+
...mode.webpackOptions,
333+
watchOptions: { aggregateTimeout: 2000 },
334+
};
318335
const compiler = webpack(webpackOptions);
319336
const testDevServerOptions = mode.options || {};
320-
const devServerOptions = {
321-
port,
322-
...testDevServerOptions,
323-
};
324-
const server = new Server(devServerOptions, compiler);
325-
326-
await server.start();
337+
const devServerOptions = { port, ...testDevServerOptions };
327338

328-
await new Promise((resolve, reject) => {
329-
request(`http://127.0.0.1:${devServerOptions.port}`)
330-
.get("/main")
331-
.expect(200, (error) => {
332-
if (error) {
333-
reject(error);
339+
server = new Server(devServerOptions, compiler);
334340

335-
return;
336-
}
337-
338-
resolve();
339-
});
340-
});
341+
await server.start();
341342

342343
const webSocketServerLaunched =
343344
testDevServerOptions.webSocketServer !== false;
@@ -432,7 +433,11 @@ describe("hot and live reload", () => {
432433
}
433434
});
434435

435-
const { page, browser } = await runBrowser();
436+
const launched = await runBrowser();
437+
438+
({ browser } = launched);
439+
440+
const page = launched.page;
436441

437442
const consoleMessages = [];
438443
const pageErrors = [];
@@ -561,11 +566,6 @@ describe("hot and live reload", () => {
561566

562567
expect(consoleMessages).toMatchSnapshot("console messages");
563568
expect(pageErrors).toMatchSnapshot("page errors");
564-
565-
fs.unlinkSync(cssFilePath);
566-
567-
await browser.close();
568-
await server.stop();
569569
});
570570
});
571571
});

0 commit comments

Comments
 (0)