$ npm install test-runner
A minimal test runner built around a single, core principle: if a test function completes successfully (or fulfils), it passes. If it throws (or rejects) it fails. It has no opinion how you write tests, or which (if any) assertion library you use.
const TestRunner = require('test-runner')
const runner = new TestRunner()
Passing test, sync.
runner.test('this will pass', function () {
const thought = 'Nothing failing here.'
})
Passing test, async.
runner.test('this will also pass', function () {
return Promise.resolve('Nothing failing here.')
})
Failing test, sync.
runner.test('this will fail', function () {
throw new Error('Definitely something wrong here.')
})
Failing test, async.
runner.test('this will also fail', function () {
return Promise.reject('Definitely something wrong here.')
})
To run the tests, execute the script:
$ node test.js
... or use the command-line tool to test multiple files:
$ test-runner test/*.js
EventEmitter ⏏
PromiseArrayEventEmitter ⏏Register tests and run them sequentially or in parallel. By default, testing begins automatically but can be set to start manually.
Kind: Exported class
Extends: EventEmitter
| Param | Type | Description |
|---|---|---|
| [options] | object |
|
| [options.log] | function |
Specify a custom log function. Defaults to console.log. |
| [options.manualStart] | boolean |
If true, you must call runner.start() manually. |
| [options.sequential] | boolean |
Run async tests sequentially. |
PromiseBegin testing. You'll only need to use this method when manualStart is true.
Kind: instance method of TestRunner
Fulfil: Array - Resolves with an array containing the return value of each test.
Register a test.
Kind: instance method of TestRunner
Chainable
| Param | Type | Description |
|---|---|---|
| name | string |
Each name supplied must be unique to the runner instance. |
| testFunction | function |
The test function. If it throws or rejects, the test will fail. |
No-op. Use this method when you want a test to be skipped.
Kind: instance method of TestRunner
Chainable
Only run this and other tests registered with only.
Kind: instance method of TestRunner
Chainable
| Param | Type |
|---|---|
| name | string |
| testFunction | function |
ArrayRun one or more test files. The output will be an array containing the export value from each module.
Kind: static method of TestRunner
| Param | Type | Description |
|---|---|---|
| globs | Array.<string> |
One or more file paths or glob expressions. |
© 2016-18 Lloyd Brookes <75pound@gmail.com>. Documented by jsdoc-to-markdown.
© 2010 - cnpmjs.org x YWFE | Home | YWFE