Skip to content
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

feat: improve error handling within startCallback and endCallback #3969

Merged
merged 2 commits into from Oct 24, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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