testreporter.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2019 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * Javascript code in this page
  21. */
  22. 'use strict';
  23. var TestReporter = function TestReporter(browser, appPath) {
  24. function send(action, json, cb) {
  25. var r = new XMLHttpRequest();
  26. r.open('POST', action, true);
  27. r.setRequestHeader('Content-Type', 'application/json');
  28. r.onreadystatechange = function sendTaskResultOnreadystatechange(e) {
  29. if (r.readyState === 4) {
  30. if (r.status !== 200) {
  31. send(action, json, cb);
  32. } else {
  33. if (cb) {
  34. cb();
  35. }
  36. }
  37. }
  38. };
  39. json['browser'] = browser;
  40. r.send(JSON.stringify(json));
  41. }
  42. function sendInfo(message) {
  43. send('/info', {
  44. message: message
  45. });
  46. }
  47. function sendResult(status, description, error) {
  48. var message = {
  49. status: status,
  50. description: description
  51. };
  52. if (typeof error !== 'undefined') {
  53. message['error'] = error;
  54. }
  55. send('/submit_task_results', message);
  56. }
  57. function sendQuitRequest() {
  58. send('/tellMeToQuit?path=' + escape(appPath), {});
  59. }
  60. this.now = function () {
  61. return new Date().getTime();
  62. };
  63. this.jasmineStarted = function (suiteInfo) {
  64. this.runnerStartTime = this.now();
  65. sendInfo('Started tests for ' + browser + '.');
  66. };
  67. this.suiteStarted = function (result) {};
  68. this.specStarted = function (result) {};
  69. this.specDone = function (result) {
  70. if (result.failedExpectations.length === 0) {
  71. sendResult('TEST-PASSED', result.description);
  72. } else {
  73. var failedMessages = '';
  74. var items = result.failedExpectations;
  75. for (var i = 0, ii = items.length; i < ii; i++) {
  76. failedMessages += items[i].message + ' ';
  77. }
  78. sendResult('TEST-UNEXPECTED-FAIL', result.description, failedMessages);
  79. }
  80. };
  81. this.suiteDone = function (result) {};
  82. this.jasmineDone = function () {
  83. setTimeout(sendQuitRequest, 500);
  84. };
  85. };