firsttris / vscode-jest-runner

Simple way to run or debug one or more tests from context menu, codelens or command plalette
https://marketplace.visualstudio.com/items?itemName=firsttris.vscode-jest-runner
MIT License
265 stars 124 forks source link

Tries to run jest for mocha tests, competes with other extensions #334

Open tillig opened 11 months ago

tillig commented 11 months ago

I have a repository that uses Mocha for testing (so there's a .mocharc.json in the root and mocha is referenced in package.json). I also have both this extension and Mocha Test Explorer installed.

Mocha Test Explorer adds Run and Debug options over each test just like the Jest runner does:

Both extensions contribute 'Run' and 'Debug' items

The challenge is that if I pick the wrong "Run" then it tries to run the tests using Jest... but Jest isn't installed or referenced here.

It would probably be good to do some sort of detection of whether Jest is even installed/referenced before showing the option to run/debug tests; otherwise it competes with other extensions and gets confusing.

domsleee commented 10 months ago

This is a reasonable idea, it could be something like

We need to account for monorepo structures where the jest config file is not always in the ancestory of the current file.

It would probably be good to do some sort of detection of whether Jest is even installed/referenced

Checking if jest is installed is a bit tricky, some configurations use global jest. There is also npm workspaces to consider 🤔

Open to ideas on this one.

For a workaround (not really a "fix"), you can disable the extension for your single workspace:

tillig commented 10 months ago

If I'm not mistaken, the monorepo situation would still be covered by "If any settings jestrunner.* is set" - if the config isn't in the file ancestry, it'd have to be provided to the extension somehow, which would mean the test command would need to be configured or the config location would need to be configured.

I suppose there's technically "run without any config" too. I'm not sure what to do about that.

But, yes, the workaround is to disable the extension, which I did.