assert-raisins
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

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-raisins

Write 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.js

Run individual test:

# by line number
./node_modules/.bin/ars test/someTest.js:123

Other things available:

  • it which is an alias for test
  • beforeEach() to run some code before each test in a file
  • beforeAll() 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

Readme

Keywords

none

Package Sidebar

Install

npm i assert-raisins

Weekly Downloads

3

Version

2.0.0

License

MIT

Unpacked Size

42.2 kB

Total Files

30

Last publish

Collaborators

  • artemavetisyan