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

https://github.com/codeworksfrance/toml-it

A stupid TOML integration tests typescript library
https://github.com/codeworksfrance/toml-it

codeworks integration-testing javascript jest toml typescript

Last synced: 1 day ago
JSON representation

A stupid TOML integration tests typescript library

Awesome Lists containing this project

README

          

# toml-it

[![npm package](https://img.shields.io/github/package-json/v/CodeWorksFrance/toml-it)](https://www.npmjs.com/package/toml-it) [![Node.js CI](https://github.com/CodeWorksFrance/toml-it/actions/workflows/nodejs-ci.yml/badge.svg)](https://github.com/CodeWorksFrance/toml-it/actions/workflows/nodejs-ci.yml)   [![eslint](https://github.com/CodeWorksFrance/toml-it/actions/workflows/eslint.yml/badge.svg)](https://github.com/CodeWorksFrance/toml-it/actions/workflows/eslint.yml)

`toml-it` it a simple integration tests runner. It tests the output of a `node` program.

## How to install?

```sh
npm i -D toml-it
```

## How to write a test?

Tests files must match the following pattern `**/*.spec.toml`.
The structure of a tests should be:

``` toml
stdout=""
description=""
args=""
```

## Run tests

If you are using `jest` as test runner, you can simply create a file `toml-it.spec.ts` and enter the following code:

```ts
import { TestRunner } from "toml-it";

describe('integration tests with toml', () => {
it('toml it', () => {
new TestRunner().run();
});
});
```

Then add the following command in your `package.json`:

```json
"scripts": {
...,
"test:integration": "tsc; jest",
},
```

## Example

If you want to test the following production code:

```ts
if (process.argv.length === 3) {
console.log("ok");
} else {
console.log("not ok");
}
```

You now could write two files:

### `notok.spec.toml`

```toml
stdout = "not ok"
args = "argument_1 argument_2 argument_3"
description="Should display 'not ok'"
```

### `ok.spec.toml`

```toml
stdout = "ok"
args = "argument_1"
description="Should display 'ok'"
```