testreporter.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2021 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. Object.defineProperty(exports, "__esModule", {
  24. value: true
  25. });
  26. exports.TestReporter = void 0;
  27. const TestReporter = function (browser) {
  28. function send(action, json, cb) {
  29. const r = new XMLHttpRequest();
  30. r.open("POST", action, true);
  31. r.setRequestHeader("Content-Type", "application/json");
  32. r.onreadystatechange = function sendTaskResultOnreadystatechange(e) {
  33. if (r.readyState === 4) {
  34. if (r.status !== 200) {
  35. send(action, json, cb);
  36. } else {
  37. if (cb) {
  38. cb();
  39. }
  40. }
  41. }
  42. };
  43. json.browser = browser;
  44. r.send(JSON.stringify(json));
  45. }
  46. function sendInfo(message) {
  47. send("/info", {
  48. message
  49. });
  50. }
  51. function sendResult(status, description, error) {
  52. const message = {
  53. status,
  54. description
  55. };
  56. if (typeof error !== "undefined") {
  57. message.error = error;
  58. }
  59. send("/submit_task_results", message);
  60. }
  61. function sendQuitRequest() {
  62. send(`/tellMeToQuit?browser=${escape(browser)}`, {});
  63. }
  64. this.now = function () {
  65. return Date.now();
  66. };
  67. this.jasmineStarted = function (suiteInfo) {
  68. this.runnerStartTime = this.now();
  69. const total = suiteInfo.totalSpecsDefined;
  70. const seed = suiteInfo.order.seed;
  71. sendInfo(`Started ${total} tests for ${browser} with seed ${seed}.`);
  72. };
  73. this.suiteStarted = function (result) {
  74. if (result.failedExpectations.length > 0) {
  75. let failedMessages = "";
  76. for (const item of result.failedExpectations) {
  77. failedMessages += `${item.message} `;
  78. }
  79. sendResult("TEST-UNEXPECTED-FAIL", result.description, failedMessages);
  80. }
  81. };
  82. this.specStarted = function (result) {};
  83. this.specDone = function (result) {
  84. if (result.failedExpectations.length === 0) {
  85. sendResult("TEST-PASSED", result.description);
  86. } else {
  87. let failedMessages = "";
  88. for (const item of result.failedExpectations) {
  89. failedMessages += `${item.message} `;
  90. }
  91. sendResult("TEST-UNEXPECTED-FAIL", result.description, failedMessages);
  92. }
  93. };
  94. this.suiteDone = function (result) {};
  95. this.jasmineDone = function () {
  96. setTimeout(sendQuitRequest, 500);
  97. };
  98. };
  99. exports.TestReporter = TestReporter;