line.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 line_exports = {};
  20. __export(line_exports, {
  21. default: () => line_default
  22. });
  23. module.exports = __toCommonJS(line_exports);
  24. var import_base = require("./base");
  25. class LineReporter extends import_base.TerminalReporter {
  26. constructor() {
  27. super(...arguments);
  28. this._current = 0;
  29. this._failures = 0;
  30. this._didBegin = false;
  31. }
  32. onBegin(suite) {
  33. super.onBegin(suite);
  34. const startingMessage = this.generateStartingMessage();
  35. if (startingMessage) {
  36. this.writeLine(startingMessage);
  37. this.writeLine();
  38. }
  39. this._didBegin = true;
  40. }
  41. onStdOut(chunk, test, result) {
  42. super.onStdOut(chunk, test, result);
  43. this._dumpToStdio(test, chunk, this.screen.stdout);
  44. }
  45. onStdErr(chunk, test, result) {
  46. super.onStdErr(chunk, test, result);
  47. this._dumpToStdio(test, chunk, this.screen.stderr);
  48. }
  49. _dumpToStdio(test, chunk, stream) {
  50. if (this.config.quiet)
  51. return;
  52. if (!process.env.PW_TEST_DEBUG_REPORTERS)
  53. stream.write(`\x1B[1A\x1B[2K`);
  54. if (test && this._lastTest !== test) {
  55. const title = this.screen.colors.dim(this.formatTestTitle(test));
  56. stream.write(this.fitToScreen(title) + `
  57. `);
  58. this._lastTest = test;
  59. }
  60. stream.write(chunk);
  61. if (chunk[chunk.length - 1] !== "\n")
  62. this.writeLine();
  63. this.writeLine();
  64. }
  65. onTestBegin(test, result) {
  66. ++this._current;
  67. this._updateLine(test, result, void 0);
  68. }
  69. onStepBegin(test, result, step) {
  70. if (this.screen.isTTY && step.category === "test.step")
  71. this._updateLine(test, result, step);
  72. }
  73. onStepEnd(test, result, step) {
  74. if (this.screen.isTTY && step.category === "test.step")
  75. this._updateLine(test, result, step.parent);
  76. }
  77. onTestEnd(test, result) {
  78. super.onTestEnd(test, result);
  79. if (!this.willRetry(test) && (test.outcome() === "flaky" || test.outcome() === "unexpected" || result.status === "interrupted")) {
  80. if (!process.env.PW_TEST_DEBUG_REPORTERS)
  81. this.screen.stdout.write(`\x1B[1A\x1B[2K`);
  82. this.writeLine(this.formatFailure(test, ++this._failures));
  83. this.writeLine();
  84. }
  85. }
  86. _updateLine(test, result, step) {
  87. const retriesPrefix = this.totalTestCount < this._current ? ` (retries)` : ``;
  88. const prefix = `[${this._current}/${this.totalTestCount}]${retriesPrefix} `;
  89. const currentRetrySuffix = result.retry ? this.screen.colors.yellow(` (retry #${result.retry})`) : "";
  90. const title = this.formatTestTitle(test, step) + currentRetrySuffix;
  91. if (process.env.PW_TEST_DEBUG_REPORTERS)
  92. this.screen.stdout.write(`${prefix + title}
  93. `);
  94. else
  95. this.screen.stdout.write(`\x1B[1A\x1B[2K${prefix + this.fitToScreen(title, prefix)}
  96. `);
  97. }
  98. onError(error) {
  99. super.onError(error);
  100. const message = this.formatError(error).message + "\n";
  101. if (!process.env.PW_TEST_DEBUG_REPORTERS && this._didBegin)
  102. this.screen.stdout.write(`\x1B[1A\x1B[2K`);
  103. this.screen.stdout.write(message);
  104. this.writeLine();
  105. }
  106. async onEnd(result) {
  107. if (!process.env.PW_TEST_DEBUG_REPORTERS && this._didBegin)
  108. this.screen.stdout.write(`\x1B[1A\x1B[2K`);
  109. await super.onEnd(result);
  110. this.epilogue(false);
  111. }
  112. }
  113. var line_default = LineReporter;