Building and Testing with Grunt
This article describes the setup of the "Durandal HTML Starter Kit Pro" contributed by Rainer Wittmann.
Quick start
- Install node from https://nodejs.org
- Install grunt using
npm install -g grunt-cli - Download/clone the repo found at https://github.com/RainerAtSpirit/HTMLStarterKitPro
- Run
npm installin the repo's root directory to install grunt's dependencies - Run
grunt, which will run the default task, which runsjshint,jasmine:modulesand opens the resultant_specrunner.htmlin the browser
Writing tests
There are two grunt watch tasks configured.
grunt watch:modules. Whenever a spec in the test/specs/modules directory is updatedgrunt:watchwill rungrunt:jasmine:modules.grunt watch:app. Durandal app testing, due to its the async nature, isn't that straight forward in jasmine. You can find an example using jasmine's nativerunsandwaitsForintest/specs/app. Check theDurandal'sdocumentation for updated info about that topic.
Building the app
Experimental: There's a grunt build task that builds an optimized version in the build directory.
Customization
Modify/adjust package.json after cloning. Open gruntfile.js to add/modify the existing configuration.
...
grunt.registerTask('build', ['jshint', 'jasmine', 'clean', 'copy', 'durandal:main', 'uglify', 'connect:build']);
grunt.registerTask('default', 'start web server for jasmine tests in browser', function() {
grunt.task.run('jshint');
grunt.task.run('jasmine:modules');
grunt.event.once('connect.test.listening', function( host, port ) {
var specRunnerUrl = 'https://' + host + ':' + port + '/_SpecRunner.html';
grunt.log.writeln('Jasmine specs available at: ' + specRunnerUrl);
require('open')(specRunnerUrl);
});
grunt.task.run('connect:test:keepalive');
});
New to grunt?
Head over to https://gruntjs.com/ to learn the basics.