m.test
m(icro)test is a lightweight test runner for node.js written in es6+
Last updated a year ago by ivoputzer .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install m.test 
SYNC missed versions from official npm registry.

m.test

travis npm-dependencies standard-js npm-package-quality npm-node-version npm-version npm-license

m(icro)test is a lightweight test runner for node.js written in es6+ (~4kb).

donations

thanks for your support! gratipay

install

install m.test directly from npm to project's devDependencies.

npm install --save-dev m.test

usage

test files are run by simply passing them to node. for a given test/index.js run the following command to execute the suite:

node test

run the following one to enable node's debugger:

node debug test

cli

more utilities to run your suites are available through the cli. if no files are given they will be looked up from ./test recursively.

m.test [options] [files]

when executing suites through the cli m.test will be assigned to global.test by design. the following line can be omitted:

const {test} = require('m.test')

further instructions can be accessed via --help flag and man-pages by executing either m.test --help or man m.test within your shell.


basic usage

const {ok} = require('assert')

test('it just works!', function () {
  ok(true)
})

async usage

const {ok} = require('assert')

test('it works async too!', function (done) {
  setTimeout(function () {
    ok(true)
    done()
  }, 0)
})

test('done takes a error argument!', function (done) {
  setTimeout(function (err = null) {
    done(err)
  }, 0)
})

test('runner works with Promise', function (done) {
    let promise = new Promise(function (resolve, reject) {
      setTimeout(function () {
        resolve(true)
      }, 0)
    })

    promise.then(result => {
      ok(result)
      done()
    })
  })

context usage

test('can be used as a context', function () {
  test('works!', function (done) {
    done(null)
  })
  test('works!', function (done) {
    done(null)
  })
})

alias usage

const {test: context, test: describe, test: it} = require('m.test')

context('given some context', function () {
  describe('your subject', function () {
    it('just works!', (done) => done(null))
  })
})

beforeEach afterEach usage

test('description', function (done) {
  done(null)
})
beforeEach(done => setup(done))
afterEach(done => teardown(done))

it is important to call beforeEach and afterEach wrap functions after test functions themselves. when using wraps within nested suites consider their contextual binding.

test('description 1', function () {
  test('description 1.1', Function.prototype)
  test('description 1.2', Function.prototype)
  beforeEach(done => setup(done))
  afterEach(done => teardown(done))
})
test('description 2', function () {
  test('description 2.1', Function.prototype)
  test('description 2.2', Function.prototype)
})

(in the example above hooks would be called for 1.1 e 1.2)


skip modifier

test.skip('description', function () {
  // this function will never be called
})

the skip modifier comes with an optional doSkip=true parameter that enables/disables the skip behavior according to the expression:

test.skip('description', function () {
  // this test will be skipped when NODE_ENV=CI
}, /CI/gi.test(process.env.NODE_ENV))

timeout modifier

test.timeout('description', function () {
  // this test will fail if it exceeds 200ms of execution
}, 200)

the timeout modifier comes with an optional doTimeout=true parameter that enables/disables the timeout behavior according to the expression:

test.timeout('description', function () {
  // this test will have a timeout when NODE_ENV=CI
}, 200, /CI/g.test(process.env.NODE_ENV))

view more

Current Tags

  • 0.0.58                                ...           latest (a year ago)

54 Versions

  • 0.0.58                                ...           a year ago
  • 0.0.57                                ...           3 years ago
  • 0.0.56                                ...           3 years ago
  • 0.0.55                                ...           3 years ago
  • 0.0.54                                ...           3 years ago
  • 0.0.53 [deprecated]           ...           3 years ago
  • 0.0.51                                ...           3 years ago
  • 0.0.50                                ...           3 years ago
  • 0.0.49                                ...           3 years ago
  • 0.0.48 [deprecated]           ...           3 years ago
  • 0.0.47                                ...           3 years ago
  • 0.0.46                                ...           3 years ago
  • 0.0.45 [deprecated]           ...           3 years ago
  • 0.0.44                                ...           3 years ago
  • 0.0.43                                ...           3 years ago
  • 0.0.42                                ...           3 years ago
  • 0.0.41                                ...           3 years ago
  • 0.0.40                                ...           3 years ago
  • 0.0.39                                ...           3 years ago
  • 0.0.38                                ...           3 years ago
  • 0.0.36                                ...           3 years ago
  • 0.0.35                                ...           3 years ago
  • 0.0.34                                ...           3 years ago
  • 0.0.33                                ...           3 years ago
  • 0.0.32                                ...           3 years ago
  • 0.0.31                                ...           3 years ago
  • 0.0.30                                ...           3 years ago
  • 0.0.29                                ...           3 years ago
  • 0.0.28                                ...           3 years ago
  • 0.0.27                                ...           3 years ago
  • 0.0.26                                ...           3 years ago
  • 0.0.25                                ...           3 years ago
  • 0.0.24                                ...           3 years ago
  • 0.0.23                                ...           3 years ago
  • 0.0.22                                ...           3 years ago
  • 0.0.21                                ...           3 years ago
  • 0.0.20                                ...           3 years ago
  • 0.0.19                                ...           3 years ago
  • 0.0.18                                ...           3 years ago
  • 0.0.17                                ...           3 years ago
  • 0.0.16                                ...           3 years ago
  • 0.0.15                                ...           3 years ago
  • 0.0.14                                ...           3 years ago
  • 0.0.13                                ...           3 years ago
  • 0.0.12                                ...           3 years ago
  • 0.0.11                                ...           3 years ago
  • 0.0.10                                ...           3 years ago
  • 0.0.9                                ...           3 years ago
  • 0.0.6                                ...           3 years ago
  • 0.0.4                                ...           3 years ago
  • 0.0.3                                ...           3 years ago
  • 0.0.2                                ...           3 years ago
  • 0.0.1                                ...           3 years ago
  • 0.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 55
Dependencies (0)
None
Dev Dependencies (1)

Copyright 2014 - 2017 © taobao.org |