Minimal test runner
npm install --save-dev testra
- Create tests with title and callback (can be async).
- Call asserts inside test:
is
,ok
,not
,throws
. - Run the tests with
run
.
import { test, is, ok, run, throws } from 'testra'
test('Test 1', () => {
ok(true, 'truthy')
is({ a: 1 }, { b: 2 }, 'deep equal')
throws(() => someFn(), 'should throw')
})
test('Test 2', async () => {
await new Promise(resolve => setTimeout(resolve, 1000))
ok(true, 'async')
})
run()
Additional files can be imported to enqueue tests before calling run
.
import { run } from 'testra'
import './tests-1.js'
import './tests-2.js'
run()
Alternatively, provide an async callback to run
where the tests are dynamically imported.
run(async () => {
// ..tests..
})
run(async () => {
await setupThings()
// ..tests..
})
.finally(cleanupThings)
The test report uses console
to display the results with visual structure.
- In the browser it uses
console.group
and CSS to style some text. - On the server it uses ANSI color sequences for the terminal. It also exits with code
1
when any test fails, for use in build and test pipeline.