Run jest test from editor with different config depending on file location

I have a run configuration set up to run all of my jest unit tests with a specific jest configuration file. However when I try to run an individual test from the editor by clicking on the circle with a play button on it next to the line number, it runs the test without the configuration file which causes an error. Is there a way to specify what configuration file should be used when you run tests individually depending on the file location? I know you can set defaults for jest, but I have two separate jest configs, one for my react jest tests and one for my node jest tests, and I haven't found a way to specify the config file based on the file location (use node config if in server folder and use react config if in client folder).


Currently, there is no way to specify a configuration file to be used when a single test is run. What are names of your configs? Where are they located relative to the project root?


having a similar issue, although I only have one config file: I can set that up in a 'configuration', for a global run of all tests, but if I want to use the UI to run a specific test, it doesn't take the config file, and I have to stop it, and edit the auto-generated test config to point it to the jest config.

Is there a way to configure the way the single test configuration is generated?



You can specify config for Jest Default run/debug configuration:

* on the main menu "Run | Edit Configurations...";

* expand "Defaults" node in the left area and find Jest run/debug configuration;

* specify needed config there, now all newly created Jest run/debug configurations will have the specified config.


I have added a segment in my test file names giving essentially the config I need.  (e.g. hooks.test.web.js, hooks.test.native.js).  Would be more flexible to define glob patterns, and then the associated configs.  Might need to order them so that the first matching glob was used to apply the config.  Or possibly an option in the config form to select a set of test files for the given config, or a directory, or glob pattern.


>Or possibly an option in the config form to select a set of test files for the given config, or a directory, or glob pattern.

Jest configs already define set of test files. See `testPathDirs`, `testRegex` from Sounds like a good idea to track all these Jest config files and auto-update set of test files per config. With this knowledge, Jest config can be inferred for a test file automatically. Would be great to file an issue with an example project to reproduce.


Good news! WebStorm 2018.3 brings an improvement here: it contains the fix for Now, working directory is set to the closest directory with `jest.config.js`, allowing to use different `jest.config.js` files for different test locations.
Please note it works only if Jest config file name is constant - `jest.config.js`.


This only fixes a limited number of cases

See for a scenario that isn't fixed.


Please sign in to leave a comment.