jest-community / vscode-jest

The optimal flow for Jest based testing in VS Code
MIT License
2.84k stars 295 forks source link

Automatically runs despite the repository open not using jest #1006

Closed ThisIsMissEm closed 1 year ago

ThisIsMissEm commented 1 year ago

Environment

  1. vscode-jest version: v5.2.3
  2. node -v: v16.18.1
  3. npm -v or yarn --version: 8.19.2 (npm)
  4. npm ls jest or npm ls react-scripts (if you haven’t ejected):
    typescript-sdk-tools@0.0.0
    └─┬ @inrupt/eslint-config-base@1.5.4 -> ./eslint-configs/eslint-config-base
    └── jest@28.1.1
  5. your vscode-jest settings if customized: not customised
    • jest.jestCommandLine? [fill]
    • jest.autoRun? [fill]
    • anything else that you think might be relevant? [fill]
  6. Operating system: MacOS 16.3

Prerequisite

Steps to Reproduce

We have a repository where Jest is a dependent, but not actually used for tests (it's a peer-dep for some ESLint Configuration), the vscode-jest plugin automatically runs on this repository, despite it actually having no tests (at present).

You can see this in https://github.com/inrupt/typescript-sdk-tools, just cloning and doing an npm ci --ignore-scripts should be enough to reproduce when opening in vscode — it incorrectly detects just as being present for tests, when it's actually not used for tests.

Relevant Debug Info

n/a

Expected Behavior

vscode-jest isn't enabled for the project / does not autorun.

Actual Behavior

vscode-jest autoruns and changes the focus of the terminal to it's output, despite the project having zero tests.

Screenshot 2023-02-08 at 22 02 48

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...

connectdotz commented 1 year ago

I tried your repo, and yes, I see the extension started (because it found the jest binary in the node_modules). There is no error, it just says, no tests found...

Do you plan to use jest for this project? If not, you can simply disable the extension. If you do plan to use jest later and you don't want the terminal to pop up until you have some tests, you can use jest.autoRun "off" to stop the automatic watch run.

Let me know if this didn't resolve your issue.

ThisIsMissEm commented 1 year ago

I think I just ended up changing my editor to always have jest.autoRun off, maybe I'll enable it on a project basis.

kcharles52 commented 1 year ago

In my opinion I believe that would be the best approach since you will be certain that you intent to use jest for that project. @connectdotz Am curious though if we can explore a possibility of looking into the package.json file to establish if a project uses jest and we auto run jest base on that.

ThisIsMissEm commented 1 year ago

What about looking for a jest.config. or jest.setup. file? Usually those are present in jest projects. Though I guess you could also scan the package.json scripts for mentions of "jest" as a word

connectdotz commented 1 year ago

Even though the presence of these "triggers", including the jest binary, indicates the intention of using jest, without them does not exclude a project from using jest. I will not be surprised to see false-negative complaints if we start to tighten the activation conditions as suggested.

To make a long story short, it's hard to get right all the time for all the use cases, and that's why there are customization settings. Hopefully, as you have discovered, the customization is pretty straightforward.