Coder Social home page Coder Social logo

cherub's Introduction

Cherub.js

A tiny testing framework with zero dependencies to guard against regression.

Cherub.js is designed to be flexible/lightweight & make writing tests faster/easier.

Example (browser/node.js)

import cherub from './cherub.mjs'
const
sum=(a,b)=>a+b,
tests=
[
    [0,0,'zero'],//actual, expected, test name
    [()=>sum(1,2),3,'sum/positive'],//actual=function
    [()=>sum(-1,-2),-3,{name:'sum/negative'}],//options object
    [()=>undefinedVarible,0,'crash test'],//errors will not crash cherub
],
opts={now:()=>performance.now()}//microsecond accuracy
cherub(tests,opts)

//console output
"crash test" failed:
{name:"crash test",time:0.7,passed:false,error:object}
3/4 (75%) tests passed in 4.7ms

Supports:

  • Async Testing
  • Atomic Testing (by default)
    • use cherub(tests,{shuffle:false}) to maintain testing order
  • Browser & Node.js
  • Different Assertion Libraries
    • defaults to JSON.stringify(acutal)===JSON.stringify(expected)
    • for a different default assertion use cherub(tests,{assert:customAssertionFn})
    • for custom assertions on a test-by-test basis:
      • [expectedValue,customAssertionFn,'test name'] or
      • [expected,actual,{name:'generic test',assert:customAssertionFn}]
  • Concurrent Testing (by default)
    • for sequential testing use cherub(tests,{parallel:false})
  • Configurable
    • reporting
      • use cherub(tests,{reportTest:fn({name,time,passed:bool,error:object}) for realtime results for each test
      • use cherub(tests,{report:fn({tests:[...results],time})}) to alter final results output
    • timing precision
      • default is millisecond accuracy with Date.now()
      • for microsecond accuracy use cherub(tests,{now:()=>performance.now()})
        • on node.js (8.5.0+) add import {performance} from 'perf_hooks' as well

cherub's People

Contributors

fauxsaur avatar

Watchers

James Cloos avatar

Forkers

isabella232

cherub's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.