Last active
April 12, 2016 18:20
-
-
Save chrisdavies/fa11a5d8874a5248f150 to your computer and use it in GitHub Desktop.
Gulp task for running qUnit with zombiejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is what your gulp task should look like | |
gulp.task('qunit', function(done) { | |
var files = glob.sync('./test/**/*.html'); | |
runAllQunits(files); | |
}); | |
// Runs through each qunit file (one at a time, though this could be relatively easily parallelized) | |
function runAllQunits(testFiles) { | |
var browser = new Zombie(); | |
function errorTrace(errorNode, selector) { | |
console.log(colors.yellow((errorNode.querySelector(selector) || {}).textContent)); | |
} | |
function printErrors() { | |
var errors = browser.document.querySelectorAll('#qunit-tests > .fail'); | |
Array.prototype.slice.call(errors, 0).forEach(function (error) { | |
errorTrace(error, '.test-name'); | |
errorTrace(error, '.test-message'); | |
errorTrace(error, '.test-source'); | |
}); | |
} | |
function printQunitResults() { | |
var passed = browser.document.querySelector('#qunit-testresult .failed').textContent.trim() === '0', | |
color = passed ? 'green' : 'red', | |
text = browser.document.querySelector('#qunit-testresult').textContent; | |
!passed && printErrors(); | |
console.log(colors[color](text)); | |
return text; | |
} | |
function cleanUp() { | |
browser.close(); | |
done(); | |
} | |
function testFile(file) { | |
var url = 'file:/' + path.resolve(file); | |
console.log('Running ' + file); | |
browser.visit(url).then(printQunitResults).then(next); | |
} | |
function queueTest() { | |
setTimeout(function () { | |
testFile(testFiles.pop()); | |
}); | |
} | |
function next() { | |
if (testFiles.length) { | |
queueTest(); | |
} else { | |
cleanUp(); | |
} | |
} | |
next(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment