Skip to content
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

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

Open
tillig opened this issue Sep 20, 2023 · 2 comments
Open

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

tillig opened this issue Sep 20, 2023 · 2 comments

Comments

@tillig
Copy link

tillig commented Sep 20, 2023

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
Copy link
Collaborator

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:

@tillig
Copy link
Author

tillig commented Oct 14, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants