Search code examples
intellij-ideajestjsvitevitest

How to set default environment for all tests in IntelliJ


I have replaced Jest with Vitest in my frontend monorepo recently. My module structure is like this

- | apps
         - | foo
                 - package.json
                 - | src
                 - | test

  | libs (same as apps)

When I try to run tests in intellij, it gives me these options:

enter image description here

But I want to always run Vitest, not Jest or Mocha. Vitest should be executed per default.

I also want to be able to rightclick on any folder in the monorepo and be given the option to execute only the tests inside that folder. Right now IntelliJ only offers me to run Python (?) tests and only when I rightclick one of the tests folder - not folders with any other name.

And once configured, how do I export the env configuration properly, so other devs can use it when they clone the repo? I tried exporting as a ".run.xml" to the root of the monorepo, but got the error that there is no loader for xml.


Solution

  • The logic currently used by JavaScript support plugin for detecting what test runner is available for a given test file is based on dependencies declarations in package.json nearest to this file: it looks for known test runners listed there and tries to run the most suitable one, or prompts you to choose a runner for current test. Unfortunately there is no way to choose a test runner explicitly and make it default foryour project; if you miss this feature, please vote for WEB-28397

    To share a run configuration, you need enabling Store as project file for them and commit the .idea files to your repo as suggested in https://www.jetbrains.com/help/webstorm/configure-project-settings.html#ws_project_settings_share