EAsy Test runnER
JavaScript
Latest commit 5bf1100 Nov 6, 2016 @yosuke-furukawa 3.2.0
Permalink
Failed to load latest commit information.
bin Rename pattern to glob Jun 19, 2016
images Describe test function Apr 25, 2016
lib
test Merge pull request #52 from yosuke-furukawa/feature_only_test Nov 6, 2016
.babelrc Remove espower-babel for REAME and check babel-preset-power-assert Apr 28, 2016
.eaterrc
.eslintrc.json Lint stricter Jul 3, 2016
.gitignore
.travis.yml Support Node v6 Apr 30, 2016
README.md feat: implements eater:only and only function for exclusive test Nov 5, 2016
index.js
package.json
runner.js Add test runner Apr 25, 2016

README.md

Eater

npm version Build Status Coverage Status

logo

Eater is Ea sy t est runn er . Eater has one simple rule.

If test file outputs `stderr` message, the test failed.

Features

  • Multi-process: All eater test files run as separate processes and eater does not launch too many processes more than CPU-core number.
  • Easy mock: An eater test does not affect the other tests, but mock object sometimes kills your test.
  • Happy async: eater aims is here to handle async test well. Each eater files will run in Node.js child_process, so the tests always should be async first. If your tests mix sync and async tests, you will have a headache to maintain the tests.

Demo

demo

How to use

1. Install

$ npm install eater -g

2. Write some tests

// test/sometest.js
const assert = require('assert');
assert(1 === 2); // always failure

Run

$ eater

image

eater --dir and --ext and --glob

eater searches JavaScript files under process.cwd()/test dir by default. If you want to change the dir, use --dir option.

$ eater --dir spec/

And if you changed test file extension, like .jsx/.es6/.test.js, you use --ext option.

$ eater --ext jsx

eater can find test files using glob pattern match. you use --glob option.

$ eater --glob **/__test/**/*.js

file

$ eater test/sometest.js test/foo.js test/bar.jd

If you are power-assert user

1. install power-assert and espower-loader

$ npm install eater -D
$ npm install power-assert espower-loader -D

2. enable power-assert

// script/enable-power-assert.js
require('espower-loader')({
    cwd: process.cwd(),
    pattern: 'test/**/*.js'
});

3. run tests with --require

$ eater --require ./script/enable-power-assert.js

power-assert

If you are babel(JSX) user

1. install babel-register or active-cache-babel-register

$ npm install eater -D
$ npm install babel-register -D

or

$ npm install eater -D
$ npm install active-cache-babel-register -D

Note: active-cache-babel-register improves babel transpilation performance.

2. enable babel

// script/enable-babel.js
require('babel-register')({ // or to use require('active-cache-babel-register')
  ignore: (file) => {
    if (file.match(/node_modules/)) return true;
    return false;
  }
});

3. run tests with --require

$ eater --require ./script/enable-babel.js

if you are power-assert and babel user:

1. install babel-preset-power-assert

$ npm install babel-preset-power-assert -D

2. write your .babelrc

{
  "presets": ["es2015", "babel-preset-power-assert"]
}

3. run tests with --require

$ eater --require ./script/enable-babel.js

Coverage

1. install nyc instead of istanbul

$ npm install nyc -D

2. run test with nyc

$ nyc eater

eater runner settings

eater reads the arguments from settings.

  • package.json
  • .eaterrc

package.json

{
  "name": "eaterDemo",
  "version": "1.0.0",
  "scripts": {
    "test": "eater"
  },
  "eater": {
    "dir": "test/core",
    "require": [
      "./enable-power-assert.js",
      "./enable-jsx.js"
    ]
  }
}

.eaterrc

.eaterrc is JSON5 format so you can write comment and trailing commas.

{
  dir: "test/core",
  require: [
    "./enable-power-assert.js",
    "./enable-jsx.js",
  ],
}

runner

If you would like to use test runner, eater has test function.

const calc = require('../foo/bar/calc');
const test = require('eater/runner').test;
const assert = require('assert');

test('give 2 arguments return sum', () => {
  const result = calc.sum(1, 2);
  assert(result === 3);
});

test('give 2 arguments return sum on async', () => {
  const result = calc.sumAsync(1, 2);
  result.then((value) => {
    assert(value === 3)
  });
});

Note that each subtests also run as separated processes, you don't have to care about sync/async stuff.

Use custom reporter

$ npm install eater-pacman-reporter
$ eater --reporter eater-pacman-reporter

pacman

Custom Reporters

Exclusive feature

The exclusivity feature allows you to run only the specified test code by adding // eater:only comment on top of your test code. Here's an example.

// eater:only
const test = require('eater/lib/runner').test;
const mustCall = require('must-call');
const assert = require('power-assert');

test('only is executed', () => {
  assert(true);
});

And if you need to exclude your test case, only function is helpful.

// eater:only
const only = require('eater/lib/runner').only;
const test = require('eater/lib/runner').test;
const mustCall = require('must-call');
const assert = require('power-assert');

test('this test should not execute', (_, fail) =>{
  fail('should not be executed');
});

only('only is executed', () => {
  assert(true);
});