failureTracker.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.FailureTracker = void 0;
  6. /**
  7. * Copyright Microsoft Corporation. All rights reserved.
  8. *
  9. * Licensed under the Apache License, Version 2.0 (the "License");
  10. * you may not use this file except in compliance with the License.
  11. * You may obtain a copy of the License at
  12. *
  13. * http://www.apache.org/licenses/LICENSE-2.0
  14. *
  15. * Unless required by applicable law or agreed to in writing, software
  16. * distributed under the License is distributed on an "AS IS" BASIS,
  17. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18. * See the License for the specific language governing permissions and
  19. * limitations under the License.
  20. */
  21. class FailureTracker {
  22. constructor(_config) {
  23. this._failureCount = 0;
  24. this._hasWorkerErrors = false;
  25. this._rootSuite = void 0;
  26. this._config = _config;
  27. }
  28. onRootSuite(rootSuite) {
  29. this._rootSuite = rootSuite;
  30. }
  31. onTestEnd(test, result) {
  32. if (result.status !== 'skipped' && result.status !== test.expectedStatus) ++this._failureCount;
  33. }
  34. onWorkerError() {
  35. this._hasWorkerErrors = true;
  36. }
  37. hasReachedMaxFailures() {
  38. const maxFailures = this._config.config.maxFailures;
  39. return maxFailures > 0 && this._failureCount >= maxFailures;
  40. }
  41. hasWorkerErrors() {
  42. return this._hasWorkerErrors;
  43. }
  44. result() {
  45. var _this$_rootSuite;
  46. return this._hasWorkerErrors || (_this$_rootSuite = this._rootSuite) !== null && _this$_rootSuite !== void 0 && _this$_rootSuite.allTests().some(test => !test.ok()) ? 'failed' : 'passed';
  47. }
  48. }
  49. exports.FailureTracker = FailureTracker;