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