Have to set config each time to run individual Jest test in IntelliJ

Viewed 574

I am able to run the full Jest test suite from package.json in IntelliJ eg.

"test": "jest --no-cache --runInBand --config ./jest.json"

As you can see i'm using a jest.json config file and this works fine.

Now when i want run run an individual test and have to edit the run configuration each time.

The steps:

click on the green arrows to start the test

enter image description here

I get a load of errors (which i don't think are related)

There might be a problem with the project dependency tree. It is likely not a bug in Create React App, but something you need to fix locally.

The react-scripts package provided by Create React App requires a dependency:

"babel-jest": "^24.9.0"

Don't try to install it manually: your package manager does it automatically. However, a different version of babel-jest was detected higher up in the tree:

To overcome this i have to select 'Modify Run Configurations' which presents me with:

enter image description here

I have to set manually select the jest.json config file from the project directory and then change the jest package to jest:

enter image description here

This is now starting to become very tedious after many months.

Surely it should automatically be able to remember the last config but it always seems to default to the first image - with no config file selected and the jest package as react instead of jest.

Again, running the tests from package.json is fine but individual tests have to have 'Edit Run Config' settings set each time. Surely i should be able to just click the green arrow in the spec file to run?

Any fixes for this?

2 Answers

you need editing Jest run configuration template: choose the desired Jest package there, select jest.json as Configuration file. New configurations will use these settings, the test/suite names and paths will be set automatically based on current context, you don't need to care of specifying them explicitly

I deleted all the other templates and started afresh.

Clicked 'Edit configuration Template' set the default in there.

Then clicking on the green arrow in the tests work

enter image description here

Related