0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-12-02 14:24:19 +01:00
Bootstrap/js/tests/unit/phantom.js

102 lines
2.9 KiB
JavaScript
Raw Normal View History

/*
* grunt-contrib-qunit
* http://gruntjs.com/
*
* Copyright (c) 2014 "Cowboy" Ben Alman, contributors
* 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.
QUnit.log(function (obj) {
// What is this I dont even
if (obj.message === '[object Object], undefined:undefined') { return }
// Parse some stuff before sending it.
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.
actual = QUnit.dump.parse(obj.actual)
expected = QUnit.dump.parse(obj.expected)
}
// Send it.
sendMessage('qunit.log', obj.result, actual, expected, obj.message, obj.source)
})
QUnit.testStart(function (obj) {
sendMessage('qunit.testStart', obj.name)
})
QUnit.testDone(function (obj) {
sendMessage('qunit.testDone', obj.name, obj.failed, obj.passed, obj.total, obj.duration)
})
QUnit.moduleStart(function (obj) {
sendMessage('qunit.moduleStart', obj.name)
})
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')
} else {
2015-05-06 22:34:14 +02:00
console.log('\u00D7 ' + obj.failed + ' tests failed in "' + obj.name + '" module')
}
sendMessage('qunit.moduleDone', obj.name, obj.failed, obj.passed, obj.total)
})
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)
})
}())
2015-08-19 02:06:17 +02:00
// bind polyfill
// shoutout mdn: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind#Polyfill
if (!Function.prototype.bind) {
2015-08-19 04:22:46 +02:00
Function.prototype.bind = function (oThis) {
2015-08-19 02:06:17 +02:00
if (typeof this !== 'function') {
// closest thing possible to the ECMAScript 5
// internal IsCallable function
throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
}
2015-08-19 04:22:46 +02:00
var aArgs = Array.prototype.slice.call(arguments, 1)
var fToBind = this
var FNOP = function () {}
var fBound = function () {
return fToBind.apply(this instanceof FNOP ? this : oThis, aArgs.concat(Array.prototype.slice.call(arguments)))
}
2015-08-19 02:06:17 +02:00
if (this.prototype) {
// native functions don't have a prototype
2015-08-19 04:22:46 +02:00
FNOP.prototype = this.prototype
2015-08-19 02:06:17 +02:00
}
2015-08-19 04:22:46 +02:00
fBound.prototype = new FNOP()
2015-08-19 02:06:17 +02:00
2015-08-19 04:22:46 +02:00
return fBound
}
2015-08-19 02:06:17 +02:00
}