npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

eater

v4.0.4

Published

eater is EAsy Test runnER

Downloads

175

Readme

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