Skip to content

A library for running Mocha tests in parallel

License

Notifications You must be signed in to change notification settings

funbox/frontend-tests-runner

Repository files navigation

@funboxteam/frontend-tests-runner

npm

A library for running Mocha tests in parallel and watching files changes in live mode.

По-русски

Installation

npm install --save-dev @funboxteam/frontend-tests-runner

Usage

Example of usage:

const config = {
  parallelTestsCount: 2,
  testFiles: './src/tests/e2e/*.js',
  project: {
    build() {
      // Build project function. Must return Promise.
    },
    addListener(event) {
      // Even subscription function. There're two possible events
      //   buildStart — the project building has started;
      //   buildFinish — the project building has finished;
      // Helpful for live testing.
    }
  }
};

const Runner = require('@funboxteam/frontend-tests-runner');
const runner = new Runner(config);
runner.start();

For more check examples directory.

Configuration

Example of all configuration options and their defaults:

module.exports = {
  // A number of files with tests running in parallel.
  // Optional.
  parallelTestsCount: 1,

  // Run tests in live mode (enabling watching for files changes).
  // Optional.
  live: false,

  // Write logs for each test file separately.
  // Optional.
  separatedLogs: false,

  // Directory name for `separatedLogs`.
  // Optional.
  logDir: 'test-logs',

  // Glob with tests files, for exampe: `tests/\*.js`.
  // Required.
  testFiles: undefined,

  // Return test files for run. Function can be async.
  // Optional.
  filterTestsFiles: (files, isFilteredByOnly) => {
    // e.g.:
    // if (isFilteredByOnly) return files;

    // const testsFilesDependencies = getTestsFilesDependencies(files);
    // const changedFiles = getChangedFiles();

    // return getAffectedTestsFiles(testsFilesDependencies, changedFiles);
  },

  project: {
    build() {
      // Build project function. Must return Promise.
    },
    addListener(event) {
      // Event subscription function. There're two possible events:
      //   buildStart — the project building has started;
      //   buildFinish — the project building has finished.
      // Helpful for live testing.
    }
  },

  // Mocha config https://mochajs.org/#command-line-usage.
  // Optional.
  mocha: {
    // Test timeout threshold (in milliseconds).
    // https://mochajs.org/#-timeout-ms-t-ms
    // Optional.
    timeout: 30000,

    // Retry failed tests this many times.
    // https://mochajs.org/#-retries-n
    // Optional.
    retries: 0,

    // Disable color output.
    // https://mochajs.org/#-color-c-colors
    // Optional.
    noColors: false,

    // Additional args object for Mocha.
    // Optional.
    args: {
      // e.g.:
      // '--full-trace': 'true',
      // '--require': [
      //   '@babel/register',
      //   'babel-polyfill',
      // ],
    },
  },
}

Sponsored by FunBox