Tutorials: JetBrains IDEs tutorial

First you need to install wallaby.js plugin for your IDE, if you haven’t done it yet.

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

If you are using Jest >= v24, you can try our new feature that allows to use Wallaby without any configuration.

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.

module.exports = function () {
  return {
    files: [
      'src/**/*.js'
    ],

    tests: [
      'test/**/*Spec.js'
    ]
  };
};

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.

You can read more about the configuration file format and other settings in the corresponding section.

Note that the tutorial config is using PhantomJs 2 to run tests. You may also use Chrome, Electron, or node.js as an environment to run your tests.

Run configuration

Continue by creating a new wallaby.js Run Configuration. Select Edit configurations from the drop-down menu in the top right-hand corner of the navigation bar, or from the Run menu.

In the configuration you can specify:

  • a name for the newly created configuration,
  • a path to your wallaby.js configuration file,
  • a path to a node.js executable that will be used to run wallaby.js itself (not necessarily your tests).

rc

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).

status

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.

Also, when a test error contains expected and actual properties, the Failing Tests tab displays compact diff view and can display side-by-side diff view. This allows to quickly debug failing equality assertions and snapshots.

Diff views

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.

coverage

  • 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.

window

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.

We also recommend reading about some more powerful ways to log things and measure code performance with wallaby.js.

Watch expressions in action

Watch performance in action

Value Explorer

Value Explorer integrates with Wallaby’s existing variable and expression output mechanisms (console.log, live comments, identifier expressions, and the Show Value command) to display values in an easy-to-navigate, real-time tree view. The tree can be expanded to any depth and can copy paths/values to the clipboard.

ValueExplorer in action

Test focusing

Sometimes when writing or debugging a test (or a set of tests, or a test file) for a particular feature, you may need to see code coverage and output only for this specific test (or the set of tests, or the test file). To allow it, wallaby fully supports testing frameworks test focusing functions, as well as special comments to focus/skip specific test files.

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:

context

  • 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.
  • Run project tests: the action runs all tests in your project.
  • Update project snapshots: the command updates all Jest snapshots in your project.
  • 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).
  • Show last run screen shot: the command displays the screen shot for the last run test (Important note: this feature is only available when running your tests using Chrome and PhantomJs).

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).

keymap

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.

Windows Subsystem for Linux (WSL)

If you are a Windows user wanting to run your Wallaby tests using WSL, you can specify to Use WSL in your Wallaby Run Configuration.

Jetbrains WSL

Run only on Save

If you would like to only run your tests when your files are saved to disk, you may update the run mode for your Wallaby session. Two commands are available on the left hand side of your Wallaby Run Configuration window (highlighted in the screenshot below):

  • Make current session Run on any change: the command makes your current Wallaby session start a test run when code is changed in your editor or when code is saved on disk.
  • Make current session Run only on save: the command makes your current Wallaby session start a test run ONLY when code is saved on disk.

JetBrains Run on Save

Important Note: to use the Run only on Save feature, you must first disable auto-save:

  • Go to File > Settings (Ctrl+Alt+S).
    • Go to Appearance & Behavior > System Settings.
      • Make sure the two are unchecked:
        • Save files on frame deactivation
        • Save files automatically if application is idle for x sec.
    • Go to Editor > General > Editor Tabs
      • Put a checkmark on “Mark modified files with asterisk”
      • (Optional but recommended) Under “Tab Closing Policy”, select “Close non-modified files first”. You may also want to increase the number of allowed tabs.
    • Click Apply > OK.

Trial version

Wallaby is installed with a limited-time feature-complete demo license that periodically prompts you to restart your editor to continue using the tool. Free Trial licenses are also available that allow you to evaluate without prompts and restarts.