vscode-jest-runner icon indicating copy to clipboard operation
vscode-jest-runner copied to clipboard

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

Open tillig opened this issue 2 years ago • 2 comments

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.

tillig avatar Sep 20 '23 20:09 tillig

This is a reasonable idea, it could be something like

  • If jest.config.js|ts|mjs|cjs|json exists in a parent directory, OR
  • If any settings jestrunner.* is set?

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:

domsleee avatar Oct 14 '23 13:10 domsleee

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.

tillig avatar Oct 14 '23 14:10 tillig