There are 3 ways to control how code coverage is reported in wallaby.js.

Stopping instrumentation for a file

Sometimes you may need to disable code instrumentation for the whole file, you may do it by setting the instrument flag for the file.

module.exports = function () {
  return {
    files: [
      { pattern: 'src/helper.js', instrument: false },
      ...
    ],

    ...
  };
};

Note that in this case, when the file changes, wallaby.js may not be able to automatically run tests that exercise the code in the file and display inline messages for it, because the tool uses instrumentation to establish the dependencies between source code and tests. So setting the instrument: false flag works best for files that do not normally or frequently changed, such as libraries or various helpers/utils.

Stopping code coverage calculation for a file

Sometimes you may just need to exclude a file from code coverage calculation reported in the Wallaby App, and still be able to see its coverage indicators, inline errors and messages, etc., when the file is opened in your code editor.

You may use the filesWithNoCoverageCalculated setting in these scenarios. For example, the following config will exclude all files that name ends with -helper.js from code coverage calculation:

  module.exports = function () {

    return {
      ...
      filesWithNoCoverageCalculated: ['src/**/*-helper.js']
    };
  };

Stopping code coverage calculation for code blocks inside a file

Certain functions, statements or logical branches may be impossible or impractical to unit test. Similar to /* istanbul ignore next */, wallaby.js allows to ignore code for coverage purposes by using comment hints.

You may define your own hint by specifying a regular expression or a string, for example:

  module.exports = function () {

    return {
      ...
      hints: {
        ignoreCoverage: /ignore coverage/ // or /istanbul ignore next/, or any RegExp
      },
    };
  };

You may then use the hint for code blocks/branches that you would like to ignore for coverage purposes:

var object = parameter || /* ignore coverage: should never happen */ {};

if (simpleError ||
    /* ignore coverage */ reallyDifficultToProduceError) {

}
...

someFunMemberFunction: () => {
    // coverage assessed as normal
}

/* ignore coverage */
render() {
    // this whole body would not be factored for code coverage at all
}