Skip to content

Commit

Permalink
feat: improve error handling within startCallback and endCallback (
Browse files Browse the repository at this point in the history
  • Loading branch information
tehraven committed Oct 24, 2021
1 parent 74deac7 commit b0928ac
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/Server.js
Expand Up @@ -2175,7 +2175,9 @@ class Server {
}

startCallback(callback) {
this.start().then(() => callback(null), callback);
this.start()
.then(() => callback(null), callback)
.catch(callback);
}

async stop() {
Expand Down Expand Up @@ -2235,7 +2237,9 @@ class Server {
}

stopCallback(callback) {
this.stop().then(() => callback(null), callback);
this.stop()
.then(() => callback(null), callback)
.catch(callback);
}

// TODO remove in the next major release
Expand Down
23 changes: 23 additions & 0 deletions test/e2e/api.test.js
Expand Up @@ -80,6 +80,29 @@ describe("API", () => {
});
});

it(`should catch errors within startCallback`, async () => {
const compiler = webpack(config);
const server = new Server(
{ port, static: "https://absolute-url.com/somewhere" },
compiler
);

await new Promise((resolve) => {
server.startCallback((err) => {
expect(err.message).toEqual(
"Using a URL as static.directory is not supported"
);
resolve();
});
});

await new Promise((resolve) => {
server.stopCallback(() => {
resolve();
});
});
});

it(`should work when using configured manually`, async () => {
const compiler = webpack({
...config,
Expand Down

0 comments on commit b0928ac

Please sign in to comment.