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
Jest process doesn’t quit after last test completes #1456
Comments
We don't have a good way to do that right now. I would recommend trying to hook in a debugger (Chrome Inspector) to figure out what is going on. If you know what creates the async work, you can potentially also monkey patch it and track it (like put something around Promise.prototype.then) |
Is there a reason async work can’t be force quit when all |
I don't know how you'd kill existing async processes if you don't have a handle on them. |
I migrated from |
We could do that, I guess, but I'm worried it leaves people not hanging when it should and they aren't shutting down their resources properly. cc @DmitriiAbramov what do you think? |
One example: I actually ran into this with Jest myself where we had a long running watcher process that wouldn't terminate Jest itself. If Jest would have killed itself during the test run (heh!) I would have never noticed the issue and I would have shipped a version that would hang when people try to use it. |
i'm not sure if it's safe to force kill the process. at the same time, if people want to do some async post processing after the tests are done, they could use the other issue that we might have is cutting the output stream before it finished printing. we had this issue before, when error messages don't have enough time to print before the process exits. |
The question is whether we could figure out a way for Jest to say "Looks like some tests aren't cleaning up after themselves. here is what is going on". |
An As for testing correct cleanups, if you could test if files were completing on time and if they weren’t using a bisect feature to isolate the problem (like in rspec). |
Ok, so after more research this appears to be a problem with Firebase itself, and there is no way to cleanup short of calling Resources:
All of the workarounds involve manually calling afterAll(() => setTimeout(() => process.exit(), 1000)) …to exit one second after all tests finished running to let Jest do its thing, however I’m not sure how this affects watch mode, and if I’m correct Jest does some fancy parallelism stuff which might make this not work as expected. Alternatively, would this be something you need to fix in Jest proper? If this seems like a footgun for a number of people, why not put it into Jest? Or at least a toggle between “warn” mode and “kill” mode. |
i'd love a |
I'm having the same problem when I run tests in Codeship. It also fails on drone.io. EDIT:
|
It seems to me like Firebase should be fixed. I have no reservations against adding an option called |
Seems to be a race condition of sorts. Sometimes it quits after running all test locally sometimes it doesn't... |
I'm running this as well after starting to use Jest for my API specs where I'm using real database instead of mocks (sorry 😇 but snapshots are great for this). I yet been able to solve the issue even after adding Jasmine seems to have |
another issue - if a test fails, then |
If anyone would like to send a PR, this is something that we could use some help with and I outlined details in my previous comment :) |
I'll give it a shot if I get some time over the weekend. If someone wants to do it before that it'd cool 😄 |
After run all tests that force exit when forceExitAfterTestRun is true jestjs#1456
Closing in favor of the PR that was just opened. We'll continue the discussion there. |
After run all tests that force exit when forceExitAfterTestRun is true jestjs#1456
After run all tests that force exit when forceExit is true jestjs#1456
Add patchet jest-cli with the command line param --forceExit to solve problems when jest process doesn’t quit after last test completes. More info: jestjs/jest#1456
So.... I was fighting with this for quite some time (using travis ci, coveralls and typescript). After much trial and error, i found what fixed this for me was that I added in an explicit path to the tests. It failed with the npm script
And passed (in travis ci) with:
|
This reverts #3288, aka commit 7ed7e52 (and so re-opens #3281.) After this change, Jest would hang after all tests had completed. (Not sure how I missed that before merge -- did I neglect to run the tests? >_>) I noticed the problem a few commits later, and it took a bit of debugging to identify this test file, and then this commit, as the culprit. Some background I found helpful in debugging: jestjs/jest#1456 . The root of the issue seems to be that a lot of these tests fire off `fetchMessages` actions, or others that in turn invoke that one -- and then don't wait for them. Compounding that, many of them are doomed to fail at their HTTP requests because their fixture states have no accounts, so there's no realm to base the URLs on. Anyway, we don't knowingly merge changes that break things. Merging this was a mistake; take it back out. We can merge a version of this change once we have one that doesn't cause breakage.
If you are using docker with a Redhat UBI image and |
December 2019. Ran into this issue ONLY on Travis. Tests pass locally. @qopqopqop 's fix worked for me. Using Jest version 24.9.0 I only encountered this error when our project started adding new components that use hooks and testing-library. I think there may be some friction between Jest, testing-library, and React hooks as these are all new technologies. These projects are still learning how to play nicely with each other. OR, we could be writing really buggy functional components that use hooks improperly. :-) |
I still have this issue. I can't exit the test, this make |
@koooge Can you post an example of what doesn't work for you? |
To make the test exit with 0 after all tests pass you have to pass in --watchAll=false this worked for me |
To make this work with Firebase I had to do this:
|
I've fixed it using the option: --forceExit |
So I ran into this issue as well. It was annoying seeing the I use a native promise utility library (https://github.com/blend/promise-utils) and wrap some of my external API calls in the I pulled that code out and created a simple test case to confirm my findings. it('promise.race', async() => {
await Promise.race([
new Promise((res) => setTimeout(res, 10000)),
Promise.resolve('true')
])
}) Assuming your test case timeout settings are default, the above test will always give the warning. Whatever way For now, I am sticking with Edit: |
For anyone else coming here from Firestore tests, this works for me: afterAll(async () => {
// Shut down Firestore, otherwise jest doesn't exit cleanly
await firestoreInstance.terminate()
}); |
I'm still having the same problem using Apollo & Jest. Unfortunately, even though the option Using
A workaround I found (and this is by no means a solution!) is adding a
and in teardown.js use process.exit:
|
I also have this problem. How can I fix it? I have set atom-community/atom-ide-base#33 Edit: the issue somewhere else. It is in the test-runner that I am using... |
@alusicode Like
Official docs: https://jestjs.io/docs/en/cli.html#--watchall |
Not using firebase but I had the same issue on my workflow scripts. using |
I agree that this maybe is not a solution for the issue but at least it saves me for now. |
Why does this work? I'm using firebase emulator for unit tests and I think this bit solved the last of my problems. I've tried all these and then some in afterAll, but they weren't enough: await Promise.all(firebase.apps().map((app) => app.delete()));
await firebase.firestore().disableNetwork();
await firebase.firestore().terminate(); I'm glad the warnings are gone anyways. EDIT: This doesn't solve the problem in --watch mode. Very unfortunate. |
I had to remove |
Something I noticed during debugging was that it does not seem to be the firebase/firestore instance triggering the error, but rather the assertions. The following code shows the warning after running the test suite: /**
* @jest-environment node
*/
import * as firebase from "@firebase/rules-unit-testing"
let db: any
const user = {
uid: "some-uid",
displayName: "user",
}
beforeEach(() => {
firebase.initializeTestApp({
projectId: "project-id",
auth: user,
})
db = firebase.apps()[0].firestore()
})
describe("Firestore Security Rules", () => {
it("allows user to get his own modules", async () => {
const moduleRequest = db
.collection("users")
.doc(user.displayName)
.collection("modules")
.doc("docID")
await firebase.assertSucceeds(moduleRequest.get())
})
})
afterAll(async () => {
await db.terminate()
await Promise.all(firebase.apps().map((app) => app.delete()))
}) However if you remove the assertion in the test, it exits just fine: /**
* @jest-environment node
*/
import * as firebase from "@firebase/rules-unit-testing"
let db: any
const user = {
uid: "some-uid",
displayName: "user",
}
beforeEach(() => {
firebase.initializeTestApp({
projectId: "project-id",
auth: user,
})
db = firebase.apps()[0].firestore()
})
describe("Firestore Security Rules", () => {
it("allows user to get his own modules", async () => {
const moduleRequest = db
.collection("users")
.doc(user.displayName)
.collection("modules")
.doc("docID")
// await firebase.assertSucceeds(moduleRequest.get())
})
})
afterAll(async () => {
await db.terminate()
await Promise.all(firebase.apps().map((app) => app.delete()))
}) Changing the |
Had the same issue, fixed it with a comment earlier in the thread: it will not wait for interactive input. You can add this to your package.json with: |
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. |
I’m having issues with the Jest process not completing after the last test completes. The user will have to force quit the process with ctrl-c. My theory is that not all resources are being cleaned up appropriately by the test authors, but ideally Jest should quit anyway.
Specifically I’m testing Firebase with
firebase-server
, spinning up one or more servers for every test. In anafterEach
action we call theclose
method for all the servers created in the last test, however even with this method the Jest process still doesn’t quit.Is there a way to force the Jest process to quit once tests have finished (pass or fail)? Is there a way to get an
afterAll
hook to cleanup all leftover resources? Is there a way to debug what exactly keeps the Jest process from quitting? Thanks.The text was updated successfully, but these errors were encountered: