README
mvt
Minimum Viable Testing framework
A Minimalist Take on AVA's Approach to Testing
Because AVA is awesome. Security alerts on dev dependencies are not awesome. Especially when you use the same test library across dozens of projects. No matter how well maintained a project is, when it contains 300+ dependencies security alerts are going to occur.
But It's Just a Dev Dependency...
What's good about it
- It has 0 dependencies (1 dev dep, and that's ava :smirk:)
- It can be called via the
mvt
cli or by simply callingnode [test-file].js
- It doesn't transpile your code (the code you write is the code we test)
What it lacks (the most notable items)
- Concurrency
- That's not a thing here (likely never will be)
- Transpilation
- Also not a thing here (definitely never will be)
- Actually, maybe I should add this to "What's good..."
- I added it...
- TAP Reporter
- Happy to add it if there is any demand
- A community and product maturity
- The most crucial elements
- And the primary reason you may want to stick to AVA
Table of Contents
Install
# Install globally
$ npm install --global mvt
# Install for project
$ npm install --save-dev mvt
Usage
mvt
# OR
mvt test
# OR
mvt test.js test2.js
# OR
mvt --verbose
# OR
mvt test --verbose
# OR
node test.js --verbose
# etc...
const test = require('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 })
API
Test Function
The only thing this module exports.
( message, testFunction ) test
Main function, give it a message and a test function. Test function
receives the assert
object (see below).
message
: (String) Description of testtestFunction
: ([Async]Function) Description of test
Setup and Teardown
( opts ) test.setup
Use this to configure your tests.
opts
: (Object)verbose
(Boolean) - Print every test iftrue
( callback ) test.before
Run this before we start running any tests. [callback can be async
]
( callback ) test.after
Run this after we run all tests. [callback can be async
]
Test Modifiers
( message, testFunction ) test.only
Tests will only be run on any tests run with this modifier.
( message, testFunction ) test.skip
Skip that test (logical enough).
( message, testFunction ) test.failing
This test must fail. If it passes, we'll fail your whole test suite. Goteem.
( message ) test.todo
This is just a placeholder for your good intentions.
Special Tests
( message, testFunction, opts ) test.bench
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 thetestFunction
max
(Number [in ms]) - Maximum average duration threshholdparallel
(Boolean) - IfAsync Func
run in parallel, default isfalse
cb
(Function) - Called with{ msTotal, msAvg }
on bench completion
Assertions
Methods available on assert
object passed to testFunction
is
( a, b ) -a
andb
must be identicalnot
( a, b ) -a
andb
must not be identicalpass
() - Passes errydamntimefail
() - Fails errydamntimetrue
( a ) -a
must be strictlytrue
false
( a ) -a
must be strictlyfalse
truthy
( a ) -a
must be truthyfalsy
( a ) -a
must be falsycontains
( 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 thanb
greaterThan
( a, b ) -a
must be greater thanb
deepEqual
( a, b ) -a
must bedeepEqual
tob
notDeepEqual
( a, b ) -a
must not bedeepEqual
tob
throws
( a ) -a
must be a function, and it must thrownotThrows
( a ) -a
must be a function, and it must not throwthrowsAsync
( a ) -a
must be an async function, and it must thrownotThrowsAsync
( 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 testsIt fails fast and hard with
process.exit(1)
If you have
diff
installed as a peer dependency, we'll use that for string diffs. To make them more readable and what not.
License
MIT © Andrew Carpenter