https://github.com/marianmeres/test-runner
Simple test framework for node.js
https://github.com/marianmeres/test-runner
javascript nodejs testing testing-framework testing-tools
Last synced: 4 months ago
JSON representation
Simple test framework for node.js
- Host: GitHub
- URL: https://github.com/marianmeres/test-runner
- Owner: marianmeres
- Created: 2020-12-03T15:45:23.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-08-24T11:59:50.000Z (almost 2 years ago)
- Last Synced: 2025-12-06T03:52:02.312Z (7 months ago)
- Topics: javascript, nodejs, testing, testing-framework, testing-tools
- Language: TypeScript
- Homepage:
- Size: 217 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Simple testing framework for node.js
Simple, sequential, exception based test runner for node js.
## Features
- usual `test`, `skip`, `only`, `todo` api
- usual `before`, `beforeEach`, `afterEach`, `after` hooks
- async support
- speed
- timeout checks
#### Intentionally absent features
- parallel testing
- assertions ([tip](https://nodejs.org/api/assert.html))
- CLI (read more below)
## Installation
```shell
npm i -D @marianmeres/test-runner
```
## Quick start
```js
const suite = new TestRunner('My suite');
suite.test('My test', () => {
if (false) {
throw new Error('...')
}
});
suite.run();
```
See [examples](examples/) for more.
## CLI
```shell
npx test-runner [-d some-dir] [-d another-dir]
```
Or there is a `TestRunner.runAll` api, so something like this should work fine:
```js
// tests/index.js
const args = process.argv.slice(2);
const verbose = args.includes('-v');
const whitelist = args.filter((v) => v !== '-v');
TestRunner.runAll([__dirname, '../src'], { verbose, whitelist });
```
runnable as
```shell
$ node tests [-v] [whitelist]
```
or also watchable as
```bash
$ nodemon -q tests -- [-v] [whitelist]
```
#### How to `TestRunner.runAll([dirs], options)` ?
The `TestRunner.runAll` looks by default for `[/].test.[tj]s`. Each test file must
have the suite instance "default exported":
```js
// src/some.test.js
const suite = new TestRunner('My suite');
// tests definitions here...
export default suite;
// or depending on your env:
// module.exports = suite;
```
See [examples](examples/) for more.
## Screenshots
Screenshots are taken from [examples](examples/).
#### `node examples` (non verbose)

#### `node examples -v` (verbose)

## Limitations
This runner does not spawn the actual tests executions into separate child processes.
This is an intentional choice, but it comes with the price of not beeing able to truly
isolate/kill/cancel the test execution and its context (such as pending `setTimeout`s)
which can sometimes lead to unexpected results.
## Api
Check the [definition](./dist/mjs/test-runner.d.ts)
[files](./dist/mjs/renderer.d.ts).