npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp-mocha-tdd

v2.0.6

Published

easy test driven development with gulp and mocha

Downloads

35

Readme

gulp-mocha-tdd

easy test driven development with gulp and mocha

  • it('should use mocha for unit tests')
  • it('should auto-generate the boilerplate module test describe statement')
  • it('should be able to work with your test naming conventions')
  • it('should make test driven development easy and convienant')
  • it('should support mocha options like breakpoints and grep')
  • it('should use conventions to associate modules with unit tests')
  • it('should support additional gulp stream handlers (like JSX)')
  • it('should re-run module tests when either the module or unit test code changes')
  • it('should provide coverage reports')

Usage / Common Examples

Run all tests

> gulp test

Run some tests identified by a grep statement

> gulp test --grep foo

Watch for module or unit test changes

> gulp test-watch

Stop on any debugger statements

> gulp test -d (or --debug-brk)
> node-inspector  {in another window}
browse to http://127.0.0.1:8080/debug?port=5858

Test Modules

Test modules do not need the top level describe function (it will be created automatically based on file structure). You can either just have your tests directly in the file (no usage of module.exports) or you can export a function callback that contains your tests. This callback accepts 2 parameters (targetModule, targetModuleDirectoryPath). For example:

var targetModule = require('path/to/target/module');
it('should ...', function() {
  expect(targetModule...).to...
});

or

module.exports = function(targetModule, targetBase) {
  it('should ...', function() {
    expect(targetModule...).to...
  });
  it('should ...', function() {
    expect(require(targetBase + '/targetModuleName')...).to...
  });
}

All modules must be within a root directory ("js" by default) and tests can either be in a separate root directory ("tests" by default) or tests can be in a directory relative ("_tests" by default) to the module. Tests can use any naming pattern ("{module name}-test.js" by default).

For example

|-- js
    |-- _tests
        |-- foo-test.js
    |-- foo.js

or

|-- lib
    |-- foo.js
|-- tests
    |-- foo.spec.js

See Options below for available configuration

see examples for details

Any files within the test directories prefixed with _ will be ignored for testing allowing for utility modules.

Additional Transformations

The pipe option (array of gulp stream handlers) can be used to perform additional transformations. The following gulpfile can be used to support React JSX

var gulp = require('gulp');
var react = require('gulp-react');
var gulpMochaTDD = require('gulp-mocha-tdd');

gulpMochaTDD(gulp, {
  pipe: [react({ harmony: true })]
});

Options

  • taskName: the gulp task name ("test" if undefined)
  • pipe: array of gulp stream handlers (See above for example)
  • init: init function executed once before the tests
  • scriptsDirName: top level directory ("js" if undefined)
  • testFilePattern: unit test file name (without ext) pattern (use "{name}" to reference the module name; "{name}-test" if undefined)
  • testsDirName: name of directory which contains the unit test files ("_tests" if undefined)
  • rootTestsDir: true if using a root tests directory and undefined/false if tests are in a directory relative to the module (see examples)
  • istanbul: istanbul options which, if included, will include istanbul coverage reports see available options

Installation

Install dependencies

npm install --save-dev mocha
npm install --save-dev gulp
npm install --save-dev gulp-mocha-tdd

Inject the test task in gulpfile.js

var gulp = require('gulp');
var gulpMochaTDD = require('gulp-mocha-tdd');

gulpMochaTDD(gulp, {
  // add options here
});

Add .test to your .gitignore file

Coverage Reports

See Options section above for details but here is a quick example to include coverage reports in your tests

var gulp = require('gulp');
var gulpMochaTDD = require('gulp-mocha-tdd');

gulpMochaTDD(gulp, {
  istanbul: {
    dir: './coverage',
    reporters: [ 'lcov', 'text' ],
    reportOpts: { dir: './coverage' }
  }
});