An open API service indexing awesome lists of open source software.

https://github.com/artemave/assert-raisins

Minimalistic, debugger friendly test runner for Node
https://github.com/artemave/assert-raisins

javascript nodejs test test-framework test-runner testing

Last synced: 8 months ago
JSON representation

Minimalistic, debugger friendly test runner for Node

Awesome Lists containing this project

README

          

# Assert-raisins

Minimalistic, debugger friendly test runner for Node.

Inspired by [baretest](https://github.com/volument/baretest)

## Features

- [fast](https://github.com/artemave/node-test-runners-performance-comparison)
- 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`:

```javascript
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:

```javascript
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:

```sh
NODE_OPTIONS="--enable-source-maps --loader ts-node/esm" ./node_modules/.bin/ars test/*.test.ts
```