npm

Need private packages and team management tools?Check out npm Orgs. »

lib-monkey

0.6.1 • Public • Published

lib-monkey

Travis Coveralls github David Dependency Status npm API Doc

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

  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

 
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 library

Example

 
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

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

 
  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

  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

  • Add more Jokers and Runners
  • Add self assertion api
  • Finish the docs
  • Create code coverage for the library
  • Maybe change the api to be dot chainable

License

MIT © Lib Monkey Team

install

npm i lib-monkey

Downloadsweekly downloads

55

version

0.6.1

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability