jest-watch-typeahead 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,9 +1,8 @@
1
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)
2
2
 
3
3
  <div align="center">
4
- <!-- replace with accurate logo e.g from https://worldvectorlogo.com/ -->
5
- <a href="https://facebook.github.io/jest/">
6
- <img width="150" height="150" vspace="" hspace="25" src="https://cdn.worldvectorlogo.com/logos/jest.svg">
4
+ <a href="https://jestjs.io/">
5
+ <img width="150" height="150" vspace="" hspace="25" src="https://jestjs.io/img/jest.png">
7
6
  </a>
8
7
  <h1>jest-watch-typeahead</h1>
9
8
  <p>Filter your tests by file name or test name</p>
@@ -15,7 +14,7 @@
15
14
 
16
15
  ### Install
17
16
 
18
- Install `jest`_(it needs Jest 23+)_ and `jest-watch-typeahead`
17
+ Install `jest`_(it needs Jest 26+)_ and `jest-watch-typeahead`
19
18
 
20
19
  ```bash
21
20
  yarn add --dev jest jest-watch-typeahead
@@ -2,8 +2,12 @@
2
2
 
3
3
  var _jestWatcher = require("jest-watcher");
4
4
 
5
+ var _jestRegexUtil = require("jest-regex-util");
6
+
5
7
  var _prompt = _interopRequireDefault(require("./prompt"));
6
8
 
9
+ var _utils = require("../lib/utils");
10
+
7
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
12
 
9
13
  class FileNamePlugin {
@@ -41,7 +45,7 @@ class FileNamePlugin {
41
45
  p.run(value => {
42
46
  updateConfigAndRun({
43
47
  mode: 'watch',
44
- testPathPattern: value
48
+ testPathPattern: (0, _utils.removeTrimmingDots)(value).split('/').map(_jestRegexUtil.escapeStrForRegex).join('/')
45
49
  });
46
50
  res();
47
51
  }, rej);
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.formatTestNameByPattern = exports.highlight = exports.getTerminalWidth = exports.trimAndFormatPath = void 0;
6
+ exports.removeTrimmingDots = exports.formatTestNameByPattern = exports.highlight = exports.getTerminalWidth = exports.trimAndFormatPath = void 0;
7
7
 
8
8
  var _path = _interopRequireDefault(require("path"));
9
9
 
@@ -16,6 +16,9 @@ var _stripAnsi = _interopRequireDefault(require("strip-ansi"));
16
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
17
 
18
18
  /* eslint-disable no-param-reassign */
19
+ const TRIMMING_DOTS = '...';
20
+ const ENTER = '⏎';
21
+
19
22
  const relativePath = (config, testPath) => {
20
23
  testPath = _path.default.relative(config.cwd || config.rootDir, testPath);
21
24
 
@@ -46,16 +49,16 @@ const trimAndFormatPath = (pad, config, testPath, columns) => {
46
49
 
47
50
  if (basenameLength + 4 < maxLength) {
48
51
  const dirnameLength = maxLength - 4 - basenameLength;
49
- dirname = `...${dirname.slice(dirname.length - dirnameLength, dirname.length)}`;
52
+ dirname = `${TRIMMING_DOTS}${dirname.slice(dirname.length - dirnameLength, dirname.length)}`;
50
53
  return (0, _slash.default)(_chalk.default.dim(dirname + _path.default.sep) + _chalk.default.bold(basename));
51
54
  }
52
55
 
53
56
  if (basenameLength + 4 === maxLength) {
54
- return (0, _slash.default)(_chalk.default.dim(`...${_path.default.sep}`) + _chalk.default.bold(basename));
57
+ return (0, _slash.default)(_chalk.default.dim(`${TRIMMING_DOTS}${_path.default.sep}`) + _chalk.default.bold(basename));
55
58
  } // can't fit dirname, but can fit trimmed basename
56
59
 
57
60
 
58
- return (0, _slash.default)(_chalk.default.bold(`...${basename.slice(basename.length - maxLength - 4, basename.length)}`));
61
+ return (0, _slash.default)(_chalk.default.bold(`${TRIMMING_DOTS}${basename.slice(-maxLength + 3)}`));
59
62
  };
60
63
 
61
64
  exports.trimAndFormatPath = trimAndFormatPath;
@@ -65,7 +68,6 @@ const getTerminalWidth = (pipe = process.stdout) => pipe.columns;
65
68
  exports.getTerminalWidth = getTerminalWidth;
66
69
 
67
70
  const highlight = (rawPath, filePath, pattern, rootDir) => {
68
- const trim = '...';
69
71
  const relativePathHead = './';
70
72
  let regexp;
71
73
 
@@ -86,9 +88,9 @@ const highlight = (rawPath, filePath, pattern, rootDir) => {
86
88
  let offset;
87
89
  let trimLength;
88
90
 
89
- if (filePath.startsWith(trim)) {
91
+ if (filePath.startsWith(TRIMMING_DOTS)) {
90
92
  offset = rawPath.length - filePath.length;
91
- trimLength = trim.length;
93
+ trimLength = TRIMMING_DOTS.length;
92
94
  } else if (filePath.startsWith(relativePathHead)) {
93
95
  offset = rawPath.length - filePath.length;
94
96
  trimLength = relativePathHead.length;
@@ -103,8 +105,6 @@ const highlight = (rawPath, filePath, pattern, rootDir) => {
103
105
  };
104
106
 
105
107
  exports.highlight = highlight;
106
- const DOTS = '...';
107
- const ENTER = '⏎';
108
108
 
109
109
  const formatTestNameByPattern = (testName, pattern, width) => {
110
110
  const inlineTestName = testName.replace(/(\r\n|\n|\r)/gm, ENTER);
@@ -131,17 +131,27 @@ const formatTestNameByPattern = (testName, pattern, width) => {
131
131
  return colorize(inlineTestName, startPatternIndex, endPatternIndex);
132
132
  }
133
133
 
134
- const numberOfTruncatedChars = DOTS.length + inlineTestName.length - width;
134
+ const numberOfTruncatedChars = TRIMMING_DOTS.length + inlineTestName.length - width;
135
135
  const end = Math.max(endPatternIndex - numberOfTruncatedChars, 0);
136
136
  const truncatedTestName = inlineTestName.slice(numberOfTruncatedChars);
137
137
  const shouldHighlightDots = startPatternIndex <= numberOfTruncatedChars;
138
138
 
139
139
  if (shouldHighlightDots) {
140
- return colorize(DOTS + truncatedTestName, 0, end + DOTS.length);
140
+ return colorize(TRIMMING_DOTS + truncatedTestName, 0, end + TRIMMING_DOTS.length);
141
141
  }
142
142
 
143
143
  const start = startPatternIndex - numberOfTruncatedChars;
144
- return colorize(DOTS + truncatedTestName, start + DOTS.length, end + DOTS.length);
144
+ return colorize(TRIMMING_DOTS + truncatedTestName, start + TRIMMING_DOTS.length, end + TRIMMING_DOTS.length);
145
+ };
146
+
147
+ exports.formatTestNameByPattern = formatTestNameByPattern;
148
+
149
+ const removeTrimmingDots = value => {
150
+ if (value.startsWith(TRIMMING_DOTS)) {
151
+ return value.slice(TRIMMING_DOTS.length);
152
+ }
153
+
154
+ return value;
145
155
  };
146
156
 
147
- exports.formatTestNameByPattern = formatTestNameByPattern;
157
+ exports.removeTrimmingDots = removeTrimmingDots;
@@ -2,8 +2,12 @@
2
2
 
3
3
  var _jestWatcher = require("jest-watcher");
4
4
 
5
+ var _jestRegexUtil = require("jest-regex-util");
6
+
5
7
  var _prompt = _interopRequireDefault(require("./prompt"));
6
8
 
9
+ var _utils = require("../lib/utils");
10
+
7
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
12
 
9
13
  class TestNamePlugin {
@@ -41,7 +45,7 @@ class TestNamePlugin {
41
45
  p.run(value => {
42
46
  updateConfigAndRun({
43
47
  mode: 'watch',
44
- testNamePattern: value
48
+ testNamePattern: (0, _jestRegexUtil.escapeStrForRegex)((0, _utils.removeTrimmingDots)(value))
45
49
  });
46
50
  res();
47
51
  }, rej);
@@ -34,15 +34,15 @@ expect.addSnapshotSerializer({
34
34
  print: val => (0, _stripAnsi.default)(val.replace(WINDOWS_CLEAR, '[MOCK - clear]'))
35
35
  });
36
36
 
37
- const pluginTester = (Plugin, config = {}) => {
37
+ const pluginTester = (Plugin, options = {}) => {
38
38
  const stdout = {
39
- columns: 80,
39
+ columns: (options.stdout || {}).columns || 80,
40
40
  write: jest.fn()
41
41
  };
42
42
  const jestHooks = new _jestWatcher.JestHook();
43
43
  const plugin = new Plugin({
44
44
  stdout,
45
- config
45
+ config: options.config
46
46
  });
47
47
  plugin.apply(jestHooks.getSubscriber());
48
48
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jest-watch-typeahead",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "main": "build/index.js",
5
5
  "author": "Rogelio Guzman <rogelioguzmanh@gmail.com>",
6
6
  "description": "Jest plugin for filtering by filename or test name",
@@ -19,36 +19,41 @@
19
19
  "test": "jest",
20
20
  "lint": "eslint .",
21
21
  "watch": "babel src -w --ignore **/*.test.js,integration -d build",
22
+ "prebuild": "rimraf build",
22
23
  "build": "babel src --ignore **/*.test.js,integration -d build",
23
24
  "prepublish": "yarn build",
24
- "format": "prettier --single-quote --trailing-comma all --write \"!(build)/**/*.js\""
25
+ "format": "prettier --write \"**/*.js\""
25
26
  },
26
27
  "dependencies": {
27
- "ansi-escapes": "^4.2.1",
28
- "chalk": "^2.4.1",
29
- "jest-watcher": "^24.3.0",
28
+ "ansi-escapes": "^4.3.1",
29
+ "chalk": "^4.0.0",
30
+ "jest-regex-util": "^26.0.0",
31
+ "jest-watcher": "^26.0.0",
30
32
  "slash": "^3.0.0",
31
- "string-length": "^3.1.0",
32
- "strip-ansi": "^5.0.0"
33
+ "string-length": "^4.0.1",
34
+ "strip-ansi": "^6.0.0"
33
35
  },
34
36
  "devDependencies": {
35
- "@babel/cli": "^7.0.0",
36
- "@babel/core": "^7.0.0",
37
- "@babel/preset-env": "^7.0.0",
38
- "@babel/preset-flow": "^7.0.0",
39
- "babel-core": "^7.0.0-bridge.0",
40
- "babel-eslint": "^10.0.1",
41
- "babel-jest": "^24.3.0",
42
- "eslint": "^6.2.0",
43
- "eslint-config-airbnb-base": "^14.0.0",
44
- "eslint-config-prettier": "^6.1.0",
45
- "eslint-plugin-flowtype": "^4.2.0",
46
- "eslint-plugin-import": "^2.9.0",
47
- "eslint-plugin-jest": "^22.1.3",
48
- "eslint-plugin-prettier": "^3.0.1",
49
- "flow-bin": "^0.105.2",
50
- "jest": "^24.3.0",
51
- "prettier": "^1.13.7"
37
+ "@babel/cli": "^7.8.4",
38
+ "@babel/core": "^7.9.6",
39
+ "@babel/preset-env": "^7.9.6",
40
+ "@babel/preset-flow": "^7.9.0",
41
+ "babel-eslint": "^10.1.0",
42
+ "babel-jest": "^26.0.0",
43
+ "eslint": "^6.8.0",
44
+ "eslint-config-airbnb-base": "^14.1.0",
45
+ "eslint-config-prettier": "^6.11.0",
46
+ "eslint-plugin-flowtype": "^4.7.0",
47
+ "eslint-plugin-import": "^2.20.2",
48
+ "eslint-plugin-jest": "^23.9.0",
49
+ "eslint-plugin-prettier": "^3.1.3",
50
+ "flow-bin": "^0.123.0",
51
+ "jest": "^26.0.0",
52
+ "prettier": "2.0.5",
53
+ "rimraf": "^3.0.2"
54
+ },
55
+ "peerDependencies": {
56
+ "jest": "^26.0.0"
52
57
  },
53
58
  "jest": {
54
59
  "watchPlugins": [
@@ -66,5 +71,8 @@
66
71
  "/node_modules/",
67
72
  "/__mocks__/"
68
73
  ]
74
+ },
75
+ "engines": {
76
+ "node": ">=10"
69
77
  }
70
78
  }