Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including grunt-mocha-debug with all npm packages installed. Try it out:

require("grunt/package.json"); // grunt is a peer dependency. var gruntMochaDebug = require("grunt-mocha-debug")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

grunt-mocha-debug v0.0.10

Easily run mocha tests on node.js/phantomjs


Grunt task for running mocha tests on node.js/phantomjs

Getting Started

npm install grunt-mocha-debug --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:



This task will run mocha test suites on background node/phantomjs processes.

For node.js testing it will check specified files for 'debugger' statements(nothing fancy like ast walk, just simple regex search so the debugger statement can only have trailing spaces on the line). If any file matches the search, the mocha runner process will be started with the --debug-brk argument so the code can be stepped with node-inspector.

For phantomjs testing, it will start a background phantomjs instance and reuse it across test runs. That means if the task is triggered again by grunt-contrib-watch it will only issue a 'reload' command to the test page(instead of starting a new phantomjs process for each run like grunt-mocha). Task will start an express instance to serve the test page which is how phantomjs loads the page(any normal web browser can access it too).

The 'reporter', 'ui', 'checkLeaks' and 'globals' are also configurable and seamless adapted to both types of test runs. There's also a 'reporterOutput' options which can be set to a filename to receive the reporter's output(useful for reporters like markdown)

Sample configuration

      # Only search for 'debugger' in the original coffeescript sources(the
      # default is to check only the test files)
      check: 'src/**/*.coffee'
      reporter: 'nyan'
        ui: 'tdd'
        checkLeaks: true
        globals: ['jquery']
        reporter: 'markdown'
        reporterOutput: './results.mkd'
        # Port that express will listen on(default is a random port)
        listenPort: 8888 
        # Address that express will listen on(default is
        listenAddress: ''
        # Enable phantomjs testing(node.js is the default)
        phantomjs: true
        # Files to test(possibly a concatenated/browserified version of your
        # commonjs project)
        src: 'build/browser/test.js'
        src: 'build/nodejs/**/*.js'

No other setup other than configuring the grunt task is necessary(phantomjs will be installed automatically).

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free