FailedTestsCache.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. }
  51. exports.default = FailedTestsCache;