WebStorm. Run Jest in watch mode - javascript

I see that WebStorm supports Jest testing, and I see that I can toggle auto-test on code changes. But that's not the same as Jest --watch mode which is lot faster.
Is it possible to configure watch mode somehow?
EDIT
I found out that I can pass --watch option to each test config, but I would have to do it for every file, and also it's not possible to use Jest watch options like e.g. "filter".

You can edit the default Jest configuration and add --watch in Jest options. Every new configuration will contain this option.
By the way, could you please tell how you are going to use --watch in every configuration? As far as I know, this option usually is used for all tests in one config.
Moreover, please provide more details and documentation on filter option you mentioned.

Jest -watch support will be provided in 2017.3. Please see https://youtrack.jetbrains.com/issue/WEB-26205

Related

Update Jest Snapshot Tests within IntelliJ IDEA

Recent versions of IntelliJ IDEA support the execution of Jest tests.
I couldn't find an option (or even better a shortcut) to update snapshot tests within IntelliJ IDEA.
Is there an option/shortcut to update snapshots within IntelliJ IDEA?
What I have been doing is to right click on the failing Jest test and select the Create option in the pop-up menu to create a new run configuration for just that failing test.
I then add -u to the Jest options and run that specific test (once) to update the snapshot.
It is far from ideal, but you can keep them around for later, if you like, to re-run them with the -u option when needed.
I was wondering the same thing and I asked Jetbrains. They said this feature was requested and you can track the status of it here: https://youtrack.jetbrains.com/issue/WEB-26008
I'm not sure when it will be complete but looks like it is on their radar.
The -u option can be applied as a Jest run config default if you want it to be active for all Jest tests.

Running mocha tests from node

