Serve a mocha runner page with the source and spec script paths configured in your Gruntfile
Serve a mocha runner page with the source and spec script paths configured in your Gruntfile.
This plugin requires Grunt
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-mocha-runner --save-dev
In your project's Gruntfile, add a section named
mochaRunner to the data object passed into
The port on which to serve the test runner.
The hostname on which to serve the test runner.
Setting it to
'*' will make the it accessible from anywhere.
'Mocha Spec Runner'
The title of the test runner page.
The mocha ui type to use with
The mochaRunner task builds and serves the mocha test runner page, but doesn't handle the actual opening of the page to run the tests. For that, we need an additional grunt task. grunt-mocha works really well for this. Here is a basic Gruntfile example showing grunt-mocha and grunt-mocha-runner being used together:
gruntloadNpmTasks'grunt-mocha';gruntloadNpmTasks'grunt-mocha-runner';gruntinitConfig// serves the runner pagemochaRunner:all:scripts:'test/app/spec/**/*.js''app/scripts/**/*.js'// opens the runner page to run the testsmocha:options:run: truereporter: 'Spec'test:options:// url to the runner page served by mochaRunnerurls: '';gruntregisterTask'test''mochaRunner''mocha';;
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using: