I want to run JavaScript tests from the IntelliJ gutter (the green double-arrow icons on the left side, by the line numbers).
I've set up a Run/Debug configuration for Mocha that works fine when it's used to run all my unit tests at once.
Its Node interpreter is the project's, at v8.11.4.
Its Node options are empty.
Its working directory is my/project/src.
Its environment variable is BABEL_ENV=test.
Its Mocha package is my/project/src/node_modules/mocha.
Its UI is mocha-when-then.
Its extra Mocha options are --compilers js:babel-core/register --require babel-polyfill --require ./testSetup.js --require ignore-styles.
Its test directory is my/project/src/test/, set to "All in directory".
Everything works fine when running the main, all-tests configuration. But when I run an individual test or test suite from the gutter, I get errors, because IntelliJ generates a new configuration with default settings, like blank fields for Mocha options and environment variables. I can work around this by manually copying the settings over, but having to do that for every single run is a huge waste of time.
My co-workers don't have this problem even though their configuration is identical to mine. (Identical in the IntelliJ Run/Debug Configurations menu, anyways. Obviously, something is different between our setups.)
How can I make the project settings apply or persist to tests that I run from the gutter?
Related
I want to run the tests of my frontend project, but everytime I want to start a test I get the following error:
In the Run Configurations, IntelliJ selected #angular/cli as default Jest package, which is wrong.
The correct Jest package should be jest.
After I select the correct package, Jest works and runs the selected test.
I have to do this, everytime I want to run a test.
This is not a local problem, my coworkers have the same problem in this project.
Try editing Jest run configuration template: choose the desired Jest package there, save the configuration. New configurations created from gutter/right-click menus will use these settings, you won't need to care of specifying them for each configuration
How to set up running configuration with WebStorm feature file?
When I click on green run button seems that WebStorm can't find the steps realisation.
How could I change that WebStorm understands from where should it take steps?
When I run tests with command line it works, I have config file where I declared steps folder.
You can specify --require path/to/step/definitions as Cucumber.js arguments: field:
When I create a new Mocha test file I am presented with the expected green gutter icons (▶ and ▶▶) to run each test or the suite. When I select "Run [test name]" I expect it to create a Mocha debug configuration and run it. Instead, IntelliJ creates a NodeJS run configuration, which understandably explodes in a shower of bit-flavored WTF.
If I manually create a configuration for the whole file, everything works as expected, including individual tests afterward. I am hoping that there is a setting somewhere that I have overlooked, something like "Settings -> ... -> Default Debug Configuration".
Does anyone know how I can make IntelliJ default to Mocha when a unit test is executed?
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 current file. Do you have 'mocha' listed as a dependency/dev dependency in your package.json? How many package.json files do you have in your project?
Note that, if Mocha is not installed locally/included in package.json, you can create a Mocha run configuration with "All in directory" selected and specify a directory where your spec files are located. In this case, clicking the gutter button in a test file inside this directory will suggest to run test with Mocha.
Note also that if you have created Node.js Run configuration with "JavaScript file" set to your mocha test file, IDEA will suggest using this configuration instead of Mocha when clicking on your tests, because explicitly created run configurations associated with current file have priority over the ones auto-generated from context. Deleting the configuration should solve the issue.
I am trying to simplify the way we run cucumbers. We have a runner for each folder and we always change the runner in a run configuration that has some VM options set.
I can right click on a feature, select "Run feature :" but it doesn't run successfully without the parameters from the run configuration (one of them runs the tests with an in memory database for example)
Is there anyway I can add a default configuration so I can run them directly?
Run -> Edit Configurations
In the left-hand panel, there is a category called defaults. You can set the defaults to cucumber there. However, note that you might have to delete your previously existing configurations to get this to work with files you've already tried. They usually appear in a faded gray.
In addition, you could also add a runner class, which can run (a subset of) your tests from a testing framework. You can provide #CucumberOptions in this runner.
In a teamcity config I have build step which runs PhantomJS tests. It is a "Command Line" step with custom script. The script looks like:
%PhantomJS% CreateEntityPopupTest\unit.htm
%PhantomJS% ExcelImportPopupTest\unit.htm
...
etc.
So it runs each qunit test package mentioned in the htm page. But I didn't manage to find a way to point PhantomJS (phantomjs-1.9.0-windows) to a folder, not to a single file. So there would be no need to change the config each time when we add new files with tests.
I used Chutzpah to wrap this behavior for use in TeamCity. Chutzpah can run tests written in QUnit, Jasmine or Mocha and uses PhantomJS as the headless test runner.
https://github.com/mmanela/chutzpah
I installed it on the build agents and added it to the path on the machine.
Now I simply add a Command line runner step called 'Run JS Test' in my build template. Command line is simply:
chutzpah.console.exe %jsTestFolder%
Then I just define the parameter for each project pointing to a folder... chutzpah does the rest.