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

Browser: fix 'allowUncaught' handling #4174

Merged
merged 2 commits into from Feb 13, 2020
Merged

Browser: fix 'allowUncaught' handling #4174

merged 2 commits into from Feb 13, 2020

Conversation

juergba
Copy link
Member

@juergba juergba commented Feb 2, 2020

Description

  • mocha/browser-entry.js: Node's process.on('uncaughtException', fn) handler is moved to global.onerror(fn) in Browser.
Runner.prototype.uncaught = function(err) {
  if (err instanceof Pending) {
    return;
  }
  // browser does not exit when throwing in global.onerror()
  if (this.allowUncaught && !process.browser) {
    throw err;
  }
[...]
  • the result is distinct when an Error is thrown in the handler and allowUncaught: true
    • Node: the process exits and no tests or async tasks are executed anymore.
    • Browser: the JS script aborts the handler only, but the script keeps running. There seems no way to kill the entire script with its remaining tests and pending async tasks.
      ==> test results are incorrect, since the entire recovery logic of the handler is skipped.

Description of the Change

  • Node: behavior remains unchanged, the process is aborted upon uncaughtException when allowUncaught is set.
  • Browser: we don't throw anymore inside the uncaughtException handler. The script keeps running and the test results are correct. So allowUncaught has no effect on the test run, but uncaughtException's are printed in the console.

@juergba juergba added type: bug a defect, confirmed by a maintainer area: browser browser-specific semver-patch implementation requires increase of "patch" version number; "bug fixes" labels Feb 2, 2020
@juergba juergba requested a review from a team February 2, 2020 18:55
@juergba juergba self-assigned this Feb 2, 2020
@coveralls
Copy link

coveralls commented Feb 2, 2020

Coverage Status

Coverage remained the same at 92.857% when pulling 0bb3e5f on juergba/browser into 2ff1cb2 on master.

@juergba juergba force-pushed the juergba/browser branch 2 times, most recently from 4b818e2 to fcedbb9 Compare February 7, 2020 18:25
@juergba juergba added this to the next milestone Feb 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: browser browser-specific semver-patch implementation requires increase of "patch" version number; "bug fixes" type: bug a defect, confirmed by a maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants