Introduction: JetBrains IDEs tutorial

This tutorial demonstrates how to use wallaby.js in WebStorm, IntelliJ IDEA, Rider, PhpStorm, RubyMine, or PyCharm. You may also find a sample calculator project with created run configurations and config files for Mocha, QUnit and Jasmine in this repository.

Configuration file

After the plugin is installed, you can start by creating a wallaby configuration file. The configuration file is just a simple JavaScript file in your project’s root with just a couple of mandatory settings. It’s recommended to prefix or suffix it with wallaby, for example wallaby.js.

A simple configuration file would include files and tests (and testFramework, if you are not using jasmine) properties.

The files property should list your source files and other files used by your tests, while the tests property should list your test files. Any test helpers or other test related files that are not the files with actual tests/specs should be listed under the files property. Glob patterns can also be used.

Finally, the testFramework property defines the name and the version of the testing framework you will be (or are) using to write your tests. The supported testing frameworks are listed here.

The configuration file example above assumes that your source files are in the src folder, that you are using Jasmine and your tests are in the test folder and their names end with Spec. Source files location is specified as a pattern, however in many case the loading order of your source files matters, so you may need to specify some of them one by one.

a path to a node.js executable that will be used to run wallaby.js itself (not necessarily your tests).

When you create a Run Configuration, it is recommended to use the node.js version selected by default, unless you really need to change the version for some reason.

Once you have created and saved the configuration, you can start it. The first time you run it, wallaby.js may take a minute or two to install all the dependencies it needs, such as node.js and PhantomJs. It only does this once and then uses the saved dependencies. The dependencies are updated automatically when required.

Once you have started the run configuration, in the bottom right-hand corner of the screen you’ll see the wallaby status indicator. Its job is pretty simple: when it displays a spinner, your tests are running; when it’s red, you have some failing tests; when it’s green, all of your tests are passing.

Tool window

When wallaby.js starts, it also displays a tool window. While writing code, you may not need the window to be opened, so you can collapse it. You can expand it any time by clicking the wallaby.js status indicator (or using the standard way to open a run configuration tool window).

In the tool window you can see the Failing Tests tab and the Wallaby Console tab.

The Failing Tests tab displays all tests that are currently failing along with the error stacks and registered console.log calls. Some bits of the displayed information are hyperlinks that you can use with your mouse or keyboard to navigate to different places, for example to the exact error line, or a failing test, or a place where something is logged to console.

The Wallaby Console tab also displays some additional information about test execution progress. The tab can also be useful for troubleshooting wallaby.js issues.

Code coverage

Once wallaby.js is running, you can see the code coverage in the source files that it tracks (specified in the configuration file). The coverage is live, so you can start changing your code and the coverage will automatically be updated, just as you type.

As you can see, there are various colored squares displayed for each line of your source code.

Gray square means that the source line is not covered by any of your tests.

Green square means that the source line is covered by at least one of your tests.

Yellow square means that the source line is only partially covered by some of your tests.

Red square means that the source line is the source of an error or failed expectation, or is in the stack of an error.

Pink square means that the source line is on the execution path of a failing test.

Clicking a square against a source code line will display a window with the information about the tests covering the line, including any error messages and console.log messages.

You can search inside the window by using standard Cmd/Ctrl + F command and navigate links by using Cmd/Ctrl + B.

Short error messages, expectation failures and console.log messages are also displayed inline, right where and when they happen. This is very convenient as it allows you to avoid context switching and fix the issues in place, as you write your code.

Context actions

Another way to access some source code line/context actions is to use the light bulb quick actions, or just press Alt + Enter on any line. The actions that you can use include:

Show line test(s) action: works similar to clicking a source code line square and displays the line related test data.

Jump to failing test action: quickly navigate to the failing test from any ‘pink’ context (the failing test execution path).

Jump to error source action: quickly navigate to the source of the test error from any ‘pink’ context (failing test execution path).

Show line uncovered regions: this action is useful for “yellow” lines to display what exactly is not covered in the line. Not covered expressions will be highlighted in red.

Show assertion data diff: displays the difference between the actual and expected data of the failed assertion (normally an equality one).

Show file uncovered regions: similar to the previous action, this displays uncovered regions for the whole file. The red highlights for both actions can be removed by pressing “Esc” (or you can just start changing the file code and they will disappear).

Run line test(s): the action is pretty simple (yet so wanted by so many) – it just runs a single test (if invoked from within the test) or all related tests (if invoked within some source code covered by the tests).

Run file test(s): the action runs all tests within the test file it is invoked in, or all tests in all the test files that cover the source file that the action is invoked within.

Update file snapshots: the command updates all Jest snapshots in the current (focused) file, or all snapshots in all the test files that cover the source file that the action is invoked within.

Update test snapshots: the command updates snapshots of a single test (if invoked from within the test) or all snapshots in all related tests (if invoked within some source code covered by the tests).

All of the described actions can also be mapped to any keyboard shortcuts you prefer for extra productivity. You can do so in Settings - Keymap (search for wallaby in the keymap settings).

The recommended workflow is just to keep wallaby.js up and running as you edit your code. It should pick up existing file changes, file deletion, adding new files and tests (as long as they are listed in files patterns in the configuration file). Wallaby.js does its best to track the dependencies between your files and tests, but occasionally you may need to restart it if your changes are not picked up. You can stop/start wallaby.js any time by stopping/starting the active run configuration.

Trial version

Note that trial version of wallaby.js (the one without a valid license) will be displaying prompts and stopping after some time, so you will need to restart the tool or your editor. Please contact us if you would like to arrange a trial period for yourself or your team without activation prompts and restarts.