FailedTestsCache.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. function _objectSpread(target) {
  7. for (var i = 1; i < arguments.length; i++) {
  8. var source = arguments[i] != null ? arguments[i] : {};
  9. var ownKeys = Object.keys(source);
  10. if (typeof Object.getOwnPropertySymbols === 'function') {
  11. ownKeys = ownKeys.concat(
  12. Object.getOwnPropertySymbols(source).filter(function(sym) {
  13. return Object.getOwnPropertyDescriptor(source, sym).enumerable;
  14. })
  15. );
  16. }
  17. ownKeys.forEach(function(key) {
  18. _defineProperty(target, key, source[key]);
  19. });
  20. }
  21. return target;
  22. }
  23. function _defineProperty(obj, key, value) {
  24. if (key in obj) {
  25. Object.defineProperty(obj, key, {
  26. value: value,
  27. enumerable: true,
  28. configurable: true,
  29. writable: true
  30. });
  31. } else {
  32. obj[key] = value;
  33. }
  34. return obj;
  35. }
  36. /**
  37. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  38. *
  39. * This source code is licensed under the MIT license found in the
  40. * LICENSE file in the root directory of this source tree.
  41. */
  42. class FailedTestsCache {
  43. constructor() {
  44. _defineProperty(this, '_enabledTestsMap', void 0);
  45. }
  46. filterTests(tests) {
  47. const enabledTestsMap = this._enabledTestsMap;
  48. if (!enabledTestsMap) {
  49. return tests;
  50. }
  51. return tests.filter(testResult => enabledTestsMap[testResult.path]);
  52. }
  53. setTestResults(testResults) {
  54. this._enabledTestsMap = (testResults || [])
  55. .filter(testResult => testResult.numFailingTests)
  56. .reduce((suiteMap, testResult) => {
  57. suiteMap[testResult.testFilePath] = testResult.testResults
  58. .filter(test => test.status === 'failed')
  59. .reduce((testMap, test) => {
  60. testMap[test.fullName] = true;
  61. return testMap;
  62. }, {});
  63. return suiteMap;
  64. }, {});
  65. this._enabledTestsMap = Object.freeze(this._enabledTestsMap);
  66. }
  67. updateConfig(globalConfig) {
  68. if (!this._enabledTestsMap) {
  69. return globalConfig;
  70. }
  71. const newConfig = _objectSpread({}, globalConfig);
  72. newConfig.enabledTestsMap = this._enabledTestsMap;
  73. return Object.freeze(newConfig);
  74. }
  75. }
  76. exports.default = FailedTestsCache;