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.
$ npm install eater -g
// test/sometest.js
const assert = require('assert');
assert(1 === 2); // always failure
$ eater
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
$ eater test/sometest.js test/foo.js test/bar.jd
If you are power-assert user
$ npm install eater -D
$ npm install power-assert espower-loader -D
// script/enable-power-assert.js
require('espower-loader')({
cwd: process.cwd(),
pattern: 'test/**/*.js'
});
$ eater --require ./script/enable-power-assert.js
$ 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.
// 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;
}
});
$ eater --require ./script/enable-babel.js
$ npm install babel-preset-power-assert -D
{
"presets": ["es2015", "babel-preset-power-assert"]
}
$ eater --require ./script/enable-babel.js
$ npm install nyc -D
$ nyc eater
eater reads the arguments from settings.
- package.json
- .eaterrc
{
"name": "eaterDemo",
"version": "1.0.0",
"scripts": {
"test": "eater"
},
"eater": {
"dir": "test/core",
"require": [
"./enable-power-assert.js",
"./enable-jsx.js"
]
}
}
.eaterrc is JSON5 format so you can write comment and trailing commas.
{
dir: "test/core",
require: [
"./enable-power-assert.js",
"./enable-jsx.js",
],
}
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.
$ npm install eater-pacman-reporter
$ eater --reporter eater-pacman-reporter
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);
});