2013-05-04 16:55:52 +02:00
|
|
|
|
/*
|
|
|
|
|
* grunt-contrib-qunit
|
|
|
|
|
* http://gruntjs.com/
|
|
|
|
|
*
|
2014-06-18 21:32:03 +02:00
|
|
|
|
* Copyright (c) 2014 "Cowboy" Ben Alman, contributors
|
2013-05-04 16:55:52 +02:00
|
|
|
|
* Licensed under the MIT license.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
(function () {
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
// Don't re-order tests.
|
|
|
|
|
QUnit.config.reorder = false
|
|
|
|
|
// Run tests serially, not in parallel.
|
|
|
|
|
QUnit.config.autorun = false
|
|
|
|
|
|
|
|
|
|
// Send messages to the parent PhantomJS process via alert! Good times!!
|
|
|
|
|
function sendMessage() {
|
|
|
|
|
var args = [].slice.call(arguments)
|
|
|
|
|
alert(JSON.stringify(args))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// These methods connect QUnit to PhantomJS.
|
2014-06-18 21:32:03 +02:00
|
|
|
|
QUnit.log(function (obj) {
|
2013-05-04 16:55:52 +02:00
|
|
|
|
// What is this I don’t even
|
|
|
|
|
if (obj.message === '[object Object], undefined:undefined') { return }
|
2014-06-18 21:32:03 +02:00
|
|
|
|
|
2013-05-04 16:55:52 +02:00
|
|
|
|
// Parse some stuff before sending it.
|
2014-06-18 21:32:03 +02:00
|
|
|
|
var actual
|
|
|
|
|
var expected
|
|
|
|
|
if (!obj.result) {
|
|
|
|
|
// Dumping large objects can be very slow, and the dump isn't used for
|
|
|
|
|
// passing tests, so only dump if the test failed.
|
2015-02-26 08:27:12 +01:00
|
|
|
|
actual = QUnit.dump.parse(obj.actual)
|
|
|
|
|
expected = QUnit.dump.parse(obj.expected)
|
2014-06-18 21:32:03 +02:00
|
|
|
|
}
|
2013-05-04 16:55:52 +02:00
|
|
|
|
// Send it.
|
|
|
|
|
sendMessage('qunit.log', obj.result, actual, expected, obj.message, obj.source)
|
2014-06-18 21:32:03 +02:00
|
|
|
|
})
|
2013-05-04 16:55:52 +02:00
|
|
|
|
|
2014-06-18 21:32:03 +02:00
|
|
|
|
QUnit.testStart(function (obj) {
|
2013-05-04 16:55:52 +02:00
|
|
|
|
sendMessage('qunit.testStart', obj.name)
|
2014-06-18 21:32:03 +02:00
|
|
|
|
})
|
2013-05-04 16:55:52 +02:00
|
|
|
|
|
2014-06-18 21:32:03 +02:00
|
|
|
|
QUnit.testDone(function (obj) {
|
|
|
|
|
sendMessage('qunit.testDone', obj.name, obj.failed, obj.passed, obj.total, obj.duration)
|
|
|
|
|
})
|
2013-05-04 16:55:52 +02:00
|
|
|
|
|
2014-06-18 21:32:03 +02:00
|
|
|
|
QUnit.moduleStart(function (obj) {
|
2013-05-04 16:55:52 +02:00
|
|
|
|
sendMessage('qunit.moduleStart', obj.name)
|
2014-06-18 21:32:03 +02:00
|
|
|
|
})
|
2013-05-04 16:55:52 +02:00
|
|
|
|
|
2014-06-18 21:32:03 +02:00
|
|
|
|
QUnit.moduleDone(function (obj) {
|
|
|
|
|
if (obj.failed === 0) {
|
2015-05-06 22:34:14 +02:00
|
|
|
|
console.log('\r\u221A All tests passed in "' + obj.name + '" module')
|
2013-05-04 16:55:52 +02:00
|
|
|
|
} else {
|
2015-05-06 22:34:14 +02:00
|
|
|
|
console.log('\u00D7 ' + obj.failed + ' tests failed in "' + obj.name + '" module')
|
2013-05-04 16:55:52 +02:00
|
|
|
|
}
|
2014-06-18 21:32:03 +02:00
|
|
|
|
sendMessage('qunit.moduleDone', obj.name, obj.failed, obj.passed, obj.total)
|
|
|
|
|
})
|
2013-05-04 16:55:52 +02:00
|
|
|
|
|
2014-06-18 21:32:03 +02:00
|
|
|
|
QUnit.begin(function () {
|
|
|
|
|
sendMessage('qunit.begin')
|
|
|
|
|
console.log('\n\nStarting test suite')
|
|
|
|
|
console.log('================================================\n')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
QUnit.done(function (obj) {
|
|
|
|
|
sendMessage('qunit.done', obj.failed, obj.passed, obj.total, obj.runtime)
|
|
|
|
|
})
|
2013-05-04 16:55:52 +02:00
|
|
|
|
|
|
|
|
|
}())
|