Skip to content

Fix Routes test and add new server creation helpers #1735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/Routes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('Routes', () => {

describe('without headers', () => {
beforeAll((done) => {
server = helper.start(config, {}, done);
server = helper.startAwaitingCompilation(config, {}, done);
req = request(server.app);
});

Expand Down
27 changes: 25 additions & 2 deletions test/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ const Server = require('../lib/Server');
let server;

module.exports = {
start(config, options, done) {
// start server, returning the full setup of the server
// (both the server and the compiler)
startFullSetup(config, options, done) {
// eslint-disable-next-line no-undefined
if (options.quiet === undefined) {
options.quiet = true;
Expand All @@ -21,7 +23,28 @@ module.exports = {
done();
});

return server;
return {
server,
compiler,
};
},
startAwaitingCompilation(config, options, done) {
let readyCount = 0;
const ready = () => {
readyCount += 1;
if (readyCount === 2) {
done();
}
};

const fullSetup = this.startFullSetup(config, options, ready);
// wait for compilation, since dev server can start before this
// https://github.com/webpack/webpack-dev-server/issues/847
fullSetup.compiler.hooks.done.tap('done', ready);
return fullSetup.server;
},
start(config, options, done) {
return this.startFullSetup(config, options, done).server;
},
close(done) {
if (server) {
Expand Down