@magic/test

@magic/test

Declaratively test your ecmascript module files. No transpiling of either your codebase nor the tests. Incredibly fast.

Getting Started

Be in a nodejs project.

Install

npm i --save-dev --save-exact @magic/test

Create a test

// test/yourFileToTest.jsexport default [  { fn: () => true, expect: true, info: 'true is true' },]

Add npm scripts

{  "scripts": {    "test": "t -p",    "coverage": "t"  }}

Run tests

npm test

Example output:

### Testing package: @magic/testRan 2 tests. Passed 2/2 100%

Faster output from a bigger project:

### Testing package: @artificialmuseum/engineRan 90307 tests in 274.5ms. Passed 90307/90307 100%

Features

Quick Examples

Simple test

export default [  { fn: () => 1 + 1, expect: 2 },  { fn: () => 'hello', expect: 'hello']

Async test

import { promise } from '@magic/test'export default [  {    fn: promise(cb => setTimeout(() => cb(null, true), 100)),    expect: true,    info: 'handle promises',  },]

Deep equality

import { is } from '@magic/test'export default [  {    fn: () => ({ a: 1, b: 2 }),    expect: is.deep.equal({ a: 1, b: 2 }),    info: 'deep compare objects',  },]

Mock function

import { mock } from '@magic/test'export default [  {    fn: () => {      const spy = mock.fn()      spy('arg1')      return spy.calls.length === 1    },    expect: true,    info: 'mock tracks calls',  },]

Learn More

  • - hooks, promises, types, multiple tests
  • - deep, fs, curry, log, vals, env, http, mock, has
  • - mount components, interact, assert
  • - flags, sharding, performance tips
  • - prevent state leakage between tests
  • - programmatic error handling
  • - release history

This library tests itself. Have a look at the tests on GitHub.