teleSuiteUpdater.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. "use strict";
  2. var __defProp = Object.defineProperty;
  3. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  4. var __getOwnPropNames = Object.getOwnPropertyNames;
  5. var __hasOwnProp = Object.prototype.hasOwnProperty;
  6. var __export = (target, all) => {
  7. for (var name in all)
  8. __defProp(target, name, { get: all[name], enumerable: true });
  9. };
  10. var __copyProps = (to, from, except, desc) => {
  11. if (from && typeof from === "object" || typeof from === "function") {
  12. for (let key of __getOwnPropNames(from))
  13. if (!__hasOwnProp.call(to, key) && key !== except)
  14. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  15. }
  16. return to;
  17. };
  18. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  19. var teleSuiteUpdater_exports = {};
  20. __export(teleSuiteUpdater_exports, {
  21. TeleSuiteUpdater: () => TeleSuiteUpdater
  22. });
  23. module.exports = __toCommonJS(teleSuiteUpdater_exports);
  24. var import_teleReceiver = require("./teleReceiver");
  25. var import_testTree = require("./testTree");
  26. class TeleSuiteUpdater {
  27. constructor(options) {
  28. this.loadErrors = [];
  29. this.progress = {
  30. total: 0,
  31. passed: 0,
  32. failed: 0,
  33. skipped: 0
  34. };
  35. this._lastRunTestCount = 0;
  36. this._receiver = new import_teleReceiver.TeleReporterReceiver(this._createReporter(), {
  37. mergeProjects: true,
  38. mergeTestCases: true,
  39. resolvePath: (rootDir, relativePath) => rootDir + options.pathSeparator + relativePath,
  40. clearPreviousResultsWhenTestBegins: true
  41. });
  42. this._options = options;
  43. }
  44. _createReporter() {
  45. return {
  46. version: () => "v2",
  47. onConfigure: (c) => {
  48. this.config = c;
  49. this._lastRunReceiver = new import_teleReceiver.TeleReporterReceiver({
  50. version: () => "v2",
  51. onBegin: (suite) => {
  52. this._lastRunTestCount = suite.allTests().length;
  53. this._lastRunReceiver = void 0;
  54. }
  55. }, {
  56. mergeProjects: true,
  57. mergeTestCases: false,
  58. resolvePath: (rootDir, relativePath) => rootDir + this._options.pathSeparator + relativePath
  59. });
  60. },
  61. onBegin: (suite) => {
  62. if (!this.rootSuite)
  63. this.rootSuite = suite;
  64. if (this._testResultsSnapshot) {
  65. for (const test of this.rootSuite.allTests())
  66. test.results = this._testResultsSnapshot?.get(test.id) || test.results;
  67. this._testResultsSnapshot = void 0;
  68. }
  69. this.progress.total = this._lastRunTestCount;
  70. this.progress.passed = 0;
  71. this.progress.failed = 0;
  72. this.progress.skipped = 0;
  73. this._options.onUpdate(true);
  74. },
  75. onEnd: () => {
  76. this._options.onUpdate(true);
  77. },
  78. onTestBegin: (test, testResult) => {
  79. testResult[import_testTree.statusEx] = "running";
  80. this._options.onUpdate();
  81. },
  82. onTestEnd: (test, testResult) => {
  83. if (test.outcome() === "skipped")
  84. ++this.progress.skipped;
  85. else if (test.outcome() === "unexpected")
  86. ++this.progress.failed;
  87. else
  88. ++this.progress.passed;
  89. testResult[import_testTree.statusEx] = testResult.status;
  90. this._options.onUpdate();
  91. },
  92. onError: (error) => this._handleOnError(error),
  93. printsToStdio: () => false
  94. };
  95. }
  96. processGlobalReport(report) {
  97. const receiver = new import_teleReceiver.TeleReporterReceiver({
  98. version: () => "v2",
  99. onConfigure: (c) => {
  100. this.config = c;
  101. },
  102. onError: (error) => this._handleOnError(error)
  103. });
  104. for (const message of report)
  105. void receiver.dispatch(message);
  106. }
  107. processListReport(report) {
  108. const tests = this.rootSuite?.allTests() || [];
  109. this._testResultsSnapshot = new Map(tests.map((test) => [test.id, test.results]));
  110. this._receiver.reset();
  111. for (const message of report)
  112. void this._receiver.dispatch(message);
  113. }
  114. processTestReportEvent(message) {
  115. this._lastRunReceiver?.dispatch(message)?.catch(() => {
  116. });
  117. this._receiver.dispatch(message)?.catch(() => {
  118. });
  119. }
  120. _handleOnError(error) {
  121. this.loadErrors.push(error);
  122. this._options.onError?.(error);
  123. this._options.onUpdate();
  124. }
  125. asModel() {
  126. return {
  127. rootSuite: this.rootSuite || new import_teleReceiver.TeleSuite("", "root"),
  128. config: this.config,
  129. loadErrors: this.loadErrors,
  130. progress: this.progress
  131. };
  132. }
  133. }
  134. // Annotate the CommonJS export names for ESM import in node:
  135. 0 && (module.exports = {
  136. TeleSuiteUpdater
  137. });