Minimum Viable Testing framework
npm install mvtmvt@4 for CommonJS usage.
mvt cli or by simply calling node [test-file].js
sh
Install globally
$ npm install --global mvt
Install for project
$ npm install --save-dev mvt
`
Usage
`sh
mvt
OR
mvt test
OR
mvt test.js test2.js
OR
mvt --verbose
OR
mvt test --verbose
OR
node test.js --verbose
etc...
`
`js
import test from 'mvt'
test.setup({ verbose: true })
test.after(() => console.log('test.after invoked'))
test.before(() => console.log('test.before invoked'))
test('assert.is works', (assert) => {
assert.is(1, 1)
})
test.failing('test.failing and assert.fail works', (assert) => {
assert.fail()
})
test.todo('test.todo works')
test.skip('test.skip works', (assert) => assert.truthy('skipped'))
test.only('test.only works', (assert) => assert.truthy('only'))
test.bench('test.bench works', (assert) => {
return new Promise((resolve, reject) => {
setTimeout(() => resolve(), 200)
})
}, { samples: 5, max: 300 })
`
!Output
API
Test Function
The only thing this module exports.
$3
Main function, give it a message and a test function. Test function
receives the assert object (see below).
- message: (String) Description of test
- testFunction: ([Async]Function) Description of test
Setup and Teardown
$3
Use this to configure your tests.
- opts: (Object)
- verbose (Boolean) - Print every test if true
$3
Run this before we start running any tests. [callback can be async]
$3
Run this after we run all tests. [callback can be async]
Test Modifiers
$3
Tests will only be run on any tests run with this modifier.
$3
Skip that test (logical enough).
$3
This test must fail. If it passes, we'll fail your whole test suite. Goteem.
$3
This is just a placeholder for your good intentions.
Special Tests
$3
Run the testFunction opts.samples || 10 times. If average run duration is
more than opts.max || 100 milliseconds fail the test.
- opts: (Object)
- samples (Number) - How many times we should run the testFunction
- max (Number [in ms]) - Maximum average duration threshhold
- parallel (Boolean) - If Async Func run in parallel, default is false
- cb (Function) - Called with { msTotal, msAvg } on bench completion
Assertions
Methods available on assert object passed to testFunction
- is ( a, b ) - a and b must be identical
- not ( a, b ) - a and b must not be identical
- pass () - Passes errydamntime
- fail () - Fails errydamntime
- true ( a ) - a must be strictly true
- false ( a ) - a must be strictly false
- truthy ( a ) - a must be truthy
- falsy ( a ) - a must be falsy
- contains ( a, b ) - JSON.stringify(a) must contain (String)b
- doesNotContain ( a, b ) - JSON.stringify(a) must not contain (String)b
- lessThan ( a, b ) - a must be less than b
- greaterThan ( a, b ) - a must be greater than b
- deepEqual ( a, b ) - a must be deepEqual to b
- notDeepEqual ( a, b ) - a must not be deepEqual to b
- throws ( a ) - a must be a function, and it must throw
- notThrows ( a ) - a must be a function, and it must not throw
- throwsAsync ( a ) - a must be an async function, and it must throw
- notThrowsAsync ( a ) - a must be an async function, and it must not throw
Notes
- If your test file is called with the --verbose flag it will list all passed tests
- It fails fast and hard with process.exit(1)
- If you have diff` installed as a peer