failureTracker.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 failureTracker_exports = {};
  20. __export(failureTracker_exports, {
  21. FailureTracker: () => FailureTracker
  22. });
  23. module.exports = __toCommonJS(failureTracker_exports);
  24. class FailureTracker {
  25. constructor(_config) {
  26. this._config = _config;
  27. this._failureCount = 0;
  28. this._hasWorkerErrors = false;
  29. }
  30. canRecoverFromStepError() {
  31. return !!this._recoverFromStepErrorHandler;
  32. }
  33. setRecoverFromStepErrorHandler(recoverFromStepErrorHandler) {
  34. this._recoverFromStepErrorHandler = recoverFromStepErrorHandler;
  35. }
  36. onRootSuite(rootSuite) {
  37. this._rootSuite = rootSuite;
  38. }
  39. onTestEnd(test, result) {
  40. if (test.outcome() === "unexpected" && test.results.length > test.retries)
  41. ++this._failureCount;
  42. }
  43. recoverFromStepError(stepId, error, resumeAfterStepError) {
  44. if (!this._recoverFromStepErrorHandler) {
  45. resumeAfterStepError({ stepId, status: "failed" });
  46. return;
  47. }
  48. void this._recoverFromStepErrorHandler(stepId, error).then(resumeAfterStepError).catch(() => {
  49. });
  50. }
  51. onWorkerError() {
  52. this._hasWorkerErrors = true;
  53. }
  54. hasReachedMaxFailures() {
  55. return this.maxFailures() > 0 && this._failureCount >= this.maxFailures();
  56. }
  57. hasWorkerErrors() {
  58. return this._hasWorkerErrors;
  59. }
  60. result() {
  61. return this._hasWorkerErrors || this.hasReachedMaxFailures() || this.hasFailedTests() || this._config.failOnFlakyTests && this.hasFlakyTests() ? "failed" : "passed";
  62. }
  63. hasFailedTests() {
  64. return this._rootSuite?.allTests().some((test) => !test.ok());
  65. }
  66. hasFlakyTests() {
  67. return this._rootSuite?.allTests().some((test) => test.outcome() === "flaky");
  68. }
  69. maxFailures() {
  70. return this._config.config.maxFailures;
  71. }
  72. }
  73. // Annotate the CommonJS export names for ESM import in node:
  74. 0 && (module.exports = {
  75. FailureTracker
  76. });