Vscode-jest: Jest runner in the background after exit

Created on 23 Jan 2020  路  11Comments  路  Source: jest-community/vscode-jest

Environment

  1. node -v: v13.7.0
  2. npm -v: 6.13.6
  3. npm ls jest or npm ls react-scripts (if you haven鈥檛 ejected): [email protected] / [email protected] (see below)
  4. your vscode-jest settings if customized:

    • jest.pathToJest? Not customized
    • jest.pathToConfig? Not customized
    • anything else that you think might be relevant? Multi-root project, with Jest 25 on its own on back-end and react-scripts on the front-end
  5. Operating system: Ubuntu 18.04

Prerequisite

  • are you able to run jest test from command line? Yes
  • how do you run your tests from command line? (for example: npm run test or node_modules/.bin/jest) npm run test

Steps to Reproduce

Not sure how to create a relevant repository. Would appreciate guidance on the diagnostic path. I've tried enabling debug, nothing suspicious emerges.

Expected Behavior

Jest runs correctly in the extension. Icons are fine, test results are reported correctly. Upon termination of VS Code, no Jest processes are left behind.

Actual Behavior

Jest runs correctly in the extension. Icons are fine, test results are reported correctly.

Upon termination of VS Code, I am left with a number of ghost processes. See below for the output of ps aux:

paolo    14981 22.6  0.7 981876 128424 tty2    Sl+  09:55   0:06 node /home/paolo/react/CongressGuru/congress-guru/backend/lambdas/node_modules/.bin/jest --testLocationInResults --json --useStderr --outputFile /tmp/jest_runner_lambda.json --watch --coverage --no-color --reporters default --reporters /home/paolo/.vscode/extensions/orta.vscode-jest-3.1.1/out/reporter.js
paolo    15418  0.2  0.1 587628 24740 tty2     Sl+  09:55   0:00 node /home/paolo/react/CongressGuru/congress-guru/frontend/node_modules/.bin/react-scripts test --testLocationInResults --json --useStderr --outputFile /tmp/jest_runner_front_end.json --watch --coverage --no-color --reporters default --reporters /home/paolo/.vscode/extensions/orta.vscode-jest-3.1.1/out/reporter.js
paolo    15425  8.1  0.4 954260 68880 tty2     Sl+  09:55   0:01 node /home/paolo/react/CongressGuru/congress-guru/frontend/node_modules/react-scripts/scripts/test.js --testLocationInResults --json --useStderr --outputFile /tmp/jest_runner_front_end.json --watch --coverage --no-color --reporters default --reporters /home/paolo/.vscode/extensions/orta.vscode-jest-3.1.1/out/reporter.js

The only solution I have found is running a pkill node.


The fastest (and the most fun) way to resolve the issue is to submit a pull-request yourself. If you are interested, feel free to check out the contribution guide, we look forward to seeing your PR...

bug help wanted needs investigating

Most helpful comment

thanks for everybody's data points, I was able to reproduce this and observed these 2 types of behaviors:

  1. if I close the workspace before jest can complete the run, I see all jest child process became orphan processes ... there could be some race condition that we didn't get to close the spawned child-process
  2. when the spawned process spawns another child process in the background, such as in react-scripts use case, even when we close the jest process, the react-script spawned process will not be terminated. I am guessing this probably started to happen when we switched spawn child_process with shell option a few months back...

@jeantil I could not reproduce your observation with coverage toggle, but I suspect it probably falls into one of the categories mentioned above...

Apology if this has happened to your project, I am afraid you will have to manually kill these orphan processes for now (such as pkill -f jest or pkill -f jest_runner). I will take a look to see how we can address this ASAP...

All 11 comments

That's not good at all @pdemarino!

Would you be able to try reproducing it to see if it will happen without the multi-root project? As for other guidance for how to troubleshoot this, I'd suggest running running the extension in development mode and setting a few breakpoints where we'd expect the extension to close or clean up.

@pdemarino, I have the same problem. One more solution by this issue is that: Launch VS Code in a project folder with bash command such as that:
$ code --wait . && pkill -f "bin\/jest" &

