Giter Site home page Giter Site logo

yvem / unit-test-toolbox Goto Github PK

View Code? Open in Web Editor NEW

This project forked from offirmo-graveyard/unit-test-toolbox

0.0 2.0 0.0 10 KB

An aggregation of quality npm modules to be used for writing unit tests.

License: The Unlicense

JavaScript 100.00%

unit-test-toolbox's Introduction

unit-test-toolbox

An aggregation of quality npm modules to be used for writing unit tests.

This modules includes mocha, chai, sinon, sinon-chai, chai-as-promised, chai-subset, chai-moment. It also exposes:

  • a pre-made plumbing activating the chai.expect interface, and chai sinon-chai and chai-as-promised plugins
  • (for legacy nodes with npm <= 2) the mocha executable as a redirection to its integrated mocha executable

In progress:

  • working on integrating sinon properly

Introduction - the problem

Writing unit tests in Js always requires the same operations:

  • remembering all the libs needed
  • installing them: npm install mocha chai sinon sinon-chai chai-as-promised
  • if using typescript: npm install @types/mocha @types/chai @types/sinon @types/sinon-chai @types/chai-as-promised
  • write an init file for activating chai.expect (what else ?), sinon-chai and chai-as-promised
  • write the npm task "test": "mocha --opts mocha.opts path/to/init.js '<glob_to_my_tests/**/*spec.js>'"
  • keep all those dependencies up-to-date

The proposed solution:

  • install only one module npm i -D @offirmo/unit-test-toolbox
  • write the npm task "test": "mocha --opts mocha.opts node_modules/@offirmo/unit-test-toolbox/mocha-chai-init-node.js '<glob_to_my_tests/**/*spec.js>'"
  • keep @offirmo/unit-test-toolbox up-to-date

Installation & usage

recent npm

Targeting node >= 6 & npm >= 3 (for we abuse the flat deps)

npm i --save-dev @offirmo/unit-test-toolbox

If you want to use the pre-written init file, reference it in your test task:

  "scripts": {
    "test": "mocha --opts node_modules/@offirmo/unit-test-toolbox/mocha.opts node_modules/@offirmo/unit-test-toolbox/mocha-chai-init.js 'test/unit/src/**/*spec.js'"
  },

Suggested mocha.opts:

--reporter spec
--check-leaks
--es_staging
--full-trace
--harmony

Legacy

For node 0.10 with npm 2, reference a special branch in package.json

"@offirmo/unit-test-toolbox": "git://github.com/offirmo/unit-test-toolbox.git#legacy-node_v0.10",

You can then use mocha as usual (transparently forwarded).

sinon should be imported through unit-test-toolbox:

var sinon = require('@offirmo/unit-test-toolbox/node_modules/sinon')

See also

Contributing

Suggestions welcome.

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.