Report invalid `--require` directly instead of via UnhandledPromiseRejectionWarning

Open
#1,688 0 comments 0 reactions 1 assignee View on GitHub

@Krinkle is already working on this.

Since Apr 24, 2022.

Assessment

This issue has not been assessed yet.

Description

Component: CLI Type: Enhancement
  • QUnit version: 2.18.2
  • Which environment are you using?: Node.js
  • How are you running QUnit?: QUnit CLI

We have a test case displays helpful error when failing to require a file in test/cli/cli-main.js which. The assertion currently ensures that the output "includes" the important subset, which is Error: Cannot find module 'does-not-exist-at-all'.

However, when running it directly (in prep for https://github.com/qunitjs/qunit/issues/1684) I noticed it gets there in quite an unsual manner:

(node:4519) UnhandledPromiseRejectionWarning: Error: Cannot find module 'does-not-exist-at-all'
Require stack:
- /qunit/src/cli/require-from-cwd.js
- /qunit/src/cli/run.js
- /qunit/bin/qunit.js
    at internal
    at bin/qunit
    at internal
    at bin/qunit
    at internal
(node:4519) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:4519) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

This happens because /src/cli/run.js currently handles options.requires before setting up options.reporter and process.on('unhandledRejection'). I suggest we swap this around.

Dominant language
JavaScript
Stars
4k
Forks
773
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from qunitjs/qunit

All issues in qunitjs/qunit

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.