2
0

testreporter.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2020 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 (browser) {
  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
  45. });
  46. }
  47. function sendResult(status, description, error) {
  48. var message = {
  49. status,
  50. 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?browser=${escape(browser)}`, {});
  59. }
  60. this.now = function () {
  61. return new Date().getTime();
  62. };
  63. this.jasmineStarted = function (suiteInfo) {
  64. this.runnerStartTime = this.now();
  65. const total = suiteInfo.totalSpecsDefined;
  66. const seed = suiteInfo.order.seed;
  67. sendInfo(`Started ${total} tests for ${browser} with seed ${seed}.`);
  68. };
  69. this.suiteStarted = function (result) {
  70. if (result.failedExpectations.length > 0) {
  71. let failedMessages = "";
  72. for (const item of result.failedExpectations) {
  73. failedMessages += `${item.message} `;
  74. }
  75. sendResult("TEST-UNEXPECTED-FAIL", result.description, failedMessages);
  76. }
  77. };
  78. this.specStarted = function (result) {};
  79. this.specDone = function (result) {
  80. if (result.failedExpectations.length === 0) {
  81. sendResult("TEST-PASSED", result.description);
  82. } else {
  83. let failedMessages = "";
  84. for (const item of result.failedExpectations) {
  85. failedMessages += `${item.message} `;
  86. }
  87. sendResult("TEST-UNEXPECTED-FAIL", result.description, failedMessages);
  88. }
  89. };
  90. this.suiteDone = function (result) {};
  91. this.jasmineDone = function () {
  92. setTimeout(sendQuitRequest, 500);
  93. };
  94. };