jest-watch-typeahead 0.6.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![Build Status](https://travis-ci.org/jest-community/jest-watch-typeahead.svg?branch=master)](https://travis-ci.org/jest-community/jest-watch-typeahead) [![npm version](https://badge.fury.io/js/jest-watch-typeahead.svg)](https://badge.fury.io/js/jest-watch-typeahead)
1
+ [![Build Status](https://github.com/jest-community/jest-watch-typeahead/actions/workflows/nodejs.yml/badge.svg?branch=main)](https://github.com/jest-community/jest-watch-typeahead/actions/workflows/nodejs.yml) [![npm version](https://badge.fury.io/js/jest-watch-typeahead.svg)](https://badge.fury.io/js/jest-watch-typeahead)
2
2
 
3
3
  <div align="center">
4
4
  <a href="https://jestjs.io/">
@@ -14,7 +14,7 @@
14
14
 
15
15
  ### Install
16
16
 
17
- Install `jest`_(it needs Jest 26+)_ and `jest-watch-typeahead`
17
+ Install `jest`_(it needs Jest 27+)_ and `jest-watch-typeahead`
18
18
 
19
19
  ```bash
20
20
  yarn add --dev jest jest-watch-typeahead
@@ -1,17 +1,6 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _jestWatcher = require("jest-watcher");
9
-
10
- var _prompt = _interopRequireDefault(require("./prompt"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- class FileNamePlugin {
1
+ import { Prompt } from 'jest-watcher';
2
+ import FileNamePatternPrompt from "./prompt.js";
3
+ export default class FileNamePlugin {
15
4
  constructor({
16
5
  stdin,
17
6
  stdout,
@@ -19,7 +8,7 @@ class FileNamePlugin {
19
8
  }) {
20
9
  this._stdin = stdin;
21
10
  this._stdout = stdout;
22
- this._prompt = new _jestWatcher.Prompt();
11
+ this._prompt = new Prompt();
23
12
  this._projects = [];
24
13
  this._usageInfo = {
25
14
  key: config.key || 'p',
@@ -40,7 +29,7 @@ class FileNamePlugin {
40
29
  }
41
30
 
42
31
  run(globalConfig, updateConfigAndRun) {
43
- const p = new _prompt.default(this._stdout, this._prompt);
32
+ const p = new FileNamePatternPrompt(this._stdout, this._prompt);
44
33
  p.updateSearchSources(this._projects);
45
34
  return new Promise((res, rej) => {
46
35
  p.run(testPathPattern => {
@@ -57,6 +46,4 @@ class FileNamePlugin {
57
46
  return this._usageInfo;
58
47
  }
59
48
 
60
- }
61
-
62
- exports.default = FileNamePlugin;
49
+ }
@@ -1,29 +1,12 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _chalk = _interopRequireDefault(require("chalk"));
9
-
10
- var _ansiEscapes = _interopRequireDefault(require("ansi-escapes"));
11
-
12
- var _stringLength = _interopRequireDefault(require("string-length"));
13
-
14
- var _jestWatcher = require("jest-watcher");
15
-
16
- var _jestRegexUtil = require("jest-regex-util");
17
-
18
- var _utils = require("../lib/utils");
19
-
20
- var _pattern_mode_helpers = require("../lib/pattern_mode_helpers");
21
-
22
- var _scroll = _interopRequireDefault(require("../lib/scroll"));
23
-
24
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
-
26
- class FileNamePatternPrompt extends _jestWatcher.PatternPrompt {
1
+ import chalk from 'chalk';
2
+ import ansiEscapes from 'ansi-escapes';
3
+ import stringLength from 'string-length';
4
+ import { PatternPrompt, printPatternCaret, printRestoredPatternCaret } from 'jest-watcher';
5
+ import { escapeStrForRegex } from 'jest-regex-util';
6
+ import { highlight, getTerminalWidth, trimAndFormatPath, removeTrimmingDots } from "../lib/utils.js";
7
+ import { formatTypeaheadSelection, printMore, printPatternMatches, printStartTyping, printTypeaheadItem } from "../lib/pattern_mode_helpers.js";
8
+ import scroll from "../lib/scroll.js";
9
+ export default class FileNamePatternPrompt extends PatternPrompt {
27
10
  constructor(pipe, prompt) {
28
11
  super(pipe, prompt);
29
12
  this._entityName = 'filenames';
@@ -42,36 +25,36 @@ class FileNamePatternPrompt extends _jestWatcher.PatternPrompt {
42
25
  const total = matchedTests.length;
43
26
  const pipe = this._pipe;
44
27
  const prompt = this._prompt;
45
- (0, _jestWatcher.printPatternCaret)(pattern, pipe);
46
- pipe.write(_ansiEscapes.default.cursorLeft);
28
+ printPatternCaret(pattern, pipe);
29
+ pipe.write(ansiEscapes.cursorLeft);
47
30
 
48
31
  if (pattern) {
49
- (0, _pattern_mode_helpers.printPatternMatches)(total, 'file', pipe);
50
- const prefix = ` ${_chalk.default.dim('\u203A')} `;
51
- const padding = (0, _stringLength.default)(prefix) + 2;
52
- const width = (0, _utils.getTerminalWidth)(pipe);
32
+ printPatternMatches(total, 'file', pipe);
33
+ const prefix = ` ${chalk.dim('\u203A')} `;
34
+ const padding = stringLength(prefix) + 2;
35
+ const width = getTerminalWidth(pipe);
53
36
  const {
54
37
  start,
55
38
  end,
56
39
  index
57
- } = (0, _scroll.default)(total, options);
40
+ } = scroll(total, options);
58
41
  prompt.setPromptLength(total);
59
42
  matchedTests.slice(start, end).map(({
60
43
  path,
61
44
  context
62
45
  }) => {
63
- const filePath = (0, _utils.trimAndFormatPath)(padding, context.config, path, width);
64
- return (0, _utils.highlight)(path, filePath, pattern);
65
- }).map((item, i) => (0, _pattern_mode_helpers.formatTypeaheadSelection)(item, i, index, prompt)).forEach(item => (0, _pattern_mode_helpers.printTypeaheadItem)(item, pipe));
46
+ const filePath = trimAndFormatPath(padding, context.config, path, width);
47
+ return highlight(path, filePath, pattern);
48
+ }).map((item, i) => formatTypeaheadSelection(item, i, index, prompt)).forEach(item => printTypeaheadItem(item, pipe));
66
49
 
67
50
  if (total > end) {
68
- (0, _pattern_mode_helpers.printMore)('file', pipe, total - end);
51
+ printMore('file', pipe, total - end);
69
52
  }
70
53
  } else {
71
- (0, _pattern_mode_helpers.printStartTyping)('filename', pipe);
54
+ printStartTyping('filename', pipe);
72
55
  }
73
56
 
74
- (0, _jestWatcher.printRestoredPatternCaret)(pattern, this._currentUsageRows, pipe);
57
+ printRestoredPatternCaret(pattern, this._currentUsageRows, pipe);
75
58
  }
76
59
 
77
60
  _getMatchedTests(pattern) {
@@ -102,10 +85,8 @@ class FileNamePatternPrompt extends _jestWatcher.PatternPrompt {
102
85
 
103
86
  run(onSuccess, onCancel, options) {
104
87
  super.run(value => {
105
- onSuccess((0, _utils.removeTrimmingDots)(value).split('/').map(_jestRegexUtil.escapeStrForRegex).join('/'));
88
+ onSuccess(removeTrimmingDots(value).split('/').map(escapeStrForRegex).join('/'));
106
89
  }, onCancel, options);
107
90
  }
108
91
 
109
- }
110
-
111
- exports.default = FileNamePatternPrompt;
92
+ }
package/build/index.js CHANGED
@@ -1,5 +1,3 @@
1
- "use strict";
2
-
3
1
  throw new Error(`
4
2
  jest-watch-typeahead includes two watch plugins: The filename plugin and the testname plugin.
5
3
  Please configure Jest as follows:
@@ -1,51 +1,27 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.formatTypeaheadSelection = exports.printTypeaheadItem = exports.printMore = exports.printStartTyping = exports.printPatternMatches = void 0;
7
-
8
- var _chalk = _interopRequireDefault(require("chalk"));
9
-
10
- var _stripAnsi = _interopRequireDefault(require("strip-ansi"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1
+ import chalk from 'chalk';
2
+ import stripAnsi from 'strip-ansi';
13
3
 
14
4
  const pluralize = (count, text) => count === 1 ? text : `${text}s`;
15
5
 
16
- const printPatternMatches = (count, entity, pipe, extraText = '') => {
6
+ export const printPatternMatches = (count, entity, pipe, extraText = '') => {
17
7
  const pluralized = pluralize(count, entity);
18
8
  const result = count ? `\n\n Pattern matches ${count} ${pluralized}` : `\n\n Pattern matches no ${pluralized}`;
19
9
  pipe.write(result + extraText);
20
10
  };
21
-
22
- exports.printPatternMatches = printPatternMatches;
23
-
24
- const printStartTyping = (entity, pipe) => {
25
- pipe.write(`\n\n ${_chalk.default.italic.yellow(`Start typing to filter by a ${entity} regex pattern.`)}`);
11
+ export const printStartTyping = (entity, pipe) => {
12
+ pipe.write(`\n\n ${chalk.italic.yellow(`Start typing to filter by a ${entity} regex pattern.`)}`);
26
13
  };
27
-
28
- exports.printStartTyping = printStartTyping;
29
-
30
- const printMore = (entity, pipe, more) => {
31
- pipe.write(`\n ${_chalk.default.dim(`...and ${more} more ${pluralize(more, entity)}`)}`);
14
+ export const printMore = (entity, pipe, more) => {
15
+ pipe.write(`\n ${chalk.dim(`...and ${more} more ${pluralize(more, entity)}`)}`);
32
16
  };
33
-
34
- exports.printMore = printMore;
35
-
36
- const printTypeaheadItem = (item, pipe) => {
37
- pipe.write(`\n ${_chalk.default.dim('\u203A')} ${item}`);
17
+ export const printTypeaheadItem = (item, pipe) => {
18
+ pipe.write(`\n ${chalk.dim('\u203A')} ${item}`);
38
19
  };
39
-
40
- exports.printTypeaheadItem = printTypeaheadItem;
41
-
42
- const formatTypeaheadSelection = (item, index, activeIndex, prompt) => {
20
+ export const formatTypeaheadSelection = (item, index, activeIndex, prompt) => {
43
21
  if (index === activeIndex) {
44
- prompt.setPromptSelection((0, _stripAnsi.default)(item));
45
- return _chalk.default.black.bgYellow((0, _stripAnsi.default)(item));
22
+ prompt.setPromptSelection(stripAnsi(item));
23
+ return chalk.black.bgYellow(stripAnsi(item));
46
24
  }
47
25
 
48
26
  return item;
49
- };
50
-
51
- exports.formatTypeaheadSelection = formatTypeaheadSelection;
27
+ };
@@ -1,10 +1,3 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
1
  const scroll = (size, {
9
2
  offset,
10
3
  max
@@ -30,5 +23,4 @@ const scroll = (size, {
30
23
  };
31
24
  };
32
25
 
33
- var _default = scroll;
34
- exports.default = _default;
26
+ export default scroll;
@@ -1,39 +1,23 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.removeTrimmingDots = exports.formatTestNameByPattern = exports.highlight = exports.getTerminalWidth = exports.trimAndFormatPath = void 0;
7
-
8
- var _path = _interopRequireDefault(require("path"));
9
-
10
- var _chalk = _interopRequireDefault(require("chalk"));
11
-
12
- var _slash = _interopRequireDefault(require("slash"));
13
-
14
- var _stripAnsi = _interopRequireDefault(require("strip-ansi"));
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
1
+ import path from 'path';
2
+ import chalk from 'chalk';
3
+ import slash from 'slash';
4
+ import stripAnsi from 'strip-ansi';
18
5
  const TRIMMING_DOTS = '...';
19
6
  const ENTER = '⏎';
20
7
 
21
8
  const relativePath = (config, testPath) => {
22
- const relativeTestPath = _path.default.relative(config.cwd || config.rootDir, testPath);
23
-
24
- const dirname = _path.default.dirname(relativeTestPath);
25
-
26
- const basename = _path.default.basename(relativeTestPath);
27
-
9
+ const relativeTestPath = path.relative(config.cwd || config.rootDir, testPath);
10
+ const dirname = path.dirname(relativeTestPath);
11
+ const basename = path.basename(relativeTestPath);
28
12
  return {
29
13
  basename,
30
14
  dirname
31
15
  };
32
16
  };
33
17
 
34
- const colorize = (str, start, end) => _chalk.default.dim(str.slice(0, start)) + _chalk.default.reset(str.slice(start, end)) + _chalk.default.dim(str.slice(end));
18
+ const colorize = (str, start, end) => chalk.dim(str.slice(0, start)) + chalk.reset(str.slice(start, end)) + chalk.dim(str.slice(end));
35
19
 
36
- const trimAndFormatPath = (pad, config, testPath, columns) => {
20
+ export const trimAndFormatPath = (pad, config, testPath, columns) => {
37
21
  const maxLength = columns - pad;
38
22
  const relative = relativePath(config, testPath);
39
23
  const {
@@ -43,8 +27,8 @@ const trimAndFormatPath = (pad, config, testPath, columns) => {
43
27
  dirname
44
28
  } = relative; // length is ok
45
29
 
46
- if ((dirname + _path.default.sep + basename).length <= maxLength) {
47
- return (0, _slash.default)(_chalk.default.dim(dirname + _path.default.sep) + _chalk.default.bold(basename));
30
+ if ((dirname + path.sep + basename).length <= maxLength) {
31
+ return slash(chalk.dim(dirname + path.sep) + chalk.bold(basename));
48
32
  } // we can fit trimmed dirname and full basename
49
33
 
50
34
 
@@ -53,42 +37,36 @@ const trimAndFormatPath = (pad, config, testPath, columns) => {
53
37
  if (basenameLength + 4 < maxLength) {
54
38
  const dirnameLength = maxLength - 4 - basenameLength;
55
39
  dirname = `${TRIMMING_DOTS}${dirname.slice(dirname.length - dirnameLength, dirname.length)}`;
56
- return (0, _slash.default)(_chalk.default.dim(dirname + _path.default.sep) + _chalk.default.bold(basename));
40
+ return slash(chalk.dim(dirname + path.sep) + chalk.bold(basename));
57
41
  }
58
42
 
59
43
  if (basenameLength + 4 === maxLength) {
60
- return (0, _slash.default)(_chalk.default.dim(`${TRIMMING_DOTS}${_path.default.sep}`) + _chalk.default.bold(basename));
44
+ return slash(chalk.dim(`${TRIMMING_DOTS}${path.sep}`) + chalk.bold(basename));
61
45
  } // can't fit dirname, but can fit trimmed basename
62
46
 
63
47
 
64
- return (0, _slash.default)(_chalk.default.bold(`${TRIMMING_DOTS}${basename.slice(-maxLength + 3)}`));
48
+ return slash(chalk.bold(`${TRIMMING_DOTS}${basename.slice(-maxLength + 3)}`));
65
49
  };
66
-
67
- exports.trimAndFormatPath = trimAndFormatPath;
68
-
69
- const getTerminalWidth = (pipe = process.stdout) => pipe.columns;
70
-
71
- exports.getTerminalWidth = getTerminalWidth;
72
-
73
- const highlight = (rawPath, filePath, pattern) => {
50
+ export const getTerminalWidth = (pipe = process.stdout) => pipe.columns;
51
+ export const highlight = (rawPath, filePath, pattern) => {
74
52
  const relativePathHead = './';
75
53
  let regexp;
76
54
 
77
55
  try {
78
56
  regexp = new RegExp(pattern, 'i');
79
57
  } catch (e) {
80
- return _chalk.default.dim(filePath);
58
+ return chalk.dim(filePath);
81
59
  }
82
60
 
83
- const strippedRawPath = (0, _stripAnsi.default)(rawPath);
84
- const strippedFilePath = (0, _stripAnsi.default)(filePath);
61
+ const strippedRawPath = stripAnsi(rawPath);
62
+ const strippedFilePath = stripAnsi(filePath);
85
63
  const match = strippedRawPath.match(regexp);
86
64
 
87
65
  if (!match || match.index == null) {
88
- return _chalk.default.dim(strippedFilePath);
66
+ return chalk.dim(strippedFilePath);
89
67
  }
90
68
 
91
- const offset = rawPath.length - filePath.length;
69
+ const offset = strippedRawPath.length - strippedFilePath.length;
92
70
  let trimLength;
93
71
 
94
72
  if (strippedFilePath.startsWith(TRIMMING_DOTS)) {
@@ -103,23 +81,20 @@ const highlight = (rawPath, filePath, pattern) => {
103
81
  const end = start + match[0].length;
104
82
  return colorize(strippedFilePath, Math.max(start, 0), Math.max(end, trimLength));
105
83
  };
106
-
107
- exports.highlight = highlight;
108
-
109
- const formatTestNameByPattern = (testName, pattern, width) => {
84
+ export const formatTestNameByPattern = (testName, pattern, width) => {
110
85
  const inlineTestName = testName.replace(/(\r\n|\n|\r)/gm, ENTER);
111
86
  let regexp;
112
87
 
113
88
  try {
114
89
  regexp = new RegExp(pattern, 'i');
115
90
  } catch (e) {
116
- return _chalk.default.dim(inlineTestName);
91
+ return chalk.dim(inlineTestName);
117
92
  }
118
93
 
119
94
  const match = inlineTestName.match(regexp);
120
95
 
121
96
  if (!match || match.index == null) {
122
- return _chalk.default.dim(inlineTestName);
97
+ return chalk.dim(inlineTestName);
123
98
  }
124
99
 
125
100
  const startPatternIndex = Math.max(match.index, 0);
@@ -142,15 +117,10 @@ const formatTestNameByPattern = (testName, pattern, width) => {
142
117
  const start = startPatternIndex - numberOfTruncatedChars;
143
118
  return colorize(TRIMMING_DOTS + truncatedTestName, start + TRIMMING_DOTS.length, end + TRIMMING_DOTS.length);
144
119
  };
145
-
146
- exports.formatTestNameByPattern = formatTestNameByPattern;
147
-
148
- const removeTrimmingDots = value => {
120
+ export const removeTrimmingDots = value => {
149
121
  if (value.startsWith(TRIMMING_DOTS)) {
150
122
  return value.slice(TRIMMING_DOTS.length);
151
123
  }
152
124
 
153
125
  return value;
154
- };
155
-
156
- exports.removeTrimmingDots = removeTrimmingDots;
126
+ };
@@ -1,17 +1,6 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _jestWatcher = require("jest-watcher");
9
-
10
- var _prompt = _interopRequireDefault(require("./prompt"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- class TestNamePlugin {
1
+ import { Prompt } from 'jest-watcher';
2
+ import TestNamePatternPrompt from "./prompt.js";
3
+ export default class TestNamePlugin {
15
4
  constructor({
16
5
  stdin,
17
6
  stdout,
@@ -19,7 +8,7 @@ class TestNamePlugin {
19
8
  }) {
20
9
  this._stdin = stdin;
21
10
  this._stdout = stdout;
22
- this._prompt = new _jestWatcher.Prompt();
11
+ this._prompt = new Prompt();
23
12
  this._testResults = [];
24
13
  this._usageInfo = {
25
14
  key: config.key || 't',
@@ -40,7 +29,7 @@ class TestNamePlugin {
40
29
  }
41
30
 
42
31
  run(globalConfig, updateConfigAndRun) {
43
- const p = new _prompt.default(this._stdout, this._prompt);
32
+ const p = new TestNamePatternPrompt(this._stdout, this._prompt);
44
33
  p.updateCachedTestResults(this._testResults);
45
34
  return new Promise((res, rej) => {
46
35
  p.run(testNamePattern => {
@@ -57,6 +46,4 @@ class TestNamePlugin {
57
46
  return this._usageInfo;
58
47
  }
59
48
 
60
- }
61
-
62
- exports.default = TestNamePlugin;
49
+ }
@@ -1,27 +1,11 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _chalk = _interopRequireDefault(require("chalk"));
9
-
10
- var _ansiEscapes = _interopRequireDefault(require("ansi-escapes"));
11
-
12
- var _jestWatcher = require("jest-watcher");
13
-
14
- var _jestRegexUtil = require("jest-regex-util");
15
-
16
- var _scroll = _interopRequireDefault(require("../lib/scroll"));
17
-
18
- var _utils = require("../lib/utils");
19
-
20
- var _pattern_mode_helpers = require("../lib/pattern_mode_helpers");
21
-
22
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
-
24
- class TestNamePatternPrompt extends _jestWatcher.PatternPrompt {
1
+ import chalk from 'chalk';
2
+ import ansiEscapes from 'ansi-escapes';
3
+ import { PatternPrompt, printPatternCaret, printRestoredPatternCaret } from 'jest-watcher';
4
+ import { escapeStrForRegex } from 'jest-regex-util';
5
+ import scroll from "../lib/scroll.js";
6
+ import { formatTestNameByPattern, getTerminalWidth, removeTrimmingDots } from "../lib/utils.js";
7
+ import { formatTypeaheadSelection, printMore, printPatternMatches, printStartTyping, printTypeaheadItem } from "../lib/pattern_mode_helpers.js";
8
+ export default class TestNamePatternPrompt extends PatternPrompt {
25
9
  constructor(pipe, prompt) {
26
10
  super(pipe, prompt);
27
11
  this._entityName = 'tests';
@@ -43,28 +27,28 @@ class TestNamePatternPrompt extends _jestWatcher.PatternPrompt {
43
27
  const total = matchedTests.length;
44
28
  const pipe = this._pipe;
45
29
  const prompt = this._prompt;
46
- (0, _jestWatcher.printPatternCaret)(pattern, pipe);
47
- pipe.write(_ansiEscapes.default.cursorLeft);
30
+ printPatternCaret(pattern, pipe);
31
+ pipe.write(ansiEscapes.cursorLeft);
48
32
 
49
33
  if (pattern) {
50
- (0, _pattern_mode_helpers.printPatternMatches)(total, 'test', pipe, ` from ${_chalk.default.yellow('cached')} test suites`);
51
- const width = (0, _utils.getTerminalWidth)(pipe);
34
+ printPatternMatches(total, 'test', pipe, ` from ${chalk.yellow('cached')} test suites`);
35
+ const width = getTerminalWidth(pipe);
52
36
  const {
53
37
  start,
54
38
  end,
55
39
  index
56
- } = (0, _scroll.default)(total, options);
40
+ } = scroll(total, options);
57
41
  prompt.setPromptLength(total);
58
- matchedTests.slice(start, end).map(name => (0, _utils.formatTestNameByPattern)(name, pattern, width - 4)).map((item, i) => (0, _pattern_mode_helpers.formatTypeaheadSelection)(item, i, index, prompt)).forEach(item => (0, _pattern_mode_helpers.printTypeaheadItem)(item, pipe));
42
+ matchedTests.slice(start, end).map(name => formatTestNameByPattern(name, pattern, width - 4)).map((item, i) => formatTypeaheadSelection(item, i, index, prompt)).forEach(item => printTypeaheadItem(item, pipe));
59
43
 
60
44
  if (total > end) {
61
- (0, _pattern_mode_helpers.printMore)('test', pipe, total - end);
45
+ printMore('test', pipe, total - end);
62
46
  }
63
47
  } else {
64
- (0, _pattern_mode_helpers.printStartTyping)('test name', pipe);
48
+ printStartTyping('test name', pipe);
65
49
  }
66
50
 
67
- (0, _jestWatcher.printRestoredPatternCaret)(pattern, this._currentUsageRows, pipe);
51
+ printRestoredPatternCaret(pattern, this._currentUsageRows, pipe);
68
52
  }
69
53
 
70
54
  _getMatchedTests(pattern) {
@@ -93,12 +77,10 @@ class TestNamePatternPrompt extends _jestWatcher.PatternPrompt {
93
77
 
94
78
  run(onSuccess, onCancel, options) {
95
79
  super.run(value => {
96
- const preparedPattern = (0, _jestRegexUtil.escapeStrForRegex)((0, _utils.removeTrimmingDots)(value));
80
+ const preparedPattern = escapeStrForRegex(removeTrimmingDots(value));
97
81
  const useExactMatch = this._offset !== -1;
98
82
  onSuccess(useExactMatch ? `^${preparedPattern}$` : preparedPattern);
99
83
  }, onCancel, options);
100
84
  }
101
85
 
102
- }
103
-
104
- exports.default = TestNamePatternPrompt;
86
+ }
@@ -1 +1 @@
1
- "use strict";
1
+ export {};
package/filename.js CHANGED
@@ -1,4 +1 @@
1
- // eslint-disable-next-line @typescript-eslint/no-var-requires
2
- const FileNamePlugin = require('./build/file_name_plugin/plugin').default;
3
-
4
- module.exports = FileNamePlugin;
1
+ export { default } from './build/file_name_plugin/plugin.js';
package/package.json CHANGED
@@ -1,7 +1,14 @@
1
1
  {
2
2
  "name": "jest-watch-typeahead",
3
- "version": "0.6.2",
3
+ "version": "1.0.0",
4
4
  "main": "build/index.js",
5
+ "exports": {
6
+ ".": "./build/index.js",
7
+ "./filename": "./build/file_name_plugin/plugin.js",
8
+ "./testname": "./build/test_name_plugin/plugin.js",
9
+ "./package.json": "./package.json"
10
+ },
11
+ "type": "module",
5
12
  "author": "Rogelio Guzman <rogelioguzmanh@gmail.com>",
6
13
  "description": "Jest plugin for filtering by filename or test name",
7
14
  "license": "MIT",
@@ -16,10 +23,10 @@
16
23
  "testname.js"
17
24
  ],
18
25
  "scripts": {
19
- "test": "jest",
26
+ "test": "cross-env NODE_OPTIONS=\"--experimental-vm-modules\" jest",
20
27
  "lint": "eslint .",
21
28
  "prebuild": "rimraf build",
22
- "build": "babel --extensions .js,.ts src -d build && rimraf **/*.test.{js,ts},integration",
29
+ "build": "babel --extensions .js,.ts src -d build && rimraf **/*.test.{js,ts},integration build/**/__tests__ build/test_utils",
23
30
  "prepublish": "yarn build",
24
31
  "format": "prettier --write \"**/*.js\" \"**/*.md\" \"**/*.ts\"",
25
32
  "typecheck": "yarn tsc -p ."
@@ -27,39 +34,48 @@
27
34
  "dependencies": {
28
35
  "ansi-escapes": "^4.3.1",
29
36
  "chalk": "^4.0.0",
30
- "jest-regex-util": "^26.0.0",
31
- "jest-watcher": "^26.3.0",
32
- "slash": "^3.0.0",
33
- "string-length": "^4.0.1",
34
- "strip-ansi": "^6.0.0"
37
+ "jest-regex-util": "^27.0.0",
38
+ "jest-watcher": "^27.0.0",
39
+ "slash": "^4.0.0",
40
+ "string-length": "^5.0.1",
41
+ "strip-ansi": "^7.0.1"
35
42
  },
36
43
  "devDependencies": {
37
44
  "@babel/cli": "^7.8.4",
38
45
  "@babel/core": "^7.9.6",
39
46
  "@babel/preset-env": "^7.9.6",
40
47
  "@babel/preset-typescript": "^7.10.4",
41
- "@jest/types": "^26.3.0",
42
- "@types/jest": "^26.0.13",
48
+ "@jest/globals": "^27.2.3",
49
+ "@jest/types": "^27.0.0",
50
+ "@semantic-release/changelog": "^5.0.1",
51
+ "@semantic-release/git": "^9.0.0",
52
+ "@types/jest": "^27.0.0",
43
53
  "@types/node": "^14.6.4",
44
54
  "@typescript-eslint/eslint-plugin": "^4.0.1",
45
55
  "@typescript-eslint/parser": "^4.0.1",
46
- "babel-eslint": "^10.1.0",
47
- "babel-jest": "^26.0.0",
56
+ "babel-jest": "^27.0.0",
57
+ "babel-plugin-add-import-extension": "^1.6.0",
58
+ "cross-env": "^7.0.3",
48
59
  "eslint": "^7.8.1",
49
60
  "eslint-config-airbnb-base": "^14.1.0",
50
- "eslint-config-prettier": "^6.11.0",
61
+ "eslint-config-prettier": "^8.0.0",
51
62
  "eslint-plugin-import": "^2.20.2",
52
63
  "eslint-plugin-jest": "^24.0.0",
53
- "eslint-plugin-prettier": "^3.1.3",
54
- "jest": "^26.0.0",
64
+ "eslint-plugin-prettier": "^4.0.0",
65
+ "jest": "^27.0.0",
55
66
  "prettier": "^2.1.1",
56
67
  "rimraf": "^3.0.2",
68
+ "semantic-release": "^17.4.3",
69
+ "semver": "^7.3.5",
57
70
  "typescript": "^4.0.2"
58
71
  },
59
72
  "peerDependencies": {
60
- "jest": "^26.0.0"
73
+ "jest": "^27.0.0"
61
74
  },
62
75
  "jest": {
76
+ "extensionsToTreatAsEsm": [
77
+ ".ts"
78
+ ],
63
79
  "watchPlugins": [
64
80
  "<rootDir>/filename",
65
81
  "<rootDir>/testname"
@@ -77,6 +93,23 @@
77
93
  ]
78
94
  },
79
95
  "engines": {
80
- "node": ">=10"
96
+ "node": "^12.22.0 || ^14.17.0 || >=16.0.0"
97
+ },
98
+ "resolutions": {
99
+ "semantic-release/@semantic-release/github/fs-extra": "^9.0.0",
100
+ "semantic-release/@semantic-release/npm/fs-extra": "^9.0.0"
101
+ },
102
+ "release": {
103
+ "branches": [
104
+ "main"
105
+ ],
106
+ "plugins": [
107
+ "@semantic-release/commit-analyzer",
108
+ "@semantic-release/release-notes-generator",
109
+ "@semantic-release/changelog",
110
+ "@semantic-release/npm",
111
+ "@semantic-release/git",
112
+ "@semantic-release/github"
113
+ ]
81
114
  }
82
115
  }
package/testname.js CHANGED
@@ -1,4 +1 @@
1
- // eslint-disable-next-line @typescript-eslint/no-var-requires
2
- const TestNamePlugin = require('./build/test_name_plugin/plugin').default;
3
-
4
- module.exports = TestNamePlugin;
1
+ export { default } from './build/test_name_plugin/plugin.js';
package/CHANGELOG.md DELETED
@@ -1,99 +0,0 @@
1
- ## 0.6.2
2
-
3
- ### Fixes
4
-
5
- - Use correct highlight offset even when rootDir is not root package directory ([#34](https://github.com/jest-community/jest-watch-typeahead/pull/34))
6
-
7
- ## 0.6.1
8
-
9
- ### Fixes
10
-
11
- - Provide exact pattern for selected test names
12
-
13
- ## 0.6.0
14
-
15
- ### Chore & Maintenance
16
-
17
- - Update dependencies and drop Node 8 ([#35](https://github.com/jest-community/jest-watch-typeahead/pull/35))
18
-
19
- ## 0.5.0
20
-
21
- ### Chore & Maintenance
22
-
23
- - Update dependencies
24
-
25
- ## 0.4.2
26
-
27
- ### Fixes
28
-
29
- - Fix issue with overly trimmed basenames when formatting test paths ([#33](https://github.com/jest-community/jest-watch-typeahead/pull/33))
30
-
31
- ## 0.4.1
32
-
33
- ### Fixes
34
-
35
- - Allow selecting tests and files containing regexp special characters ([#32](https://github.com/jest-community/jest-watch-typeahead/pull/32))
36
-
37
- ### Chore & Maintenance
38
-
39
- - Remove build directory before building ([#31](https://github.com/jest-community/jest-watch-typeahead/pull/31))
40
-
41
- ## 0.4.0
42
-
43
- ### Chore & Maintenance
44
-
45
- - Update dependencies and drop Node 6 ([#30](https://github.com/jest-community/jest-watch-typeahead/pull/30))
46
-
47
- ## 0.3.1
48
-
49
- ### Fixes
50
-
51
- - Helpful error message when attempting to use the package main file ([#29](https://github.com/jest-community/jest-watch-typeahead/pull/29))
52
-
53
- ## 0.3.0
54
-
55
- ### Chore & Maintenance
56
-
57
- - Bump dated dependencies ([#25](https://github.com/jest-community/jest-watch-typeahead/pull/25))
58
- - Get better truncation for testname typeahead by truncating the start and not the end ([#28](https://github.com/jest-community/jest-watch-typeahead/pull/28))
59
-
60
- ### Fixes
61
-
62
- - Use fullName(to show ancestor titles) for test name pattern plugin ([#26](https://github.com/jest-community/jest-watch-typeahead/pull/26))
63
-
64
- ## 0.2.1
65
-
66
- - Fix cursor in terminal app ([#21](https://github.com/jest-community/jest-watch-typeahead/pull/21))
67
-
68
- ### Chore & Maintenance
69
-
70
- - Bump dated dependencies ([#23](https://github.com/jest-community/jest-watch-typeahead/pull/23))
71
-
72
- ## 0.2.0
73
-
74
- ### Features
75
-
76
- - Add support for plugin config ([#13](https://github.com/jest-community/jest-watch-typeahead/pull/13))
77
-
78
- ### Fixes
79
-
80
- - Make matching case insensitive ([#18](https://github.com/jest-community/jest-watch-typeahead/pull/18))
81
- - fix: migrate to use jest-watcher ([#6](https://github.com/jest-community/jest-watch-typeahead/pull/6))
82
-
83
- ### Chore & Maintenance
84
-
85
- - Upgrade Prettier to 1.13.7 ([#17](https://github.com/jest-community/jest-watch-typeahead/pull/17))
86
- - New directory structure ([#14](https://github.com/jest-community/jest-watch-typeahead/pull/14))
87
- - Move ansi-escapes to dependencies _23f22d4_
88
- - Setup Travis and add tests ([#12](https://github.com/jest-community/jest-watch-typeahead/pull/12))
89
-
90
- ## 0.1.0
91
-
92
- ### Features
93
-
94
- - Add test name typeahead ([#1](https://github.com/jest-community/jest-watch-typeahead/pull/1))
95
- - Rename to jest-watch-typeahead
96
-
97
- ## 0.0.1
98
-
99
- Initial Release
@@ -1,162 +0,0 @@
1
- "use strict";
2
-
3
- var _jestWatcher = require("jest-watcher");
4
-
5
- var _pluginTester = _interopRequireDefault(require("../../test_utils/pluginTester"));
6
-
7
- var _plugin = _interopRequireDefault(require("../plugin"));
8
-
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
-
11
- const projects = [{
12
- config: {
13
- rootDir: '/project'
14
- },
15
- testPaths: ['/project/src/foo.js', '/project/src/file-1.js']
16
- }, {
17
- config: {
18
- rootDir: '/project'
19
- },
20
- testPaths: ['/project/src/bar.js', '/project/src/file-2.js']
21
- }];
22
- it('shows the correct initial state', async () => {
23
- const {
24
- stdout,
25
- hookEmitter,
26
- updateConfigAndRun,
27
- plugin,
28
- type
29
- } = (0, _pluginTester.default)(_plugin.default);
30
- hookEmitter.onFileChange({
31
- projects
32
- });
33
- const runPromise = plugin.run({}, updateConfigAndRun);
34
- expect(stdout.write.mock.calls.join('\n')).toMatchSnapshot();
35
- type(_jestWatcher.KEYS.ENTER);
36
- await runPromise;
37
- });
38
- it('can use arrows to select a specific file', async () => {
39
- const {
40
- stdout,
41
- hookEmitter,
42
- updateConfigAndRun,
43
- plugin,
44
- type
45
- } = (0, _pluginTester.default)(_plugin.default);
46
- hookEmitter.onFileChange({
47
- projects
48
- });
49
- const runPromise = plugin.run({}, updateConfigAndRun);
50
- stdout.write.mockReset();
51
- type('f', 'i', _jestWatcher.KEYS.ARROW_DOWN, _jestWatcher.KEYS.ENTER);
52
- expect(stdout.write.mock.calls.join('\n')).toMatchSnapshot();
53
- await runPromise;
54
- expect(updateConfigAndRun).toHaveBeenCalledWith({
55
- mode: 'watch',
56
- testPathPattern: 'src/file-1\\.js'
57
- });
58
- });
59
- it('can select a specific file that includes a regexp special character', async () => {
60
- const {
61
- hookEmitter,
62
- updateConfigAndRun,
63
- plugin,
64
- type
65
- } = (0, _pluginTester.default)(_plugin.default);
66
- hookEmitter.onFileChange({
67
- projects: [{
68
- config: {
69
- rootDir: '/project'
70
- },
71
- testPaths: ['/project/src/file_(xyz).js']
72
- }]
73
- });
74
- const runPromise = plugin.run({}, updateConfigAndRun);
75
- type('x', 'y', 'z', _jestWatcher.KEYS.ARROW_DOWN, _jestWatcher.KEYS.ENTER);
76
- await runPromise;
77
- expect(updateConfigAndRun).toHaveBeenCalledWith({
78
- mode: 'watch',
79
- testPathPattern: 'src/file_\\(xyz\\)\\.js'
80
- });
81
- });
82
- it('can select a pattern that matches multiple files', async () => {
83
- const {
84
- stdout,
85
- hookEmitter,
86
- updateConfigAndRun,
87
- plugin,
88
- type
89
- } = (0, _pluginTester.default)(_plugin.default);
90
- hookEmitter.onFileChange({
91
- projects
92
- });
93
- const runPromise = plugin.run({}, updateConfigAndRun);
94
- stdout.write.mockReset();
95
- type('f', 'i', _jestWatcher.KEYS.ENTER);
96
- expect(stdout.write.mock.calls.join('\n')).toMatchSnapshot();
97
- await runPromise;
98
- expect(updateConfigAndRun).toHaveBeenCalledWith({
99
- mode: 'watch',
100
- testPathPattern: 'fi'
101
- });
102
- });
103
- it('can configure the key and prompt', async () => {
104
- const {
105
- plugin
106
- } = (0, _pluginTester.default)(_plugin.default, {
107
- config: {
108
- key: 'l',
109
- prompt: 'have a custom prompt'
110
- }
111
- });
112
- expect(plugin.getUsageInfo()).toEqual({
113
- key: 'l',
114
- prompt: 'have a custom prompt'
115
- });
116
- });
117
- it('file matching is case insensitive', async () => {
118
- const {
119
- stdout,
120
- hookEmitter,
121
- updateConfigAndRun,
122
- plugin,
123
- type
124
- } = (0, _pluginTester.default)(_plugin.default);
125
- hookEmitter.onFileChange({
126
- projects
127
- });
128
- const runPromise = plugin.run({}, updateConfigAndRun);
129
- type('f');
130
- stdout.write.mockReset();
131
- type('I');
132
- expect(stdout.write.mock.calls.join('\n')).toMatchSnapshot();
133
- type(_jestWatcher.KEYS.ENTER);
134
- await runPromise;
135
- });
136
- it("selected file doesn't include trimming dots", async () => {
137
- const {
138
- hookEmitter,
139
- updateConfigAndRun,
140
- plugin,
141
- type
142
- } = (0, _pluginTester.default)(_plugin.default, {
143
- stdout: {
144
- columns: 40
145
- }
146
- });
147
- hookEmitter.onFileChange({
148
- projects: [{
149
- config: {
150
- rootDir: '/project'
151
- },
152
- testPaths: ['/project/src/long_name_gonna_need_trimming.js']
153
- }]
154
- });
155
- const runPromise = plugin.run({}, updateConfigAndRun);
156
- type('t', 'r', 'i', 'm', 'm', _jestWatcher.KEYS.ARROW_DOWN, _jestWatcher.KEYS.ENTER);
157
- await runPromise;
158
- expect(updateConfigAndRun).toHaveBeenCalledWith({
159
- mode: 'watch',
160
- testPathPattern: 'ong_name_gonna_need_trimming\\.js'
161
- });
162
- });
@@ -1,70 +0,0 @@
1
- "use strict";
2
-
3
- var _utils = require("../utils");
4
-
5
- jest.mock('chalk', () => {
6
- const chalk = jest.requireActual('chalk');
7
- return new chalk.Instance({
8
- enabled: true,
9
- level: 1
10
- });
11
- });
12
- describe('trimAndFormatPath', () => {
13
- test.each`
14
- testPath | pad | columns
15
- ${'/project/src/gonna/fit/all.js'} | ${6} | ${80}
16
- ${'/project/src/trimmed_dir/foo.js'} | ${6} | ${20}
17
- ${'/project/src/exactly/sep_and_basename.js'} | ${6} | ${29}
18
- ${'/project/src/long_name_gonna_need_trimming.js'} | ${6} | ${40}
19
- `('formats when testpath="$testPath", pad="$pad", and columns="$columns"', ({
20
- testPath,
21
- pad,
22
- columns
23
- }) => {
24
- expect((0, _utils.trimAndFormatPath)(pad, {
25
- rootDir: '/project'
26
- }, testPath, columns)).toMatchSnapshot();
27
- });
28
- });
29
- describe('formatTestNameByPattern', () => {
30
- test.each`
31
- testName | pattern | width
32
- ${'the test name'} | ${'the'} | ${30}
33
- ${'the test name'} | ${'the'} | ${25}
34
- ${'the test name'} | ${'the'} | ${20}
35
- ${'the test name'} | ${'the'} | ${15}
36
- ${'the test name'} | ${'the'} | ${10}
37
- ${'the test name'} | ${'the'} | ${5}
38
- ${'the test name'} | ${'test'} | ${30}
39
- ${'the test name'} | ${'test'} | ${25}
40
- ${'the test name'} | ${'test'} | ${20}
41
- ${'the test name'} | ${'test'} | ${15}
42
- ${'the test name'} | ${'test'} | ${10}
43
- ${'the test name'} | ${'test'} | ${5}
44
- ${'the test name'} | ${'name'} | ${30}
45
- ${'the test name'} | ${'name'} | ${25}
46
- ${'the test name'} | ${'name'} | ${20}
47
- ${'the test name'} | ${'name'} | ${15}
48
- ${'the test name'} | ${'name'} | ${10}
49
- ${'the test name'} | ${'name'} | ${5}
50
- `('formats when testname="$testName", pattern="$pattern", and width="$width"', ({
51
- testName,
52
- pattern,
53
- width
54
- }) => {
55
- expect((0, _utils.formatTestNameByPattern)(testName, pattern, width)).toMatchSnapshot();
56
- });
57
- });
58
- describe('highlight', () => {
59
- const rawPath = '/Users/janedoe/monorepo/libs/utils/src/__tests__/hello-world.js';
60
- const pattern = 'hello';
61
- test.each`
62
- filePath
63
- ${'libs/utils/src/__tests__/hello-world.js'}
64
- ${'...s/utils/src/__tests__/hello-world.js'}
65
- `(`highlights match correctly when filePath="$filePath"`, ({
66
- filePath
67
- }) => {
68
- expect((0, _utils.highlight)(rawPath, filePath, pattern)).toMatchSnapshot();
69
- });
70
- });
@@ -1,197 +0,0 @@
1
- "use strict";
2
-
3
- var _jestWatcher = require("jest-watcher");
4
-
5
- var _pluginTester = _interopRequireDefault(require("../../test_utils/pluginTester"));
6
-
7
- var _plugin = _interopRequireDefault(require("../plugin"));
8
-
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
-
11
- const testResults = [{
12
- testResults: [{
13
- title: 'foo 1',
14
- fullName: 'some description foo 1'
15
- }, {
16
- title: 'bar 1',
17
- fullName: 'some description bar 1'
18
- }]
19
- }, {
20
- testResults: [{
21
- title: 'foo 2',
22
- fullName: 'other description foo 2'
23
- }, {
24
- title: 'bar 2',
25
- fullName: 'other description bar 2'
26
- }]
27
- }];
28
- it('shows the correct initial state', async () => {
29
- const {
30
- stdout,
31
- updateConfigAndRun,
32
- plugin,
33
- type
34
- } = (0, _pluginTester.default)(_plugin.default);
35
- const runPromise = plugin.run({}, updateConfigAndRun);
36
- expect(stdout.write.mock.calls.join('\n')).toMatchSnapshot();
37
- type(_jestWatcher.KEYS.ENTER);
38
- await runPromise;
39
- });
40
- it('shows the correct message when there are no cached tests', async () => {
41
- const {
42
- stdout,
43
- updateConfigAndRun,
44
- plugin,
45
- type
46
- } = (0, _pluginTester.default)(_plugin.default);
47
- const runPromise = plugin.run({}, updateConfigAndRun);
48
- expect(stdout.write.mock.calls.join('\n')).toMatchSnapshot();
49
- type('t', _jestWatcher.KEYS.ENTER);
50
- await runPromise;
51
- });
52
- it('can use arrows to select a specific test', async () => {
53
- const {
54
- stdout,
55
- hookEmitter,
56
- updateConfigAndRun,
57
- plugin,
58
- type
59
- } = (0, _pluginTester.default)(_plugin.default);
60
- hookEmitter.onTestRunComplete({
61
- testResults
62
- });
63
- const runPromise = plugin.run({}, updateConfigAndRun);
64
- stdout.write.mockReset();
65
- type('f', _jestWatcher.KEYS.ARROW_DOWN, _jestWatcher.KEYS.ARROW_DOWN, _jestWatcher.KEYS.ENTER);
66
- expect(stdout.write.mock.calls.join('\n')).toMatchSnapshot();
67
- await runPromise;
68
- expect(updateConfigAndRun).toHaveBeenCalledWith({
69
- mode: 'watch',
70
- testNamePattern: '^other description foo 2$'
71
- });
72
- });
73
- it('can select a pattern that matches multiple tests', async () => {
74
- const {
75
- stdout,
76
- hookEmitter,
77
- updateConfigAndRun,
78
- plugin,
79
- type
80
- } = (0, _pluginTester.default)(_plugin.default);
81
- hookEmitter.onTestRunComplete({
82
- testResults
83
- });
84
- const runPromise = plugin.run({}, updateConfigAndRun);
85
- stdout.write.mockReset();
86
- type('f', 'o', _jestWatcher.KEYS.ENTER);
87
- expect(stdout.write.mock.calls.join('\n')).toMatchSnapshot();
88
- await runPromise;
89
- expect(updateConfigAndRun).toHaveBeenCalledWith({
90
- mode: 'watch',
91
- testNamePattern: 'fo'
92
- });
93
- });
94
- it('can select a pattern that matches a describe block', async () => {
95
- const {
96
- stdout,
97
- hookEmitter,
98
- updateConfigAndRun,
99
- plugin,
100
- type
101
- } = (0, _pluginTester.default)(_plugin.default);
102
- hookEmitter.onTestRunComplete({
103
- testResults
104
- });
105
- const runPromise = plugin.run({}, updateConfigAndRun);
106
- stdout.write.mockReset();
107
- type('s', 'o', _jestWatcher.KEYS.ENTER);
108
- expect(stdout.write.mock.calls.join('\n')).toMatchSnapshot();
109
- await runPromise;
110
- expect(updateConfigAndRun).toHaveBeenCalledWith({
111
- mode: 'watch',
112
- testNamePattern: 'so'
113
- });
114
- });
115
- it('can select a pattern that includes a regexp special character', async () => {
116
- const {
117
- hookEmitter,
118
- updateConfigAndRun,
119
- plugin,
120
- type
121
- } = (0, _pluginTester.default)(_plugin.default);
122
- hookEmitter.onTestRunComplete({
123
- testResults: [{
124
- testResults: [{
125
- title: 'bracket',
126
- fullName: 'bracket description (foo)'
127
- }]
128
- }]
129
- });
130
- const runPromise = plugin.run({}, updateConfigAndRun);
131
- type('b', 'r', _jestWatcher.KEYS.ARROW_DOWN, _jestWatcher.KEYS.ENTER);
132
- await runPromise;
133
- expect(updateConfigAndRun).toHaveBeenCalledWith({
134
- mode: 'watch',
135
- testNamePattern: '^bracket description \\(foo\\)$'
136
- });
137
- });
138
- it('can configure the key and prompt', async () => {
139
- const {
140
- plugin
141
- } = (0, _pluginTester.default)(_plugin.default, {
142
- config: {
143
- key: 'l',
144
- prompt: 'have a custom prompt'
145
- }
146
- });
147
- expect(plugin.getUsageInfo()).toEqual({
148
- key: 'l',
149
- prompt: 'have a custom prompt'
150
- });
151
- });
152
- it('test matching is case insensitive', async () => {
153
- const {
154
- stdout,
155
- hookEmitter,
156
- updateConfigAndRun,
157
- plugin,
158
- type
159
- } = (0, _pluginTester.default)(_plugin.default);
160
- hookEmitter.onTestRunComplete({
161
- testResults
162
- });
163
- const runPromise = plugin.run({}, updateConfigAndRun);
164
- type('f');
165
- stdout.write.mockReset();
166
- type('O');
167
- expect(stdout.write.mock.calls.join('\n')).toMatchSnapshot();
168
- type(_jestWatcher.KEYS.ENTER);
169
- await runPromise;
170
- });
171
- it("selected pattern doesn't include trimming dots", async () => {
172
- const {
173
- hookEmitter,
174
- updateConfigAndRun,
175
- plugin,
176
- type
177
- } = (0, _pluginTester.default)(_plugin.default, {
178
- stdout: {
179
- columns: 30
180
- }
181
- });
182
- hookEmitter.onTestRunComplete({
183
- testResults: [{
184
- testResults: [{
185
- title: 'trimmed long',
186
- fullName: 'long test name, gonna need trimming'
187
- }]
188
- }]
189
- });
190
- const runPromise = plugin.run({}, updateConfigAndRun);
191
- type('t', 'r', 'i', 'm', 'm', _jestWatcher.KEYS.ARROW_DOWN, _jestWatcher.KEYS.ENTER);
192
- await runPromise;
193
- expect(updateConfigAndRun).toHaveBeenCalledWith({
194
- mode: 'watch',
195
- testNamePattern: '^me, gonna need trimming$'
196
- });
197
- });
@@ -1,59 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = pluginTester;
7
-
8
- var _jestWatcher = require("jest-watcher");
9
-
10
- var _stripAnsi = _interopRequireDefault(require("strip-ansi"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- expect.addSnapshotSerializer({
15
- test: val => typeof val === 'string',
16
- print: val => (0, _stripAnsi.default)(val)
17
- });
18
- /**
19
- * See https://github.com/facebook/jest/pull/7523 for more details
20
- */
21
-
22
- const CLEAR = '\x1B[2J\x1B[3J\x1B[H';
23
- expect.addSnapshotSerializer({
24
- test: val => val.includes(CLEAR),
25
- print: val => (0, _stripAnsi.default)(val.replace(CLEAR, '[MOCK - clear]'))
26
- });
27
- /**
28
- * See https://github.com/facebook/jest/pull/7523 for more details
29
- */
30
-
31
- const WINDOWS_CLEAR = '\x1B[2J\x1B[0f';
32
- expect.addSnapshotSerializer({
33
- test: val => val.includes(WINDOWS_CLEAR),
34
- print: val => (0, _stripAnsi.default)(val.replace(WINDOWS_CLEAR, '[MOCK - clear]'))
35
- });
36
-
37
- function pluginTester(Plugin, options = {}) {
38
- const stdout = {
39
- columns: (options.stdout || {}).columns || 80,
40
- write: jest.fn()
41
- };
42
- const jestHooks = new _jestWatcher.JestHook();
43
- const plugin = new Plugin({
44
- stdout,
45
- stdin: process.stdin,
46
- config: options.config
47
- });
48
- plugin.apply(jestHooks.getSubscriber());
49
-
50
- const type = (...keys) => keys.forEach(key => plugin.onKey(key));
51
-
52
- return {
53
- stdout,
54
- hookEmitter: jestHooks.getEmitter(),
55
- updateConfigAndRun: jest.fn(),
56
- plugin,
57
- type
58
- };
59
- }