I am trying to run my mocha tests from node . The ultimate goal is to add code-coverage via istanbul/blanket and generate a lcov file for input into sonar for code coverage.
This is a sample project on which I am trying
https://github.com/rajarshigoswami/Todos
The mocha tests are under
https://github.com/rajarshigoswami/Todos/tree/master/test/mocha
The tests are running from browser, but when I am trying via node, it wont pick up any of the spec files.
How to use :
run : npm install
then : grunt
My questions are :
What am I missing or doing wrong here?
How do I integrate blanket.js/istanbul to generate lcov files
I would change a few things. Simply add this to package.json
"scripts": {
"test":
"./node_modules/.bin/istanbul test ./node_modules/.bin/_mocha -- -R spec"
}
Now, when you do npm test it runs mocha and istambul
This article will help you
There's a few options depending what you need to do:
1) So firstly it would be good to know what you actually mean by running tests in node? For example I use to mocha to test server-side code for my node.js applications. It just runs the tests without relying on any specific environment (except node.js obviously). Without any other tools simply run mocha your/custom/test/directory/ (that assume your mocha is installed globally).
So as long as your view test don't rely on being run in a Web Browser you're good.
2) If what you just want run your front-end tests without need of opening SpecRunner.html manually in a web browser, I highly recommend using karma test runner, with a headless browser like PhantomJS.
3) Finally if you already have the grunt installed just grab the mocha-istanbul npm module. The configuration is really simple:
mocha_istanbul: {
coverage: {
// where your tests leave
src: 'server/tests',
options: {
// instrument only spec files
mask: '*.spec.js',
// output a human readable website
// (along site regular test summary produced by mocha)
reportFormats: ['html']
}
}
}
So as you can see there are some options out there. Just grab the one that suits your project the best.
your problem is that you are trying to test code that using requirejs
in order for the you mocha spec to work with phantom and requirejs on a grunt task runner you can use grunt-mocha-phantomjs
for you other issue of using istambol check this link (this link is more suitable for your purpose because its use backbone also (-: )

Triggering Karma tests in the test runner

I am having a small issue with WebStorm that I am hoping someone has experienced and solved before.
I am using WebStorm to build a angular.js app and I have it set up to use Karma to run my tests. This is fine for the most part: I have a Karma configuration setup and I can get to to run the tests or debug them with no issue.
My problem is that when I try to run a test individually by clicking on one of the test in the "Test Run" tree it goes off to a node configuration, tries to run it and fails (because its looking for js dependencies). After that I just go back to my 'karma config' and it runs through the whole of the test no problem.
Does anyone know how I can get the IDE hooked up so that I can trigger my tests from the UI?
Running tests from file right-click menu is only supported for those runners that allow executing individual tests (JSTestDriver, for example). There is currently no such possibility for Karma (WEB-13173). See the discussion at https://github.com/karma-runner/karma/issues/1235.
to run individual test files, you can have several karma configuration files with different sets of tests included. Plus you can rename individual tests/suits in the way mentioned in https://github.com/karma-runner/karma/issues/553

Run/debug node.js testcases with jasmine in Webstorm 11

I install Webstorm 11 and want to run my tests (for node.js app) implemented with Jasmine.
However it's not easy to do that. I could just type in command line 'jasmine' command and test will be runned, but in this case I'm not able to debug code.
So is there a way to configure Webstorm to deal with jasmine specs as it should?
Ok, so while no one answer at the moment I will try to provide my version:
This flow will allow to run jasmine testsute from Webstrom and debug testcases
install jasmine (ither locally or globally)
in project folder create folder 'spec/support' In this folder place jasmine.json
tests configuration example:
{
"spec_dir": "tests",
"spec_files": [
"**/*[sS]pec.js"
],
"helpers": [
"helpers/**/*.js"
]
}
Create node.js configuration in Webstorm
In this configuration select source file - jasmine executable file (for localy installed
jasmine it will be 'node_modules\jasmine\bin\jasmine.js' )
So you are ready. However at the current moment when trying to debug this configuration - it fails with error:
Cannot stop on breakpoint due to internal error org.jetbrains.v8.V8CommandProcessor$1:
If you faced with it - you need to change Webstom configuration and set this settings:
-Dnodejs.debugger.use.jb.support=false For more details check there:
So this allow you to run jasmine tests and debug them. However there is still some things which this solution not able to do:
Run individual testcases
Run individual testcases with right click button and Run command from menu
Jetbrains, if you reading this - please fix this already. I started play with node in Webstorm 3 years ago and since that moment and dozens of version there is still no nice way to run tests. It's ridiculous.
Jasmine works with the JSTestDriver which you get out-of-the-box with WebStorm 11:
https://www.jetbrains.com/webstorm/help/enabling-javascript-unit-testing-support.html
This page also details how to add Jasmine within JSTestDriver:
https://www.jetbrains.com/webstorm/help/preparing-to-use-jstestdriver-test-runner.html
At a high level you're going to:
Install JSTestDriver from JetBrains plugin repo
Configure it as a WebStorm JavaScript library (https://www.jetbrains.com/webstorm/help/configuring-javascript-libraries.html#configure)
Open jsTestDriver.conf and type the following code in it:
load:
lib/jasmine/jasmine.js
lib/jasmine-jstd-adapter/JasmineAdapter.js
WebStorm doesn't manage test running directly. This job is done by a test runner. WebStorm supports several test runners - Mocha, Karma, JsTestDriver, nodeunit. Most of them can execute Jasmine tests

SonarQube: Integrate ESLint for JavaScript in SonarQube?

We have determined our rules, which should be used for JavaScript code, with ESLint. Now we want to integrate ESLint to SonarQube as we did it before the same way with Checkstyle for JavaCode.
Under the following link it is described why SonarQube doesn't want to provide a plugin for ESLint:
http://www.sonarqube.org/sonarqube-javascript-plugin-why-compete-with-jslint-and-jshint/
Is there still no plugin fir ESLint in SonarQube? Isn't this part of a marketing strategy? There is also a plugin for Checkstyle, FindBugs etc... Why does SonarQube suddenly stop to support the integration of other code analysing tools?
Yes, there is still no plugin for ESLint, and this is part of the strategy, but in the other direction.
In fact, our first plugins were for external analyzers, and over time we realized that simply aggregating other tools' results didn't truly serve the community because that community was coming to us with rule bugs, requests and suggestions for improvement - and all we could do was refer them on the tools' makers.
So we started writing our own rules instead for better responsiveness and, we believe, enhanced accuracy.
I urge you to take the rules you feel are missing to the SonarQube Google Group
Edit The strategy has come full circle. SonarJS now imports ESLint reports.
I have not tried it yet, but I've just discovered this plugin that seems to be very promising for any front end project:
https://github.com/groupe-sii/sonar-web-frontend-plugin
It may worth giving a try
You have a good option here:
https://github.com/sleroy/SonarEsLintPlugin
From the docs:
• Install Node.js
• Install EsLint (3+) with npm install -g eslint, or ensure it is installed locally against your project
• If you're installing globally, find the path to EsLint and copy it - will be similar to C:\Users\
[Username]\AppData\Roaming\npm\node_modules\eslint\bin\eslint.js on Windows
• Copy .jar file (downloaded from https://github.com/sleroy/SonarEsLintPlugin/releases page) to SonarQube extensions folder
• Restart SonarQube server
• Browse to SonarQube web interface, login as Admin, hit up Settings
• Hit the Rules tab, then the EsLint rule set, then apply it to your project - alter rule activation as required
I came across a similar requirement and the following are the steps that I followed to achieve the ESLint report output integration into the Sonarqube dashboard:
Switch to the project directory.
Run: npx eslint <source_code_to_be_scanned> --format json --output-file <file_name>.json
For e.g. npx eslint ./src/**/*.js --format json --output-file eslint-result.json
Cope the relative path of the generated report.
Add an additional property in your sonar-project.properties file as below:
sonar.eslint.reportPaths=app/eslint-result.json
Perform the scan
Output: I was able to see the expected output within my Sonarqbue dashboard.
I hope some of you find it helpful and save a bit of time.

Categories

Resources