failureTracker.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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, options) {
  26. this._failureCount = 0;
  27. this._hasWorkerErrors = false;
  28. this._topLevelProjects = [];
  29. this._config = config;
  30. this._pauseOnError = !!options?.pauseOnError;
  31. this._pauseAtEnd = !!options?.pauseAtEnd;
  32. }
  33. onRootSuite(rootSuite, topLevelProjects) {
  34. this._rootSuite = rootSuite;
  35. this._topLevelProjects = topLevelProjects;
  36. }
  37. onTestEnd(test, result) {
  38. if (test.outcome() === "unexpected" && test.results.length > test.retries)
  39. ++this._failureCount;
  40. }
  41. onWorkerError() {
  42. this._hasWorkerErrors = true;
  43. }
  44. pauseOnError() {
  45. return this._pauseOnError;
  46. }
  47. pauseAtEnd(inProject) {
  48. return this._topLevelProjects.includes(inProject) && this._pauseAtEnd;
  49. }
  50. hasReachedMaxFailures() {
  51. return this.maxFailures() > 0 && this._failureCount >= this.maxFailures();
  52. }
  53. hasWorkerErrors() {
  54. return this._hasWorkerErrors;
  55. }
  56. result() {
  57. return this._hasWorkerErrors || this.hasReachedMaxFailures() || this.hasFailedTests() || this._config.failOnFlakyTests && this.hasFlakyTests() ? "failed" : "passed";
  58. }
  59. hasFailedTests() {
  60. return this._rootSuite?.allTests().some((test) => !test.ok());
  61. }
  62. hasFlakyTests() {
  63. return this._rootSuite?.allTests().some((test) => test.outcome() === "flaky");
  64. }
  65. maxFailures() {
  66. return this._config.config.maxFailures;
  67. }
  68. }
  69. // Annotate the CommonJS export names for ESM import in node:
  70. 0 && (module.exports = {
  71. FailureTracker
  72. });