Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: migrate jest-watcher to TypeScript #7843

Merged
merged 4 commits into from
Feb 10, 2019
Merged

Conversation

SimenB
Copy link
Member

@SimenB SimenB commented Feb 9, 2019

Summary

I somehow missed that this depends on jest-util, so there's a @ts-ignore in here 😅

Built diff:

diff --git c/packages/jest-watcher/build/BaseWatchPlugin.js w/packages/jest-watcher/build/BaseWatchPlugin.js
index cab7c44f2..44acd23fc 100644
--- c/packages/jest-watcher/build/BaseWatchPlugin.js
+++ w/packages/jest-watcher/build/BaseWatchPlugin.js
@@ -10,8 +10,6 @@ exports.default = void 0;
  *
  * This source code is licensed under the MIT license found in the
  * LICENSE file in the root directory of this source tree.
- *
- *
  */
 class BaseWatchPlugin {
   constructor({stdin, stdout}) {
@@ -19,15 +17,15 @@ class BaseWatchPlugin {
     this._stdout = stdout;
   }
 
-  apply(hooks) {}
+  apply() {}
 
-  getUsageInfo(globalConfig) {
+  getUsageInfo() {
     return null;
   }
 
-  onKey(value) {}
+  onKey() {}
 
-  run(globalConfig, updateConfigAndRun) {
+  run() {
     return Promise.resolve();
   }
 }
diff --git c/packages/jest-watcher/build/JestHooks.js w/packages/jest-watcher/build/JestHooks.js
index d1523a1ae..edcc03c72 100644
--- c/packages/jest-watcher/build/JestHooks.js
+++ w/packages/jest-watcher/build/JestHooks.js
@@ -42,8 +42,6 @@ function _asyncToGenerator(fn) {
  *
  * This source code is licensed under the MIT license found in the
  * LICENSE file in the root directory of this source tree.
- *
- *
  */
 class JestHooks {
   constructor() {
@@ -84,13 +82,12 @@ class JestHooks {
         ),
       shouldRunTestSuite: (function() {
         var _shouldRunTestSuite = _asyncToGenerator(function*(testSuiteInfo) {
-          return Promise.all(
+          const result = yield Promise.all(
             _this._listeners.shouldRunTestSuite.map(listener =>
               listener(testSuiteInfo)
             )
-          ).then(result =>
-            result.every(shouldRunTestSuite => shouldRunTestSuite)
           );
+          return result.every(shouldRunTestSuite => shouldRunTestSuite);
         });
 
         function shouldRunTestSuite(_x) {
diff --git c/packages/jest-watcher/build/PatternPrompt.js w/packages/jest-watcher/build/PatternPrompt.js
index a69f073c3..30dd061c2 100644
--- c/packages/jest-watcher/build/PatternPrompt.js
+++ w/packages/jest-watcher/build/PatternPrompt.js
@@ -1,11 +1,3 @@
-/**
- * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- *
- *
- */
 'use strict';
 
 Object.defineProperty(exports, '__esModule', {
@@ -43,12 +35,17 @@ function _jestUtil() {
   return data;
 }
 
-var _Prompt = _interopRequireDefault(require('./lib/Prompt'));
-
 function _interopRequireDefault(obj) {
   return obj && obj.__esModule ? obj : {default: obj};
 }
 
+/**
+ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
+ *
+ * This source code is licensed under the MIT license found in the
+ * LICENSE file in the root directory of this source tree.
+ */
+// @ts-ignore: Not yet migrated
 const CLEAR = _jestUtil().specialChars.CLEAR;
 
 const usage = entity =>
@@ -64,6 +61,8 @@ const usageRows = usage('').split('\n').length;
 
 class PatternPrompt {
   constructor(pipe, prompt) {
+    // TODO: Should come in the constructor
+    this._entityName = '';
     this._pipe = pipe;
     this._prompt = prompt;
     this._currentUsageRows = usageRows;
@@ -89,7 +88,7 @@ class PatternPrompt {
     this._prompt.enter(this._onChange.bind(this), onSuccess, onCancel);
   }
 
-  _onChange(pattern, options) {
+  _onChange() {
     this._pipe.write(_ansiEscapes().default.eraseLine);
 
     this._pipe.write(_ansiEscapes().default.cursorLeft);
diff --git c/packages/jest-watcher/build/constants.js w/packages/jest-watcher/build/constants.js
index a619cb776..97b0bdd7b 100644
--- c/packages/jest-watcher/build/constants.js
+++ w/packages/jest-watcher/build/constants.js
@@ -10,8 +10,6 @@ exports.KEYS = void 0;
  *
  * This source code is licensed under the MIT license found in the
  * LICENSE file in the root directory of this source tree.
- *
- *
  */
 const isWindows = process.platform === 'win32';
 const KEYS = {
diff --git c/packages/jest-watcher/build/lib/Prompt.js w/packages/jest-watcher/build/lib/Prompt.js
index e190653d6..4402fb89e 100644
--- c/packages/jest-watcher/build/lib/Prompt.js
+++ w/packages/jest-watcher/build/lib/Prompt.js
@@ -12,16 +12,27 @@ var _constants = require('../constants');
  *
  * This source code is licensed under the MIT license found in the
  * LICENSE file in the root directory of this source tree.
- *
- *
  */
 class Prompt {
   constructor() {
+    // Copied from `enter` to satisfy TS
+    this._entering = true;
+    this._value = '';
+    this._selection = null;
+    this._offset = -1;
+    this._promptLength = 0;
+
+    this._onChange = () => {};
+
+    this._onSuccess = () => {};
+
+    this._onCancel = () => {};
+
     this._onResize = this._onResize.bind(this);
   }
 
   _onResize() {
-    this._onChange(this._value);
+    this._onChange();
   }
 
   enter(onChange, onSuccess, onCancel) {
diff --git c/packages/jest-watcher/build/lib/colorize.js w/packages/jest-watcher/build/lib/colorize.js
index fd523c4d9..7562424e4 100644
--- c/packages/jest-watcher/build/lib/colorize.js
+++ w/packages/jest-watcher/build/lib/colorize.js
@@ -24,8 +24,6 @@ function _interopRequireDefault(obj) {
  *
  * This source code is licensed under the MIT license found in the
  * LICENSE file in the root directory of this source tree.
- *
- *
  */
 var _default = (str, start, end) =>
   _chalk().default.dim(str.slice(0, start)) +
diff --git c/packages/jest-watcher/build/lib/formatTestNameByPattern.js w/packages/jest-watcher/build/lib/formatTestNameByPattern.js
index 7c8703a6a..07219c388 100644
--- c/packages/jest-watcher/build/lib/formatTestNameByPattern.js
+++ w/packages/jest-watcher/build/lib/formatTestNameByPattern.js
@@ -26,8 +26,6 @@ function _interopRequireDefault(obj) {
  *
  * This source code is licensed under the MIT license found in the
  * LICENSE file in the root directory of this source tree.
- *
- *
  */
 const DOTS = '...';
 const ENTER = '⏎';
@@ -48,7 +46,7 @@ var _default = (testName, pattern, width) => {
     return _chalk().default.dim(inlineTestName);
   }
 
-  const startPatternIndex = Math.max(match.index, 0);
+  const startPatternIndex = Math.max(match.index || 0, 0);
   const endPatternIndex = startPatternIndex + match[0].length;
 
   if (inlineTestName.length <= width) {
diff --git c/packages/jest-watcher/build/lib/patternModeHelpers.js w/packages/jest-watcher/build/lib/patternModeHelpers.js
index 0b159d018..13bbfb209 100644
--- c/packages/jest-watcher/build/lib/patternModeHelpers.js
+++ w/packages/jest-watcher/build/lib/patternModeHelpers.js
@@ -1,11 +1,3 @@
-/**
- * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- *
- *
- */
 'use strict';
 
 Object.defineProperty(exports, '__esModule', {
@@ -47,6 +39,12 @@ function _interopRequireDefault(obj) {
   return obj && obj.__esModule ? obj : {default: obj};
 }
 
+/**
+ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
+ *
+ * This source code is licensed under the MIT license found in the
+ * LICENSE file in the root directory of this source tree.
+ */
 const printPatternCaret = (pattern, pipe) => {
   const inputText = `${_chalk().default.dim(' pattern \u203A')} ${pattern}`;
   pipe.write(_ansiEscapes().default.eraseDown);
diff --git c/packages/jest-watcher/build/lib/scroll.js w/packages/jest-watcher/build/lib/scroll.js
index b8413de02..4a545041e 100644
--- c/packages/jest-watcher/build/lib/scroll.js
+++ w/packages/jest-watcher/build/lib/scroll.js
@@ -1,11 +1,3 @@
-/**
- * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- *
- *
- */
 'use strict';
 
 Object.defineProperty(exports, '__esModule', {
@@ -13,6 +5,12 @@ Object.defineProperty(exports, '__esModule', {
 });
 exports.default = scroll;
 
+/**
+ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
+ *
+ * This source code is licensed under the MIT license found in the
+ * LICENSE file in the root directory of this source tree.
+ */
 function scroll(size, {offset, max}) {
   let start = 0;
   let index = Math.min(offset, size);

Test plan

Green CI

prompt: string;
};

export type AllowedConfigOptions = Partial<
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, as I look a this, they're actually wrong. I took my list from the docs, but this is longer than that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codecov-io
Copy link

Codecov Report

Merging #7843 into master will increase coverage by 0.19%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #7843      +/-   ##
==========================================
+ Coverage   64.36%   64.55%   +0.19%     
==========================================
  Files         228      219       -9     
  Lines        8485     8370     -115     
  Branches        5        6       +1     
==========================================
- Hits         5461     5403      -58     
+ Misses       3022     2965      -57     
  Partials        2        2
Impacted Files Coverage Δ
packages/jest-cli/src/lib/update_global_config.js 93.75% <ø> (ø) ⬆️
packages/jest-runner/src/runTest.js 2.73% <ø> (ø) ⬆️
packages/jest-cli/src/plugins/quit.js 42.85% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dc35500...9950466. Read the comment docs.

packages/jest-watcher/src/JestHooks.ts Outdated Show resolved Hide resolved
packages/jest-watcher/src/lib/Prompt.ts Show resolved Hide resolved
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants