multiplexer.js 3.1 KB

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