Skip to content

Commit a827a65

Browse files
knagaitsevevilebottnawi
authored andcommitted
test: fixed Routes test bug and added server creation helper to await compilation (#1735)
1 parent ef4297e commit a827a65

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

test/Routes.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('Routes', () => {
2121

2222
describe('without headers', () => {
2323
beforeAll((done) => {
24-
server = helper.start(config, {}, done);
24+
server = helper.startAwaitingCompilation(config, {}, done);
2525
req = request(server.app);
2626
});
2727

test/helper.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ const Server = require('../lib/Server');
66
let server;
77

88
module.exports = {
9-
start(config, options, done) {
9+
// start server, returning the full setup of the server
10+
// (both the server and the compiler)
11+
startFullSetup(config, options, done) {
1012
// eslint-disable-next-line no-undefined
1113
if (options.quiet === undefined) {
1214
options.quiet = true;
@@ -21,7 +23,28 @@ module.exports = {
2123
done();
2224
});
2325

24-
return server;
26+
return {
27+
server,
28+
compiler,
29+
};
30+
},
31+
startAwaitingCompilation(config, options, done) {
32+
let readyCount = 0;
33+
const ready = () => {
34+
readyCount += 1;
35+
if (readyCount === 2) {
36+
done();
37+
}
38+
};
39+
40+
const fullSetup = this.startFullSetup(config, options, ready);
41+
// wait for compilation, since dev server can start before this
42+
// https://github.com/webpack/webpack-dev-server/issues/847
43+
fullSetup.compiler.hooks.done.tap('done', ready);
44+
return fullSetup.server;
45+
},
46+
start(config, options, done) {
47+
return this.startFullSetup(config, options, done).server;
2548
},
2649
close(done) {
2750
if (server) {

0 commit comments

Comments
 (0)