phantom.js 2.0 KB

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