grunt-qunit-amd
Grunt plugin to run Qunit tests on your AMD libraries without having to create html pages.
Getting Started
This plugin requires Grunt ~0.4.1
(and is not working with node 0.10
)
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-qunit-amd --save-dev
One the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt;
The "qunit_amd" task
Overview
In your project's Gruntfile, add a section named qunit_amd
to the data object passed into grunt.initConfig()
.
grunt
#to launch all tests: grunt qunit_amd:unit #to launch just one test: grunt qunit_amd:unit:myTestFileName
Options
options.include
Type: Array
An array of files to be injected in all the test suites.
options.tests
Type: Array
An array of patterns to retrieve the test files. Test files are threated as require.js main files
sample test:
;
I provided a phantom.log method to be used to log properly to console (HTMLElements already parsed, object already stringified, etc).
options.coverage
Type: Object
In order to take advantage of Istanbul code coverage reporting
coverage: out: 'path/to/your/coverage/output/folder' tmp: 'path/to/a/temp/folder' pathsToCover: 'glob/to/the/files' 'you/want/coverage/for'
options.qunit
Type: Object
QUnit configuration by default QUnit is configured like this:
QUnitconfigblocking = false;QUnitconfigrequireExpects = true;QUnitconfigautorun = false;
in order to override this settings you need just to pass a config object
qunit : requireExpects: false autorun: true
options.require
Type: Object
RequireJS configuration Read the RequireJS documentation
Contributing
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 Grunt.
Thanks
This library exists because I've been working with these guys and I learned a lot of stuff about testing: Marco Pracucci, Rocco Zanni, Luca Lischetti