After exiting from VS Code all Jest runner processes would be killed automatically.

Noticed the same issue for couple of months now:

501 56707     1   0 Wed10AM ??        10:24.90 node /Users/renarsvilnis/work/project-1-fe/node_modules/react-scripts/scripts/test.js --testLocationInResults --json --useStderr --outputFile /var/folders/c2/xwc5xfcn7zj6_tzdgm0bzgj40000gn/T/jest_runner_rma_portal_fe.json --watch --no-coverage --no-color --reporters default --reporters /Users/renarsvilnis/.vscode/extensions/orta.vscode-jest-3.1.1/out/reporter.js
501 91865     1   0 10:36AM ??         1:18.45 node /Users/renarsvilnis/work/project-2-fe/node_modules/react-app-rewired/scripts/test.js --testLocationInResults --json --useStderr --outputFile /var/folders/c2/xwc5xfcn7zj6_tzdgm0bzgj40000gn/T/jest_runner_amplifi_com_controller_fe.json --watch --no-coverage --no-color --reporters default --reporters /Users/renarsvilnis/.vscode/extensions/orta.vscode-jest-3.1.1/out/reporter.js
501 93060     1   0 Wed11AM ??        10:08.02 node /Users/renarsvilnis/work/project-1-fe/node_modules/react-scripts/scripts/test.js --testLocationInResults --json --useStderr --outputFile /var/folders/c2/xwc5xfcn7zj6_tzdgm0bzgj40000gn/T/jest_runner_rma_portal_fe.json --watch --no-coverage --no-color --reporters default --reporters /Users/renarsvilnis/.vscode/extensions/orta.vscode-jest-3.1.1/out/reporter.js

All frontend apps using bootstrapped create-react-app typescript app thus the react-scripts.

I've had the same issue, as well - I wasn't even using this plugin directly because in this particular project we have a complex Jest setup, but I was simply running jest from the command line. I was finding that connections were being left open to the DB so I tracked down the parent process which pointed to this plugin. I've had this issue with both Jest 24 and Jest 25 and we are using ts-jest. I'm on macOS 10.15.3. Removing the plugin has solved the issue.

hmmm... I can't reproduce this with a react-native monorepo project... wondering:

  1. is anybody experiencing this outside of react apps? i.e. is this react-script related...
  2. does this happen every time for people that reported issue? Or just occasionally? If so, did you observe any specific pattern that triggered it?

@connectdotz

  1. I have seen it only on react-scripts projects for me at least all of them are typescript based. Not sure how react-scripts handles that under the hood - compiles with babel or ts-jest.
  2. Every time I have the project opened in vscode. Even without running tests trough the CLI.

not using React here - this is for a GraphQL API

This could be related to my https://github.com/jest-community/vscode-jest/issues/455#issuecomment-614904752 where I can consistently reproduce a similar (and more severe) issue with process leaks by toggling coverage report.

thanks for everybody's data points, I was able to reproduce this and observed these 2 types of behaviors:

  1. if I close the workspace before jest can complete the run, I see all jest child process became orphan processes ... there could be some race condition that we didn't get to close the spawned child-process
  2. when the spawned process spawns another child process in the background, such as in react-scripts use case, even when we close the jest process, the react-script spawned process will not be terminated. I am guessing this probably started to happen when we switched spawn child_process with shell option a few months back...

@jeantil I could not reproduce your observation with coverage toggle, but I suspect it probably falls into one of the categories mentioned above...

Apology if this has happened to your project, I am afraid you will have to manually kill these orphan processes for now (such as pkill -f jest or pkill -f jest_runner). I will take a look to see how we can address this ASAP...

hi, we have a new release candidate with the fix: v3.2.0. Would appreciate more testing before release, please feel free to give it a try and let us know if it worked, or not...

(to try the new release candidate, just to install the .vsix file (vscode-jest-3.2.0.vsix) in your vscode: https://code.visualstudio.com/docs/editor/extension-gallery#_install-from-a-vsix)

@connectdotz
I did install v3.2.0, Jest tests are still running by themselves in the background.

Was this page helpful?
0 / 5 - 0 ratings