Skip to content

Commit

Permalink
added configurable timeout and cleaned up QUnit refs in comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Camille Reynders committed Apr 27, 2012
1 parent cbe2a3a commit d669613
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
16 changes: 12 additions & 4 deletions tasks/jasmine.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = function ( grunt ) {
} ).join( '\n' );
}

// Handle methods passed from PhantomJS, including QUnit hooks.
// Handle methods passed from PhantomJS, including Jasmine hooks.
var phantomHandlers = {
begin : function(){

Expand Down Expand Up @@ -65,7 +65,7 @@ module.exports = function ( grunt ) {
},
done_timeout:function () {
grunt.log.writeln();
grunt.warn( 'PhantomJS timed out, possibly due to a missing QUnit start() call.', 90 );
grunt.warn( 'PhantomJS timed out, possibly due to an unfinished async spec.', 90 );
},
// console.log pass-through.
console:console.log.bind( console ),
Expand All @@ -78,6 +78,12 @@ module.exports = function ( grunt ) {
// ==========================================================================

grunt.registerMultiTask( 'jasmine', 'Run Jasmine specs in a headless PhantomJS instance.', function () {
var timeout = grunt.config(['jasmine', this.target, 'timeout']);

if( typeof timeout === "undefined" ){
timeout = 10000;
}

// Get files as URLs.
var urls = grunt.file.expandFileURLs( this.file.src );

Expand All @@ -91,6 +97,7 @@ module.exports = function ( grunt ) {
grunt.utils.async.forEachSeries( urls, function ( url, next ) {
var basename = path.basename( url );
grunt.verbose.subhead( 'Running specs for ' + basename ).or.write( 'Running specs for ' + basename );
grunt.log.writeln();

// Create temporary file to be used for grunt-phantom communication.
var tempfile = new Tempfile();
Expand Down Expand Up @@ -133,6 +140,7 @@ module.exports = function ( grunt ) {

if ( done ) {
// All done.
grunt.log.writeln();
cleanup();
next();
} else {
Expand All @@ -153,8 +161,9 @@ module.exports = function ( grunt ) {
tempfile.path,
// The Jasmine helper file to be injected.
grunt.task.getFile( 'jasmine/jasmine-helper.js' ),
// URL to the QUnit .html test file to run.
// URL to the Jasmine .html test file to run.
url,
timeout,
// PhantomJS options.
'--config=' + grunt.task.getFile( 'jasmine/phantom-config.json' )
],
Expand All @@ -167,7 +176,6 @@ module.exports = function ( grunt ) {
} );
}, function ( err ) {
// All tests have been run.
grunt.log.writeln();
// Log results.
if ( status.failed > 0 ) {
grunt.warn( status.failed + '/' + status.total + ' assertions failed in ' + status.specs + ' specs (' +
Expand Down
2 changes: 1 addition & 1 deletion tasks/jasmine/jasmine-helper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Is injected into the spec runner file
* Copyright (c) 2012 Camille Reynders
* Copyright (c) 2012 "Cowboy" Ben Alman
* Licensed under the MIT license.
Expand Down
7 changes: 5 additions & 2 deletions tasks/jasmine/phantom-jasmine-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ var fs = require( 'fs' );
// The temporary file used for communications.
var tmpfile = phantom.args[0];


// The Jasmine helper file to be injected.
var jasmineHelper = phantom.args[1];

// The Jasmine .html specs file to run.
var url = phantom.args[2];

//in milliseconds
var timeout = phantom.args[ 3 ];

// Keep track of the last time a Jasmine message was sent.
var last = new Date();

Expand All @@ -45,7 +48,7 @@ function sendDebugMessage() {

// Abort if Jasmine doesn't do anything for a while.
setInterval( function () {
if ( new Date() - last > 5000 ) {
if ( new Date() - last > timeout ) {
sendMessage( ['done_timeout'] );
}
}, 1000 );
Expand Down

0 comments on commit d669613

Please sign in to comment.