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

Errors in Happy DOM are not detected #4139

Closed
6 tasks done
capricorn86 opened this issue Sep 18, 2023 · 0 comments · Fixed by #4140
Closed
6 tasks done

Errors in Happy DOM are not detected #4139

capricorn86 opened this issue Sep 18, 2023 · 0 comments · Fixed by #4140

Comments

@capricorn86
Copy link
Contributor

capricorn86 commented Sep 18, 2023

Describe the bug

Errors in Happy DOM are not catched by the Vitest error handler.

This works when using JSDOM as there is a listener on the window error event that emits "uncaughtException" on the Node.js process.

We can use the new Happy DOM setting disableErrorCapturing to achieve this.

This will also improve performance as try/catch which is used internally in Happy DOM by default can slow down execution.

Reproduction

Example 1

const script = document.createElement('script');
// Invalid code
script.text = 'globalThis.test = /';
document.body.appendChild(script);

Example 2

setTimeout(() => {
    throw new Error('Error')
});

Expected
Vitest error handler to catch the error and invalidate the test.

Actual
A console message with the error is outputted, but Vitest doesn't detect the error.

System Info

System:
    OS: Linux 6.2 Ubuntu 23.04 23.04 (Lunar Lobster)
    CPU: (4) x64 Intel(R) Core(TM) i5-7600K CPU @ 3.80GHz
    Memory: 6.86 GB / 15.57 GB
    Container: Yes
    Shell: 5.2.15 - /bin/bash
  Binaries:
    Node: 20.6.1 - ~/.nvm/versions/node/v20.6.1/bin/node
    npm: 9.8.1 - ~/.nvm/versions/node/v20.6.1/bin/npm
  Browsers:
    Chrome: 116.0.5845.187
    Chromium: 116.0.5845.187

Used Package Manager

npm

Validations

@capricorn86 capricorn86 changed the title Some errors in Happy DOM are not detected Errors in Happy DOM are not detected Sep 18, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Oct 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant