TestNamePatternPrompt.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. function _jestWatcher() {
  7. const data = require('jest-watcher');
  8. _jestWatcher = function _jestWatcher() {
  9. return data;
  10. };
  11. return data;
  12. }
  13. function _defineProperty(obj, key, value) {
  14. if (key in obj) {
  15. Object.defineProperty(obj, key, {
  16. value: value,
  17. enumerable: true,
  18. configurable: true,
  19. writable: true
  20. });
  21. } else {
  22. obj[key] = value;
  23. }
  24. return obj;
  25. }
  26. // TODO: Make underscored props `private`
  27. class TestNamePatternPrompt extends _jestWatcher().PatternPrompt {
  28. constructor(pipe, prompt) {
  29. super(pipe, prompt);
  30. _defineProperty(this, '_cachedTestResults', void 0);
  31. this._entityName = 'tests';
  32. this._cachedTestResults = [];
  33. }
  34. _onChange(pattern, options) {
  35. super._onChange(pattern, options);
  36. this._printPrompt(pattern);
  37. }
  38. _printPrompt(pattern) {
  39. const pipe = this._pipe;
  40. (0, _jestWatcher().printPatternCaret)(pattern, pipe);
  41. (0, _jestWatcher().printRestoredPatternCaret)(
  42. pattern,
  43. this._currentUsageRows,
  44. pipe
  45. );
  46. }
  47. _getMatchedTests(pattern) {
  48. let regex;
  49. try {
  50. regex = new RegExp(pattern, 'i');
  51. } catch (e) {
  52. return [];
  53. }
  54. const matchedTests = [];
  55. this._cachedTestResults.forEach(({testResults}) =>
  56. testResults.forEach(({title}) => {
  57. if (regex.test(title)) {
  58. matchedTests.push(title);
  59. }
  60. })
  61. );
  62. return matchedTests;
  63. }
  64. updateCachedTestResults(testResults = []) {
  65. this._cachedTestResults = testResults;
  66. }
  67. }
  68. exports.default = TestNamePatternPrompt;