qunitjs / qunit

🔮 An easy-to-use JavaScript unit testing framework.
https://qunitjs.com
MIT License
4.02k stars 783 forks source link

[QUESTION] How can I forcefully abort a testcase and advance to next in queue #1755

Open aravinth-r-7867 opened 2 months ago

aravinth-r-7867 commented 2 months ago

We have a huge testsuite. Some testcases have been set assert.timeout option upto 3 to 5 minutes. We cannot remove this timeout option for now. Sometimes when any exception is thrown, tests are hanging for a long time (upto the timeout mentioned) before moving to the next testcase. We want to abort a test immediately if it throws any uncaught exception (not any test assertion failures) and proceed to next testcase. We couldn't able to find any option to do so. Is there any way to achieve this?

Krinkle commented 1 week ago

I'm re-opening this as I think I can learn from your experience.

We currently catch and report uncaught errors as failures inside the currently-running test (when possible). It would indeed be possible to cancel a pending timeout based on that. However, this can't be a total cancellation I think, since that would expose the test suite to race conditions with undefined consequences.

For example, if the test function is an async function, we wait for the promise to resolve. When errors are thrown inside a promise chain, these already cause the test to automatically reject the async/promise and thus there is a fast failure, no timeout.

In your case, where is this uncaught exception is coming from? Knowing this can help me understand if there's a general solution we can come up with to address this. I don't think cancelling timeouts would be what we want to do here, but perhaps there's something else we can recommend/document/improve.

Thanks!