phantom.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * grunt-contrib-qunit
  3. * http://gruntjs.com/
  4. *
  5. * Copyright (c) 2013 "Cowboy" Ben Alman, contributors
  6. * Licensed under the MIT license.
  7. */
  8. /*global QUnit:true, alert:true*/
  9. (function () {
  10. 'use strict';
  11. // Don't re-order tests.
  12. QUnit.config.reorder = false
  13. // Run tests serially, not in parallel.
  14. QUnit.config.autorun = false
  15. // Send messages to the parent PhantomJS process via alert! Good times!!
  16. function sendMessage() {
  17. var args = [].slice.call(arguments)
  18. alert(JSON.stringify(args))
  19. }
  20. // These methods connect QUnit to PhantomJS.
  21. QUnit.log = function(obj) {
  22. // What is this I don’t even
  23. if (obj.message === '[object Object], undefined:undefined') { return }
  24. // Parse some stuff before sending it.
  25. var actual = QUnit.jsDump.parse(obj.actual)
  26. var expected = QUnit.jsDump.parse(obj.expected)
  27. // Send it.
  28. sendMessage('qunit.log', obj.result, actual, expected, obj.message, obj.source)
  29. }
  30. QUnit.testStart = function(obj) {
  31. sendMessage('qunit.testStart', obj.name)
  32. }
  33. QUnit.testDone = function(obj) {
  34. sendMessage('qunit.testDone', obj.name, obj.failed, obj.passed, obj.total)
  35. }
  36. QUnit.moduleStart = function(obj) {
  37. sendMessage('qunit.moduleStart', obj.name)
  38. }
  39. QUnit.begin = function () {
  40. sendMessage('qunit.begin')
  41. console.log("Starting test suite")
  42. console.log("================================================\n")
  43. }
  44. QUnit.moduleDone = function (opts) {
  45. if (opts.failed === 0) {
  46. console.log("\r\u2714 All tests passed in '" + opts.name + "' module")
  47. } else {
  48. console.log("\u2716 " + opts.failed + " tests failed in '" + opts.name + "' module")
  49. }
  50. sendMessage('qunit.moduleDone', opts.name, opts.failed, opts.passed, opts.total)
  51. }
  52. QUnit.done = function (opts) {
  53. console.log("\n================================================")
  54. console.log("Tests completed in " + opts.runtime + " milliseconds")
  55. console.log(opts.passed + " tests of " + opts.total + " passed, " + opts.failed + " failed.")
  56. sendMessage('qunit.done', opts.failed, opts.passed, opts.total, opts.runtime)
  57. }
  58. }())