Settings for running single test

Hi

I'am working on project that uses both Mocha and Karma for running tests. Since WebStorm 2017.2 it is possible to run single test for Karma, and that is great but now i can't go back to running single test in Mocha.

I tried to remove whole .idea folder from project and it's still defaults to Karma. Is it possible to switch back to Mocha?

Thanks!

2
10 comments

The logic used for determining what test runner is available for a given test file is based on dependencies declarations in package.json nearest to the current file. Usually, client-side tests (that use karma) and server-side tests (using mocha) are placed in separate sub-projects each having a separate package.json file. Such project layout allows to use Karma and Mocha in corresponding sub-project directories.

If you have a single package.json, with both 'karma' and 'mocha' included, and there is a karma config in your project, karma is preferred - see https://youtrack.jetbrains.com/issue/WEB-26070#comment=27-2088951. To force using Mocha test runner for files in a directory, create a Mocha run configuration with "Test directory" set to this directory.

0
Avatar
Permanently deleted user

Bummer for sure with our project setup which has a mix of karma and mocha specs mixed together, identified by file name pattern (client.spec.js vs spec.js). I would think it's becoming less uncommon to structure projects like this, by functional area.

You mention forcing mocha by creating a mocha test configuration for a Test Directory? Should that then prefer to run all tests within that directory (eg. running an individual file) using mocha, creating a new transient run configuration? It didn't appear to work for me :(

Also, fwiw, the issue linked above doesn't appear visible to me (no permission to view that page).

1

> Should that then prefer to run all tests within that directory (eg. running an individual file) using mocha, creating a new transient run configuration?

yes.

>It didn't appear to work for me :(

please attach a screenshot of your run configuration

0
Avatar
Permanently deleted user

Thank you for quick reply.

I crated package.json with mocha dependency in directory where i want to run mocha test and its working great.

Thanks!

0
Avatar
Permanently deleted user

Thanks for your reply - sorry for not responding sooner.

It's becoming more apparent to me that our project setup just doesn't play well with the assumptions that karma specs and mocha specs will live in different directories - we bundle a lot of functionality for components into a single directory (controllers react components, client specs, server specs, etc) so configuration per directory is unreasonable (run configurations per directory are also unreasonable).

Reading back over this, I noticed that the inclusion of both karma and mocha in our single package.json would prefer karma IF we have karma config file (can't navigate to the issue to confirm), which we don't; however, it still prefers karma.

I've seen other scenarios where "Run file..." will pull up a contextual dropdown allowing you to choose the Run Configuration type and wonder why this wouldn't be the case for us? Regardless, even if we had a karma config file, I'd think that defaulting to one or the other will always be an issue for varying project setups.

0

> I noticed that the inclusion of both karma and mocha in our single package.json would prefer karma IF we have karma config file

If there are both karma and mocha in the same package.json and there is no karma config file, it's still karma's priority.

> I've seen other scenarios where "Run file..." will pull up a contextual dropdown allowing you to choose the Run Configuration type and wonder why this wouldn't be the case for us?

There is no such possibility.

Just to get a clear picture of your situation, could you please explain how you use karma in your project if you don't even have its config file?

 

0
Avatar
Permanently deleted user

Our karma config lives in grunt (https://github.com/karma-runner/grunt-karma).

0
Avatar
Permanently deleted user

FYI, there are other situations in which the preference for karma seems overly greedy.

For instance, if I add a File pattern based Mocha run configuration, and run all the specs that way in a recursive set of directories, subsequently clicking on the "run spec" arrow in one of the file's gutters will still try to run karma (even if the arrow is red as a result of a failed mocha spec). I have to go to the run spec output window, find the failed spec, and rerun it from there before the gutter arrow (or Run... menu option) will prefer mocha.

1

Please follow https://youtrack.jetbrains.com/issue/WEB-28397 to be able to specify test runner for the project.

>For instance, if I add a File pattern based Mocha run configuration, and run all the specs that way in a recursive set of directories, subsequently clicking on the "run spec" arrow in one of the file's gutters will still try to run karma (even if the arrow is red as a result of a failed mocha spec). I have to go to the run spec output window, find the failed spec, and rerun it from there before the gutter arrow (or Run... menu option) will prefer mocha.

It doesn't work with Mocha "File Patterns" run configurations. Please use "All in directory".

1
Avatar
Permanently deleted user

Great, thanks for the ticket.

0

Please sign in to leave a comment.