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 🙏

© 2025 – Pkg Stats / Ryan Hefner

redtea

v5.0.6

Published

redtea ===

Downloads

279

Readme

redtea

Test framework for JavaScript.

Usage

// test.js
import describe from 'redtea';

export default describe.batch(
  'My tests',
    describe('Number', 1, {type: Number}),
);
sudo npm install --global redtea
npm install --save-dev redtea
redtea test.js
My tests
  Number (number 1)
    √ is a Number

1 test(s), 1 passed, 0 failed

describe

describe() is the core function of redtea. It will assert a given value against an object of properties.

Notation

type DESCRIBE = (label: string, value: any, assertions: ASSERTIONS) => Function;

Example

describe('Is a number and is equal to 10', 10, {type: Number, value: 10});

batch

Use batch if you want to group tests together. You can use nested groups of tests this way too.

Notation

type BATCH = (label: string, ...tests: Array<Function>) => Function;

Example

describe.batch('Groups',
  describe.batch('Group 1'),
  describe.batch('Group 2',
    describe.batch('Group 3'),
  ),
);

promise

You can evaluate the return of a promise using promise.

Notation

type PROMISE = (label: string, promise: () => Promise, assertions: ASSERTIONS);

Example

describe.promise(
  'it should fulfill "hello"',
  () => new Promise(resolve => resolve('hello')),
  {value: 'hello'}
);

// Catching errors
describe.promise(
  'it should reject promise',
  () => new Promise((resolve, reject) => reject(new Error('Ouch'))),
  {
    type: Error,
    has: {message: 'Ouch'},
  }
);

emitter

You can also assert events emitted by an emitter.

Notation

type EMITTER = (label: string, emitter: () => EventEmitter, assertions: ASSERTIONS);

Example

import {EventEmitter} from 'events';

class Emitter extends EventEmitter {
  constructor(name) {
    super();
    this.name = name;
    process.nextTick(::this.greetings);
  }
  greetings() {
    this.emit('hello', this.name);
  }
}

describe.emitter(
  'it should greet "hello John"',
  () => new Emitter('John'),
  {
    emits: {
      hello: {
        wait: 250,
        value: 'John',
      }
    }
  }
);

// Make sure some events are not emitted
describe.emitter(
  'it should not throw error',
  () => new Emitter('John'),
  {
    not: {
      emits: {
        error: 5000,
      }
    },
  }
);

Assertions

Notations

type ASSERTIONS = {
  type?: TYPE,
  types?: TYPE[],
  mixed?: TYPE[],
  mixedArray?: TYPE[],
  value?: any,
  has?: any,
  shape?: Object,
  some?: (item: any, index: number, items: Array<any>) => boolean,
  every?: (item: any, index: number, items: Array<any>) => boolean,
  above: number | Date,
  below: number | Date,
  not?: ASSERTIONS,
  emits: EMITTERS,
};

type TYPE = Function | null | TYPE_EXTRA | Array<Function | null | TYPE_EXTRA>;

type TYPE_EXTRA = {
  mixed?: [TYPE],
};

type EMITTERS = {
  [event: string]: ASSERTIONS & {wait?: Number},
};

value: any

The value to match that. We use lodash's isEqual for comparisons.

define('Value', 10, {value: 10});

type: TYPE

Type comparison.

define('Is null', null, {type: null});
define('Is a regular expression', /a/, {type: RegExp});

class Foo {}
define('Is a foo', new Foo(), {type: Foo});

// Arrays
define('Array type', [1, 2, 3], {type: [Number]});

mixed: Array<TYPE>

define('Is either number or string', 1, {mixed: [Number, String]});

mixedArray: Array<TYPE>

define('Items are either boolean or an array of numbers', [true, [1]], {mixedArray: [Boolean, [Number]]});

has: any

String

Will perform a regular expression

define('Has abc', 'abcdefgh', {has: /abc/});

Array

Has at least one item matching.

define('Has 1', [1, 2, 3], {has: 1});

Object

Check if properties exist.

define('Has foo: 1', {foo: 1, bar: 2}, {has: {foo: 1}});
// property exists
define('Has foo', {foo: 1, bar: 2}, {has: 'foo'});
// properties exist
define('Has foo and bar', {foo: 1, bar: 2}, {has: ['foo', 'bar']});

some: (item: any, index: number, items: Array<any>) => boolean

Check if some items of the array match.

define(
  'At least 1 item greater than 5',
  [1, 5, 10],
  {some: (number => number > 5)}
);

every: (item: any, index: number, items: Array<any>) => boolean

Check if every items of the array match.

define(
  'All items greater than 5',
  [10, 15, 20],
  {every: (number => number > 5)}
);

above: number | Date

define(
  'Number is above 2',
  3,
  {above: 2}
);

define(
  'Date is in the future',
  new Date([2020]),
  {above: new Date()}
);

below: number | Date

define(
  'Number is below 2',
  1,
  {below: 2}
);

define(
  'Date is in the past',
  new Date([1980]),
  {below: new Date()}
);

between: Array<number> | Array<Date>

define(
  'Number is between 1 and 3',
  2,
  {between: [1, 3]}
);

define(
  'Date is between last year and next year',
  new Date(),
  {between: [new Date([2015]), new Date([2016])]}
);