5 * Copyright (c) 2013 "Cowboy" Ben Alman, contributors
6 * Licensed under the MIT license.
9 /*global QUnit:true, alert:true*/
13 // Don't re-order tests.
14 QUnit.config.reorder = false
15 // Run tests serially, not in parallel.
16 QUnit.config.autorun = false
18 // Send messages to the parent PhantomJS process via alert! Good times!!
19 function sendMessage() {
20 var args = [].slice.call(arguments)
21 alert(JSON.stringify(args))
24 // These methods connect QUnit to PhantomJS.
25 QUnit.log = function(obj) {
26 // What is this I don’t even
27 if (obj.message === '[object Object], undefined:undefined') { return }
28 // Parse some stuff before sending it.
29 var actual = QUnit.jsDump.parse(obj.actual)
30 var expected = QUnit.jsDump.parse(obj.expected)
32 sendMessage('qunit.log', obj.result, actual, expected, obj.message, obj.source)
35 QUnit.testStart = function(obj) {
36 sendMessage('qunit.testStart', obj.name)
39 QUnit.testDone = function(obj) {
40 sendMessage('qunit.testDone', obj.name, obj.failed, obj.passed, obj.total)
43 QUnit.moduleStart = function(obj) {
44 sendMessage('qunit.moduleStart', obj.name)
47 QUnit.begin = function () {
48 sendMessage('qunit.begin')
49 console.log("Starting test suite")
50 console.log("================================================\n")
53 QUnit.moduleDone = function (opts) {
54 if (opts.failed === 0) {
55 console.log("\r\u2714 All tests passed in '" + opts.name + "' module")
57 console.log("\u2716 " + opts.failed + " tests failed in '" + opts.name + "' module")
59 sendMessage('qunit.moduleDone', opts.name, opts.failed, opts.passed, opts.total)
62 QUnit.done = function (opts) {
63 console.log("\n================================================")
64 console.log("Tests completed in " + opts.runtime + " milliseconds")
65 console.log(opts.passed + " tests of " + opts.total + " passed, " + opts.failed + " failed.")
66 sendMessage('qunit.done', opts.failed, opts.passed, opts.total, opts.runtime)