reporterV2.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 reporterV2_exports = {};
  20. __export(reporterV2_exports, {
  21. wrapReporterAsV2: () => wrapReporterAsV2
  22. });
  23. module.exports = __toCommonJS(reporterV2_exports);
  24. function wrapReporterAsV2(reporter) {
  25. try {
  26. if ("version" in reporter && reporter.version() === "v2")
  27. return reporter;
  28. } catch (e) {
  29. }
  30. return new ReporterV2Wrapper(reporter);
  31. }
  32. class ReporterV2Wrapper {
  33. constructor(reporter) {
  34. this._deferred = [];
  35. this._reporter = reporter;
  36. }
  37. version() {
  38. return "v2";
  39. }
  40. onConfigure(config) {
  41. this._config = config;
  42. }
  43. onBegin(suite) {
  44. this._reporter.onBegin?.(this._config, suite);
  45. const deferred = this._deferred;
  46. this._deferred = null;
  47. for (const item of deferred) {
  48. if (item.error)
  49. this.onError(item.error);
  50. if (item.stdout)
  51. this.onStdOut(item.stdout.chunk, item.stdout.test, item.stdout.result);
  52. if (item.stderr)
  53. this.onStdErr(item.stderr.chunk, item.stderr.test, item.stderr.result);
  54. }
  55. }
  56. onTestBegin(test, result) {
  57. this._reporter.onTestBegin?.(test, result);
  58. }
  59. onStdOut(chunk, test, result) {
  60. if (this._deferred) {
  61. this._deferred.push({ stdout: { chunk, test, result } });
  62. return;
  63. }
  64. this._reporter.onStdOut?.(chunk, test, result);
  65. }
  66. onStdErr(chunk, test, result) {
  67. if (this._deferred) {
  68. this._deferred.push({ stderr: { chunk, test, result } });
  69. return;
  70. }
  71. this._reporter.onStdErr?.(chunk, test, result);
  72. }
  73. onTestEnd(test, result) {
  74. this._reporter.onTestEnd?.(test, result);
  75. }
  76. async onEnd(result) {
  77. return await this._reporter.onEnd?.(result);
  78. }
  79. async onExit() {
  80. await this._reporter.onExit?.();
  81. }
  82. onError(error) {
  83. if (this._deferred) {
  84. this._deferred.push({ error });
  85. return;
  86. }
  87. this._reporter.onError?.(error);
  88. }
  89. onStepBegin(test, result, step) {
  90. this._reporter.onStepBegin?.(test, result, step);
  91. }
  92. onStepEnd(test, result, step) {
  93. this._reporter.onStepEnd?.(test, result, step);
  94. }
  95. printsToStdio() {
  96. return this._reporter.printsToStdio ? this._reporter.printsToStdio() : true;
  97. }
  98. }
  99. // Annotate the CommonJS export names for ESM import in node:
  100. 0 && (module.exports = {
  101. wrapReporterAsV2
  102. });