Skip to content

Commit

Permalink
Build: Update test-on-node task to support QUnit.todo
Browse files Browse the repository at this point in the history
  • Loading branch information
Trent Willis committed Feb 8, 2017
1 parent 95ec26c commit ce025b6
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 29 deletions.
93 changes: 75 additions & 18 deletions build/tasks/test-on-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,56 @@ module.exports = function( grunt ) {

var done = this.async();

async.series( runs, function( error, result ) {
var total = result.reduce( function( previous, details ) {
return previous + details.total;
}, 0 );
var failed = result.reduce( function( previous, details ) {
return previous + details.failed;
}, 0 );
var runtime = result.reduce( function( previous, details ) {
return previous + details.runtime;
}, 0 );
async.series( runs, function( error, stats ) {
var totals = stats.reduce( function( totals, stats ) {
totals.passed += stats.passed;
totals.failed += stats.failed;
totals.skipped += stats.skipped;
totals.todo += stats.todo;
totals.passedAssertions += stats.passedAssertions;
totals.failedAssertions += stats.failedAssertions;
totals.runtime += stats.runtime;
return totals;
}, {
passed: 0,
failed: 0,
skipped: 0,
todo: 0,
runtime: 0,
passedAssertions: 0,
failedAssertions: 0
} );

grunt.log.writeln( "-----" );
grunt.log.ok( total + " total assertions (in " + runtime + "ms) , " +
"with " + failed + " failed assertions" );
grunt.log.ok( constructMessage( totals ) );

done( !error );
} );
} );

function constructMessage( stats ) {
var totalTests = stats.passed + stats.failed + stats.skipped + stats.todo,
totalAssertions = stats.passedAssertions + stats.failedAssertions;

return [
totalTests,
" tests completed with ",
stats.failed,
" failed, " +
stats.skipped,
" skipped, and ",
stats.todo,
" todo. \n" +
totalAssertions,
" assertions (in ",
stats.runtime,
"ms), passed: " +
stats.passedAssertions,
", failed: ",
stats.failedAssertions
].join( "" );
}

function runQUnit( file, runEnd ) {

// Resolve current QUnit path and remove it from the require cache
Expand All @@ -57,39 +88,65 @@ module.exports = function( grunt ) {
function registerEvents( QUnit, file, runEnd ) {
var runDone = false;
var testActive = false;
var stats = {
passed: 0,
failed: 0,
skipped: 0,
todo: 0
};

QUnit.begin( function() {
grunt.log.ok( "Testing " + file + " ..." );
} );

QUnit.testStart( function() {
testActive = true;
} );

QUnit.log( function( details ) {
if ( !testActive || details.result ) {
if ( !testActive || details.result || details.todo ) {
return;
}
var message = "name: " + details.name + " module: " + details.module +
" message: " + details.message;
grunt.log.error( message );
} );
QUnit.testDone( function() {

QUnit.testDone( function( details ) {
testActive = false;

var testPassed = details.failed > 0 ? details.todo : !details.todo;

if ( details.skipped ) {
stats.skipped++;
} else if ( !testPassed ) {
stats.failed++;
} else if ( details.todo ) {
stats.todo++;
} else {
stats.passed++;
}
} );

QUnit.done( function( details ) {
if ( runDone ) {
return;
}
var message = details.total + " assertions (in " + details.runtime + "ms), passed: " +
details.passed + ", failed: " + details.failed;

if ( details.failed ) {
stats.runtime = details.runtime;
stats.passedAssertions = details.passed;
stats.failedAssertions = details.failed;

var message = constructMessage( stats );

if ( stats.failed ) {
grunt.log.error( message );
} else {
grunt.log.ok( message );
}

runDone = true;
runEnd( details.failed, details );
runEnd( stats.failed, stats );
} );
}
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"grunt-concurrent": "2.3.1",
"grunt-contrib-connect": "1.0.2",
"grunt-contrib-copy": "1.0.0",
"grunt-contrib-qunit": "1.2.0",
"grunt-contrib-qunit": "1.3.0",
"grunt-contrib-watch": "1.0.0",
"grunt-coveralls": "1.0.1",
"grunt-eslint": "19.0.0",
Expand Down
20 changes: 10 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1339,7 +1339,7 @@ glob@^5.0.15, glob@~5.0.0:
once "^1.3.0"
path-is-absolute "^1.0.0"

glob@^7.0.0, glob@~7.1.1:
glob@^7.0.0, glob@^7.0.5, glob@~7.1.1:
version "7.1.1"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.1.tgz#805211df04faaf1c63a3600306cdf5ade50b2ec8"
dependencies:
Expand All @@ -1350,7 +1350,7 @@ glob@^7.0.0, glob@~7.1.1:
once "^1.3.0"
path-is-absolute "^1.0.0"

glob@^7.0.3, glob@^7.0.5, glob@~7.0.0:
glob@^7.0.3, glob@~7.0.0:
version "7.0.6"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.0.6.tgz#211bafaf49e525b8cd93260d14ab136152b3f57a"
dependencies:
Expand Down Expand Up @@ -1431,9 +1431,9 @@ grunt-contrib-copy@1.0.0:
chalk "^1.1.1"
file-sync-cmp "^0.1.0"

grunt-contrib-qunit@1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/grunt-contrib-qunit/-/grunt-contrib-qunit-1.2.0.tgz#76ee87ce8cc157592802bb7545392f671ccb4956"
grunt-contrib-qunit@1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/grunt-contrib-qunit/-/grunt-contrib-qunit-1.3.0.tgz#9dac628cfd4ec815998633db73b52bdb3ddbc99e"
dependencies:
grunt-lib-phantomjs "^1.0.0"

Expand Down Expand Up @@ -2553,16 +2553,16 @@ right-align@^0.1.1:
dependencies:
align-text "^0.1.1"

rimraf@^2.2.8, rimraf@^2.5.2:
rimraf@^2.2.8, rimraf@~2.2.8:
version "2.2.8"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.2.8.tgz#e439be2aaee327321952730f99a8929e4fc50582"

rimraf@^2.5.2:
version "2.5.4"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.5.4.tgz#96800093cbf1a0c86bd95b4625467535c29dfa04"
dependencies:
glob "^7.0.5"

rimraf@~2.2.8:
version "2.2.8"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.2.8.tgz#e439be2aaee327321952730f99a8929e4fc50582"

rollup-plugin-babel@2.6.1:
version "2.6.1"
resolved "https://registry.yarnpkg.com/rollup-plugin-babel/-/rollup-plugin-babel-2.6.1.tgz#470b03486337045d7e8a3e43fc5fc00e8db82c26"
Expand Down

0 comments on commit ce025b6

Please sign in to comment.