Zero-dependency light weight testing & benchmarking tool for node-js.
This package is not ready for production, but still can be fun to use.
npm i test-a-bit --save-dev
Call runner(<test_scripts>, <options>)
Each test script running in a separate process. You can specify the timeout for each script.
/* run_test.js */
import { runner } from 'test-a-bit'
runner([
{ script: './tests/success.js' },
{ script: './tests/fail.js' },
{ script: './tests/timeout.js', timeout: 200 },
{ script: './tests/random.js', timeout: 200, silent: false },
],
{
silent: false, // log or not process output by default
timeout: 1000, // default timeout
}
).then(results => console.log(results, 'bye'))
List of objects with script
and timeout
.
Set to true
to suppress console output from console.log inside the tests.
Runner returns Promise with results map like this:
{
'12ebd1-9daf62-594cd5': {
uid: '12ebd1-9daf62-594cd5',
name: 'sample fail test',
note: 'oh, no!',
timeout: 200,
script: './tests/random.js',
silent: false,
result: 'fail',
delta: 0.09140002727508545,
delta_precision: 'milli',
delta_precision_sym: 'ms',
exit_code: 1
}
}
If you are lazy enough - just use auto_runner
to automatically run all scripts in the specific folder.
auto_runner('./tests/').then(results => console.log('bye'))
Each test is a separated file that calls the execute
method once with the test function. To indicate test result - run
the success
or fail
function.
/* tests/random-test.js */
import { execute } from 'test-a-bit'
execute('sample fail test', (success, fail, is_runner) => {
const rnd = Math.random()
if (!is_runner) console.log(`oh wow! rolled: rnd`)
success > 0.5
? success('got lucky!')
: fail('oh, no!')
})
Possible output:
[fail] sample fail test >> oh, no! / Δ=0.07ms
<name>
- Is a string - will be passed to the output.
<callback>
- Callback Function with your test inside.
Callback function has 3 arguments: result functions success
& fail
, and is_runner
flag.
Call this to mark test passed or failed respectively.
note
- string, will be passed to the output.
Is this test was runner by a runner (along with other tests). Might be handy to decide if you need to spam the console.
That's it. Have a fun! :3