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
- Host: GitHub
- URL: https://github.com/artemave/assert-raisins
- Owner: artemave
- License: mit
- Created: 2020-02-09T20:10:07.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-05-16T16:05:00.000Z (about 2 years ago)
- Last Synced: 2025-02-02T07:41:16.495Z (over 1 year ago)
- Topics: javascript, nodejs, test, test-framework, test-runner, testing
- Language: JavaScript
- Homepage:
- Size: 143 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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
```