Zero-dependency light weight testing & benchmarking tool for node-js.
- ✅ It's really simple.
- ✅ Individual test isolation
- ✅ Test startup and execution time in vacuum
- ✅ Actual stacktraces
- ✅ Zero dependencies
For non-conventional testing, of course.
npm i test-a-bit --save-dev
Each test file should use execute
function to define a single test:
import { execute } from 'test-a-bit'
// One execute per test file
execute('my test', (success, fail) => {
// Your test logic here
if (someCondition) {
success('test passed!') // Resolves test immediately
} else {
fail('test failed!') // Resolves test immediately
}
})
// Async example
execute('async test', async (success, fail) => {
try {
const result = await someOperation()
success('all good') // Resolves test
} catch (err) {
fail(err.message) // Resolves test with failure
}
})
There are several ways to run your tests:
Run a single test file directly:
node tests/my-test.js
Run multiple test files with specific options:
import { runner } from 'test-a-bit'
await runner([
{ script: './tests/first.js' },
{ script: './tests/second.js', timeout: 1000 },
{ script: './tests/debug.js', silent: false }, // show console output
])
Automatically find and run all tests in a directory:
import { auto_runner } from 'test-a-bit'
await auto_runner('./tests/', { timeout: 1000 })
Control console output visibility:
// Global silent mode (default: true)
await runner(tests, { silent: true })
// Per-test silent mode
await runner([
{ script: './test1.js', silent: false }, // show output
{ script: './test2.js' }, // inherit global silent setting
])
Stop execution immediately when a test fails:
await runner([
{ script: './test1.js' },
{ script: './test2.js', hard_break: true }, // break if this fails
{ script: './test3.js' }, // won't run if test2 fails
], { hard_break: false }) // global setting
await runner([
{ script: './quick.js', timeout: 100 },
{ script: './slow.js', timeout: 5000 },
{ script: './infinite.js', timeout: -1 }, // no timeout
])
Defines a single test. Use one per test file.
name
: Test name (string)testFn
: Test function(success, fail) => void
success(message)
: Call to pass the test (resolves immediately)fail(message)
: Call to fail the test (resolves immediately)
precision
: Time measurement precision ('milli', 'micro', 'nano')
Runs multiple test files in sequence.
tests
: Array of test configurationsscript
: Path to test filetimeout
: Test timeout in ms (-1 for no timeout)silent
: Control test's console outputhard_break
: Stop execution on test failure
options
:timeout
: Default timeout (default: 5000ms)silent
: Control console output (default: true)hard_break
: Stop on first failure (default: false)log
: Show summary after completion
Automatically discovers and runs tests in a directory.
directory
: Path to test directoryoptions
: Same as runner options
MIT License - feel free to use this project commercially.
With love ❤️ from Ukraine 🇺🇦