Home

Awesome

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

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

{
  "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);
});