UNPKG

1.29 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8var _jestWatcher = require("jest-watcher");
9
10var _prompt = _interopRequireDefault(require("./prompt"));
11
12function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
14class TestNamePlugin {
15 constructor({
16 stdin,
17 stdout,
18 config = {}
19 }) {
20 this._stdin = stdin;
21 this._stdout = stdout;
22 this._prompt = new _jestWatcher.Prompt();
23 this._testResults = [];
24 this._usageInfo = {
25 key: config.key || 't',
26 prompt: config.prompt || 'filter by a test name regex pattern'
27 };
28 }
29
30 apply(jestHooks) {
31 jestHooks.onTestRunComplete(({
32 testResults
33 }) => {
34 this._testResults = testResults;
35 });
36 }
37
38 onKey(key) {
39 this._prompt.put(key);
40 }
41
42 run(globalConfig, updateConfigAndRun) {
43 const p = new _prompt.default(this._stdout, this._prompt);
44 p.updateCachedTestResults(this._testResults);
45 return new Promise((res, rej) => {
46 p.run(testNamePattern => {
47 updateConfigAndRun({
48 mode: 'watch',
49 testNamePattern
50 });
51 res();
52 }, rej);
53 });
54 }
55
56 getUsageInfo() {
57 return this._usageInfo;
58 }
59
60}
61
62exports.default = TestNamePlugin;
\No newline at end of file