2
0

testreporter.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * JavaScript code in this page
  4. *
  5. * Copyright 2022 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) {
  29. return new Promise(resolve => {
  30. json.browser = browser;
  31. fetch(action, {
  32. method: "POST",
  33. headers: {
  34. "Content-Type": "application/json"
  35. },
  36. body: JSON.stringify(json)
  37. }).then(response => {
  38. if (!response.ok || response.status !== 200) {
  39. throw new Error(response.statusText);
  40. }
  41. resolve();
  42. }).catch(reason => {
  43. console.warn(`TestReporter - send failed (${action}): ${reason}`);
  44. resolve();
  45. send(action, json);
  46. });
  47. });
  48. }
  49. function sendInfo(message) {
  50. send("/info", {
  51. message
  52. });
  53. }
  54. function sendResult(status, description, error) {
  55. const message = {
  56. status,
  57. description
  58. };
  59. if (error !== undefined) {
  60. message.error = error;
  61. }
  62. send("/submit_task_results", message);
  63. }
  64. function sendQuitRequest() {
  65. send(`/tellMeToQuit?browser=${escape(browser)}`, {});
  66. }
  67. this.now = function () {
  68. return Date.now();
  69. };
  70. this.jasmineStarted = function (suiteInfo) {
  71. this.runnerStartTime = this.now();
  72. const total = suiteInfo.totalSpecsDefined;
  73. const seed = suiteInfo.order.seed;
  74. sendInfo(`Started ${total} tests for ${browser} with seed ${seed}.`);
  75. };
  76. this.suiteStarted = function (result) {
  77. if (result.failedExpectations.length > 0) {
  78. let failedMessages = "";
  79. for (const item of result.failedExpectations) {
  80. failedMessages += `${item.message} `;
  81. }
  82. sendResult("TEST-UNEXPECTED-FAIL", result.description, failedMessages);
  83. }
  84. };
  85. this.specStarted = function (result) {};
  86. this.specDone = function (result) {
  87. if (result.failedExpectations.length === 0) {
  88. sendResult("TEST-PASSED", result.description);
  89. } else {
  90. let failedMessages = "";
  91. for (const item of result.failedExpectations) {
  92. failedMessages += `${item.message} `;
  93. }
  94. sendResult("TEST-UNEXPECTED-FAIL", result.description, failedMessages);
  95. }
  96. };
  97. this.suiteDone = function (result) {};
  98. this.jasmineDone = function () {
  99. setTimeout(sendQuitRequest, 500);
  100. };
  101. };
  102. exports.TestReporter = TestReporter;