Running Selected Tests feature used together with Value Explorer and Advanced Logging features enables highly productive workflow.

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

However, because a piece of code can be covered by multiple tests (from the same test file, or from multiple test files), by default wallaby re-runs all affected tests and displays combined code coverage for the covered piece of code.

Testing frameworks support special functions, that allow to focus a specific test or a test suite. In Jest, Mocha, and AVA you may use .only to specify which tests are the only ones you want to run in a test file:

describe('suite', () => {
  it.only('test 1', () => { // to only run test 1
    ...
  });

  it('test 2', () => {
    ...
  });
});
describe.only('suite 1', () => { // to only run suite 1
  ...
});

describe('suite 2', () => {
  ...
});

In Jasmine you may use fit/fdescribe:

describe('suite', () => {
  fit('test 1', () => { // to only run test 1
    ...
  });

  it('test 2', () => {
    ...
  });
});
fdescribe('suite 1', () => { // to only run suite 1
  ...
});

describe('suite 2', () => {
  ...
});

When wallaby detects the use of the test/suite focusing functions in a test file, it automatically starts running only this specific test/suite, and stops running tests from other test files. As a result, in this mode wallaby will display code coverage and output only for this specific test/suite.

To find out whether wallaby is operating in this mode and is only executing some of your tests, you may inspect the Wallaby Tests output header. In the default mode it usually says:

No failing tests, N passing

and if some tests are selected, it’ll also display names of test files with focused/selected tests.

No failing tests, N passing (only executed test.js)

Additional configuration

Because wallaby attempts to detect the use of test focusing functions before actually running your tests, it may sometimes miss some cases (or produce false positives) due to the dynamic nature of JavaScript and because of the unlimited variety of ways to use the test focusing functions.

If you have some focused tests/suite in a test file, but wallaby is still displaying results from other test files, you may force wallaby to select and run this specific test file only, by adding the special file.only comment anywhere in the test file:


// file.only
...

This way wallaby will only be running focused tests from the test file, or all tests in the test file if none of them is marked with a test selection function, such as .only/fit.

If you encounter a scenario when using the automatic test focusing is not desirable, you may turn the feature off in your wallaby config:

module.exports = function (wallaby) {
  return {
    ...
    automaticTestFileSelection: false
  };
};

Test file selection

Sometimes you may also need to tell wallaby to only run (or to ignore) a specific test file (or a set of test files), without changing your wallaby config file. To allow it, wallaby supports special comments.

To only run a specific test file (or test files), you may add the following comment anywhere in the test file (or files):


// file.only
...

To skip a specific test file (or test files) and don’t run it, you may add the following comment anywhere in the test file (or files):


// file.skip
...

You may change the default comments by using the hints.testFileSelection setting and by specifying any regular expression you want:

module.exports = function (wallaby) {
  return {
    ...

    hints: {
      testFileSelection: {
        include: /file\.only/,
        exclude: /file\.skip/
      }
    }
  };
};