Skip to content

Using Intern with Grunt

Colin Snover edited this page Sep 9, 2013 · 14 revisions

Grunt support is built into Intern. Install Intern and load the Grunt task into your Gruntfile using grunt.loadTasks('path/to/intern/grunt'); (Intern 1.0) or grunt.loadNpmTasks('intern') (Intern 1.1+).

An example of the Grunt Intern task is available in the intern-examples repository.

Task Options

Options available when running Intern using Grunt are the same as the options available when running Intern directly from the command-line, plus the following additional options:

Name
Default
Description
runType
client
The execution mode in which Intern should be run. This may be either "runner" for the automated test runner, or "client" for the Node.js client.
sauceUsername
(none)
The username for authentication with Sauce Labs.
sauceAccessKey
(none)
The access key for authentication with Sauce Labs.

Events

Added in Intern 1.3

The current Grunt events are rudimentary, based on the output of the default console reporter, and do not provide much detail into the actual state of the test runner to Grunt tasks. Future versions of Intern are likely to improve to provide first-class event support, if sufficient demand exists for this feature.

Event Parameters Description
intern.pass data - A string that contains the pass message. This event is emitted when a test passes.
intern.fail data - A string that contains the failure message. This event is emitted when a test fails.

Gruntfile example

grunt.initConfig({
    intern: {
        someReleaseTarget: {
            options: {
                runType: 'runner', // defaults to 'client'
                config: 'tests/intern',
                reporters: [ 'console', 'lcov' ],
                suites: [ 'myPackage/tests/all' ]
            }
        },
        anotherReleaseTarget: { /* ... */ }
    }
});

// Load the Intern task
grunt.loadNpmTasks('intern');

// Register a test task that uses Intern
grunt.registerTask('test', [ 'intern' ]);

// By default we just test
grunt.registerTask('default', [ 'test' ]);