assert-raisins
v2.0.1
Published
Minimalistic Node test runner.
Downloads
21
Readme
Assert-raisins
Minimalistic, debugger friendly test runner for Node.
Inspired by baretest
Features
- fast
- parallel
- run test for a line number
- no nesting
- better test cleanup (than after hooks)
- esm
- typescript types included
Usage
Install:
npm i --save-dev assert-raisinsWrite a test test/firstTest.js:
import { test } from 'assert-raisins'
import assert from 'node:assert'
test('first passing test', () => {
assert.ok(true)
})
test('first failing test', async () => {
assert.equal(1, 2)
})Run all tests:
./node_modules/.bin/ars test/**/*Test.jsRun individual test:
# by line number
./node_modules/.bin/ars test/someTest.js:123Other things available:
itwhich is an alias fortestbeforeEach()to run some code before each test in a filebeforeAll()to run some code before all tests in a file
Test cleanup
Use cleanup function to register some cleanup hook. If it happens to be called within beforeAll, it will be executed "after all". If it's called within beforeEach, it'll be run "after each", and if it's called within a test, it will be executed after that test. cleanup can be invoked multiple times.
In this example, the server will be stopped after each test:
import { cleanup } from 'assert-raisins'
class Server {
start() {
...
cleanup(() => this.stop())
}
}
beforeEach(async () => {
const server = new Server()
await server.start()
})Parallel tests
When running multiple test files, the load is distributed between concurrent workers (limited by the number of CPU cores). Each worker is passed TEST_WORKER_ID environment variable (so you can, for instance, create that many test databases).
typescript, jsx, sourcemaps, code coverage
Use NODE_OPTIONS environment variable for any of that. For example, for typescript:
NODE_OPTIONS="--enable-source-maps --loader ts-node/esm" ./node_modules/.bin/ars test/*.test.ts