# lib-monkey

> Random Integration Testing for NodeJS

Latest version **0.6.1** (published 2019-05-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install lib-monkey
pnpm add lib-monkey
yarn add lib-monkey
bun add lib-monkey
```

Provides the command `lib-monkey`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.6.1 |
| Published | 2019-05-07 |
| First published | 2017-09-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 82.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Team Of Monkeys |
| Maintainers | uncledick |
| Keywords | testing, monkey, integration, random, lib, library, cool |

## Links

- npm: https://www.npmjs.com/package/lib-monkey
- Repository: https://github.com/lib-monkey/lib-monkey
- Homepage: https://github.com/lib-monkey/lib-monkey#readme
- Issues: https://github.com/lib-monkey/lib-monkey/issues
- npm.io page: https://npm.io/package/lib-monkey

## Dependencies (4)

- [chance](https://npm.io/package/chance.md) ^1.0.13
- [colors](https://npm.io/package/colors.md) ^1.1.2
- [throat](https://npm.io/package/throat.md) ^4.1.0
- [commander](https://npm.io/package/commander.md) ^2.12.2

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads
- [aws-elasticsearch-connector](https://npm.io/package/aws-elasticsearch-connector.md) — 37.4K weekly downloads

## Recent versions

- 0.6.1 (latest) — 2019-05-07
- 0.6.0-beta-rev3.2 — 2019-05-07
- 0.6.0-beta-rev3.1 — 2019-05-07
- 0.6.0-beta-rev3 — 2019-05-07
- 0.5.2 — 2019-05-07
- 0.5.1 — 2018-01-22
- 0.5.0 — 2018-01-10
- 0.4.7 — 2017-11-21
- 0.4.6 — 2017-11-04
- 0.4.5 — 2017-11-03
- 0.4.1 — 2017-10-07
- 0.4.0 — 2017-10-02
- 0.3.4 — 2017-09-30
- 0.3.3 — 2017-09-28
- 0.3.1 — 2017-09-27
- … 3 more at https://npm.io/package/lib-monkey/versions

## README

# lib-monkey

[![Travis](https://img.shields.io/travis/lib-monkey/lib-monkey/master.svg)](https://travis-ci.org/lib-monkey/lib-monkey) [![Coveralls github](https://img.shields.io/coveralls/github/lib-monkey/lib-monkey.svg)](https://coveralls.io/github/lib-monkey/lib-monkey) [![David](https://img.shields.io/david/lib-monkey/lib-monkey.svg)](https://david-dm.org/lib-monkey/lib-monkey) [![Dependency Status](https://dependencyci.com/github/lib-monkey/lib-monkey/badge)](https://dependencyci.com/github/lib-monkey/lib-monkey) [![npm](https://img.shields.io/npm/v/lib-monkey.svg)](https://www.npmjs.com/package/lib-monkey) [![API Doc](https://doclets.io/lib-monkey/lib-monkey/master.svg)](https://doclets.io/lib-monkey/lib-monkey/master/overview)

Monkey Testing for libraries

When there is a need to test code with random values

Simply put is instead of using pre-determened variables inside test and creating stub data values, you define a sort of joker that can generate pseudo random values and use them through running the test multiple times you have a higher chance to test most of your edge cases.


## Installation
```bash
  npm install lib-monkey
```

## Getting Started

There are multiple jokers and runners to use for the library but the basic idea is to send the joker to one of the runners to know where to put the random value


```javascript

const monkey = require('lib-monkey');

describe('test', () => {

  it('test sync or prommise', () => 
     monkey.it(() => {

      const a = monkey.generate(monkey.int.min(0).max(10));
      
      // Do some tests with a as ranom value
      // Will accept sync or prommise based results

    })
     .do(n_times, concurrency));

  it('test callback async', () => 
     monkey.it((done) => {
      const a = monkey.generate(monkey.int.min(0).max(10));
      
      // Do some tests with a as ranom value
      // Call done after async tests

    })
     .do(n_times, concurrency));
});
```

## ```Jokers```

There are multipe jokers in library and they have multiple modifyers.

There is the base modifyer ```nullable(boolean|chance|null == true)``` and all the other modifyers are based of of [Chance][chance] library

#### Example

```javascript

monkey.int.min(0).max(10) => chance.integer({ min:0, max: 10 })

monkey.bool.likelihood(70) => chance.bool({ likelihood: 70 })

```

Currently there are the following jokers:

 - bool, char, float, int, letter, natural, string
 - date, hammertime, timestamp, timezone
 - paragraph, sentence, syllable, word
 - pick (from array), array (of jokers), map, object (deep map), typed (of specific type)


## ```monkey.it```

It's basicaly every it function in every test framework, except that it's nameless and supports contexts <br/>
> ```monkey.it(fn, context)``` where fn will have it's ```this``` equal context.

And this it will forward and enritch any assertion error that 

#### Example

```javascript

  monkey.it(async () => {
    const foo = monkey.generate(monkey.bool); // foo will be 50/50 true false pretty much

    // Do Some tests and 
  })
    .do(5)
    .catch(err => console.error(err) || process.exit(-1));

```

## cli

To easly re-run the test localy with specific seed or just to test something the library comes with a cli

```bash
  npm install -g lib-monkey


  lib-monkey -s [seed] [CMD]

  lib-monkey -j [joker description]

  
  # example

  lib-monkey -s 16012018 -j int.min(0).max(10) ===> 7
```


## Roadmap
This project should co-exist with all the avialbe test runners like mocha or jasmin and be used as a tool for random value testing

- [x] Add more Jokers and Runners
- [ ] ~~Add self assertion api~~
- [ ] Finish the docs
- [x] Create code coverage for the library
- [x] Maybe change the api to be dot chainable


## License

[MIT][license] © [Lib Monkey Team][author]

[chance]: https://www.npmjs.com/package/chance

[license]: LICENSE

[author]: https://github.com/lib-monkey

---
_Source: https://npm.io/package/lib-monkey · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
