FailedTestsCache.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. function _defineProperty(obj, key, value) {
  7. if (key in obj) {
  8. Object.defineProperty(obj, key, {
  9. value: value,
  10. enumerable: true,
  11. configurable: true,
  12. writable: true
  13. });
  14. } else {
  15. obj[key] = value;
  16. }
  17. return obj;
  18. }
  19. /**
  20. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  21. *
  22. * This source code is licensed under the MIT license found in the
  23. * LICENSE file in the root directory of this source tree.
  24. */
  25. class FailedTestsCache {
  26. constructor() {
  27. _defineProperty(this, '_enabledTestsMap', void 0);
  28. }
  29. filterTests(tests) {
  30. const enabledTestsMap = this._enabledTestsMap;
  31. if (!enabledTestsMap) {
  32. return tests;
  33. }
  34. return tests.filter(testResult => enabledTestsMap[testResult.path]);
  35. }
  36. setTestResults(testResults) {
  37. this._enabledTestsMap = (testResults || [])
  38. .filter(testResult => testResult.numFailingTests)
  39. .reduce((suiteMap, testResult) => {
  40. suiteMap[testResult.testFilePath] = testResult.testResults
  41. .filter(test => test.status === 'failed')
  42. .reduce((testMap, test) => {
  43. testMap[test.fullName] = true;
  44. return testMap;
  45. }, {});
  46. return suiteMap;
  47. }, {});
  48. this._enabledTestsMap = Object.freeze(this._enabledTestsMap);
  49. }
  50. updateConfig(globalConfig) {
  51. if (!this._enabledTestsMap) {
  52. return globalConfig;
  53. }
  54. const newConfig = {...globalConfig};
  55. newConfig.enabledTestsMap = this._enabledTestsMap;
  56. return Object.freeze(newConfig);
  57. }
  58. }
  59. exports.default = FailedTestsCache;