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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature]: expose isTornDown
readonly property
#13640
Comments
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
This is not stale |
Happy to take a PR adding this. Exposing on |
This commit adds a new feature to the Jest runtime package that exposes the `isTornDown` variable as a way to check if the Jest environment has been torn down programmatically. The `isTornDown` variable is a read-only boolean that is set to `true` when the environment is torn down and `false` otherwise. The commit also adds documentation for the `isTornDown` variable to the Jest runtime module. Closes jestjs#13640
Created a PR for this: #13698 |
@jomendez Thanks for PR. Looking at the issue it seems that the focus is on timed-out test, not on torn down environment. I mean For example, some callback taking hook like Just thinking out loud. Not sure if a hook is useful. From the issue it is not clear how the API could be used. That would help to shape it. @CreativeTechGuy could elaborate please? How do you see the usage? Rough idea in my head (does import {onTimeout} from '@jest/globals';
const ac = new AbortController();
onTimeout(() => {
ac.abort();
process.exitCode = 1;
}); EDIT Can be I am overthinking. A simple boolean like |
@mrazauskas I love the thought process. I think this would need to be documented so it's clear what and why it is needed. I suspect that most often this will be used as a fix once someone has already seen the error:
Since that error uses the term "environment torn down" that seems like a decent way to continue to refer to it. So maybe If I had to guess, a majority of users will never touch this. But now if someone does run into that error, they have the agency to do something about it. That seems like the most likely case to address. One concern with an |
This commit adds a new feature to the Jest runtime package that exposes the `isTornDown` variable as a way to check if the Jest environment has been torn down programmatically. The `isTornDown` variable is a read-only boolean that is set to `true` when the environment is torn down and `false` otherwise. The commit also adds documentation for the `isTornDown` variable to the Jest runtime module. Closes jestjs#13640
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
馃殌 Feature Proposal
Provide a way to check if the Jest environment is torn down programatically.
Motivation
In cases where a test does a lot of work and can time out, it can result in thousands of errors in the form of:
If the test has timed out, it'd be great to be able to check that and abort what we are doing. This is primarily useful for libraries which build test utilities, specifically when the library interacts with fake timers heavily.
The code I experienced this with was a loop of async/await which may have compounded the issue but I believe the issue is more generic than that.
Example
I am testing code which runs based on
requestAnimationFrame
. As a result I have a lot ofjest.advanceTimersByTime
calls in my tests. Sometimes these are called in a loop to advance through several minutes, one frame at a time. These tests can occasionally time out since a lot of work is being done every frame. When that happens, there may still be a few hundred/thousandadvanceTimersByTime
calls still to be called in the loop. As a result, not only does the test fail due to timeout, but now the entire console is spammed with massive stack traces and errors because of the above ReferenceError.Pitch
Jest is already tracking this internally to show the error message. It has an
isTornDown
property (in jest-runtime) which isn't exposed. If we had access to that property, we could stop our work. I don't see a reliable way to check if the environment has been torn down or the test has timed out programatically during the test aside from exposing a new property/method.The text was updated successfully, but these errors were encountered: