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-cli to TypeScript #8024

Merged
merged 15 commits into from Mar 5, 2019
Merged

Conversation

SimenB
Copy link
Member

@SimenB SimenB commented Mar 2, 2019

Summary

I don't think the yargs part is typed correctly... Halp?

Built diff:

diff --git c/packages/jest-cli/build/cli/args.js w/packages/jest-cli/build/cli/args.js
index d7f22cc35..6cadf3e70 100644
--- c/packages/jest-cli/build/cli/args.js
+++ w/packages/jest-cli/build/cli/args.js
@@ -34,8 +34,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 check = argv => {
   if (argv.runInBand && argv.hasOwnProperty('maxWorkers')) {
diff --git c/packages/jest-cli/build/cli/index.js w/packages/jest-cli/build/cli/index.js
index 03d8f26a3..bb877dbfe 100644
--- c/packages/jest-cli/build/cli/index.js
+++ w/packages/jest-cli/build/cli/index.js
@@ -56,8 +56,6 @@ function _core() {
   return data;
 }
 
-var args = _interopRequireWildcard(require('./args'));
-
 function _chalk() {
   const data = _interopRequireDefault(require('chalk'));
 
@@ -100,7 +98,9 @@ function _realpathNative() {
 
 var _init = _interopRequireDefault(require('../init'));
 
-var _package = require('../../package.json');
+var _version = _interopRequireDefault(require('../version'));
+
+var args = _interopRequireWildcard(require('./args'));
 
 function _interopRequireWildcard(obj) {
   if (obj && obj.__esModule) {
@@ -202,7 +202,6 @@ function run(_x, _x2) {
 function _run() {
   _run = _asyncToGenerator(function*(maybeArgv, project) {
     try {
-      // $FlowFixMe:`allow reduced return
       const argv = buildArgv(maybeArgv);
 
       if (argv.init) {
@@ -230,18 +229,20 @@ function _run() {
 
 const buildArgv = maybeArgv => {
   const version =
-    _package.version +
+    (0, _version.default)() +
     (__dirname.includes(`packages${_path().default.sep}jest-cli`)
       ? '-dev'
       : '');
   const rawArgv = maybeArgv || process.argv.slice(2);
-  const argv = (0, _yargs().default)(rawArgv)
-    .usage(args.usage)
-    .version(version)
-    .alias('help', 'h')
-    .options(args.options)
-    .epilogue(args.docs)
-    .check(args.check).argv;
+  const argv =
+    maybeArgv ||
+    (0, _yargs().default)(process.argv.slice(2))
+      .usage(args.usage)
+      .version(version)
+      .alias('help', 'h')
+      .options(args.options)
+      .epilogue(args.docs) // @ts-ignore: it's unable to infer what arguments it contains
+      .check(args.check).argv;
   (0, _jestValidate().validateCLIOptions)(
     argv,
     _objectSpread({}, args.options, {
@@ -254,7 +255,6 @@ const buildArgv = maybeArgv => {
 
   return Object.keys(argv).reduce((result, key) => {
     if (!key.includes('-')) {
-      // $FlowFixMe:`allow reduced return
       result[key] = argv[key];
     }
 
@@ -319,7 +319,7 @@ const readResultsAndExit = (result, globalConfig) => {
               "weren't stopped in your tests. Consider running Jest with " +
               '`--detectOpenHandles` to troubleshoot this issue.'
           )
-      ); // $FlowFixMe: `unref` exists in Node
+      );
     }, 1000).unref();
   }
 };
diff --git c/packages/jest-cli/build/init/constants.js w/packages/jest-cli/build/init/constants.js
index 9b0e676be..900f23ecd 100644
--- c/packages/jest-cli/build/init/constants.js
+++ w/packages/jest-cli/build/init/constants.js
@@ -10,8 +10,6 @@ exports.JEST_CONFIG = exports.PACKAGE_JSON = 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 PACKAGE_JSON = 'package.json';
 exports.PACKAGE_JSON = PACKAGE_JSON;
diff --git c/packages/jest-cli/build/init/errors.js w/packages/jest-cli/build/init/errors.js
index 77ed57202..eed7c8a66 100644
--- c/packages/jest-cli/build/init/errors.js
+++ w/packages/jest-cli/build/init/errors.js
@@ -10,14 +10,11 @@ exports.MalformedPackageJsonError = exports.NotFoundPackageJsonError = 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 NotFoundPackageJsonError extends Error {
   constructor(rootDir) {
-    super();
+    super(`Could not find a "package.json" file in ${rootDir}`);
     this.name = '';
-    this.message = `Could not find a "package.json" file in ${rootDir}`;
     Error.captureStackTrace(this, () => {});
   }
 }
@@ -26,11 +23,11 @@ exports.NotFoundPackageJsonError = NotFoundPackageJsonError;
 
 class MalformedPackageJsonError extends Error {
   constructor(packageJsonPath) {
-    super();
-    this.name = '';
-    this.message =
+    super(
       `There is malformed json in ${packageJsonPath}\n` +
-      'Fix it, and then run "jest --init"';
+        'Fix it, and then run "jest --init"'
+    );
+    this.name = '';
     Error.captureStackTrace(this, () => {});
   }
 }
diff --git c/packages/jest-cli/build/init/generate_config_file.js w/packages/jest-cli/build/init/generate_config_file.js
index 4b7b0884b..44952dc9e 100644
--- c/packages/jest-cli/build/init/generate_config_file.js
+++ w/packages/jest-cli/build/init/generate_config_file.js
@@ -20,8 +20,6 @@ function _jestConfig() {
  *
  * This source code is licensed under the MIT license found in the
  * LICENSE file in the root directory of this source tree.
- *
- *
  */
 const stringifyOption = (option, map, linePrefix = '') => {
   const optionDescription = `  // ${_jestConfig().descriptions[option]}`;
@@ -69,10 +67,12 @@ const generateConfigFile = results => {
   const properties = [];
 
   for (const option in _jestConfig().descriptions) {
-    if (overrideKeys.includes(option)) {
-      properties.push(stringifyOption(option, overrides));
+    const opt = option;
+
+    if (overrideKeys.includes(opt)) {
+      properties.push(stringifyOption(opt, overrides));
     } else {
-      properties.push(stringifyOption(option, _jestConfig().defaults, '// '));
+      properties.push(stringifyOption(opt, _jestConfig().defaults, '// '));
     }
   }
 
diff --git c/packages/jest-cli/build/init/index.js w/packages/jest-cli/build/init/index.js
index 6408c62fe..cae2fc28c 100644
--- c/packages/jest-cli/build/init/index.js
+++ w/packages/jest-cli/build/init/index.js
@@ -5,30 +5,30 @@ Object.defineProperty(exports, '__esModule', {
 });
 exports.default = void 0;
 
-function _chalk() {
-  const data = _interopRequireDefault(require('chalk'));
+function _fs() {
+  const data = _interopRequireDefault(require('fs'));
 
-  _chalk = function _chalk() {
+  _fs = function _fs() {
     return data;
   };
 
   return data;
 }
 
-function _fs() {
-  const data = _interopRequireDefault(require('fs'));
+function _path() {
+  const data = _interopRequireDefault(require('path'));
 
-  _fs = function _fs() {
+  _path = function _path() {
     return data;
   };
 
   return data;
 }
 
-function _path() {
-  const data = _interopRequireDefault(require('path'));
+function _chalk() {
+  const data = _interopRequireDefault(require('chalk'));
 
-  _path = function _path() {
+  _chalk = function _chalk() {
     return data;
   };
 
@@ -202,7 +202,8 @@ var _default =
           `The following questions will help Jest to create a suitable configuration for your project\n`
         )
       );
-      let promptAborted = false;
+      let promptAborted = false; // @ts-ignore: Return type cannot be object - faulty typings
+
       const results = yield (0, _prompts().default)(questions, {
         onCancel: () => {
           promptAborted = true;
diff --git c/packages/jest-cli/build/init/modify_package_json.js w/packages/jest-cli/build/init/modify_package_json.js
index 6ecc78840..526b485b6 100644
--- c/packages/jest-cli/build/init/modify_package_json.js
+++ w/packages/jest-cli/build/init/modify_package_json.js
@@ -10,14 +10,8 @@ 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.
- *
- *
  */
-const modifyPackageJson = ({
-  projectPackageJson,
-  shouldModifyScripts,
-  hasJestProperty
-}) => {
+const modifyPackageJson = ({projectPackageJson, shouldModifyScripts}) => {
   if (shouldModifyScripts) {
     projectPackageJson.scripts
       ? (projectPackageJson.scripts.test = 'jest')
diff --git c/packages/jest-cli/build/init/questions.js w/packages/jest-cli/build/init/questions.js
index 657b5ccbf..e4790b961 100644
--- c/packages/jest-cli/build/init/questions.js
+++ w/packages/jest-cli/build/init/questions.js
@@ -10,8 +10,6 @@ exports.testScriptQuestion = 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.
- *
- *
  */
 const defaultQuestions = [
   {
diff --git c/packages/jest-cli/build/init/types.js w/packages/jest-cli/build/init/types.js
new file mode 100644
index 000000000..ad9a93a7c
--- /dev/null
+++ w/packages/jest-cli/build/init/types.js
@@ -0,0 +1 @@
+'use strict';
diff --git c/packages/jest-cli/build/version.js w/packages/jest-cli/build/version.js
index e99eee057..62f7d7cc0 100644
--- c/packages/jest-cli/build/version.js
+++ w/packages/jest-cli/build/version.js
@@ -5,16 +5,15 @@ Object.defineProperty(exports, '__esModule', {
 });
 exports.default = getVersion;
 
-var _package = require('../package.json');
-
 /**
  * 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 _require = require('../package.json'),
+  VERSION = _require.version;
+
 function getVersion() {
-  return _package.version;
+  return VERSION;
 }

Test plan

Green CI

@codecov-io
Copy link

Codecov Report

Merging #8024 into master will increase coverage by 0.02%.
The diff coverage is 81.81%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8024      +/-   ##
==========================================
+ Coverage   62.66%   62.68%   +0.02%     
==========================================
  Files         263      262       -1     
  Lines       10308    10311       +3     
  Branches     2281     2299      +18     
==========================================
+ Hits         6459     6463       +4     
+ Misses       3279     3277       -2     
- Partials      570      571       +1
Impacted Files Coverage Δ
packages/jest-cli/src/init/modify_package_json.ts 100% <ø> (ø)
packages/jest-cli/src/init/constants.ts 100% <ø> (ø)
packages/jest-config/src/Deprecated.ts 66.66% <ø> (ø) ⬆️
packages/jest-cli/src/init/index.ts 83.72% <ø> (ø)
packages/jest-core/src/SearchSource.ts 57.89% <100%> (ø) ⬆️
packages/jest-config/src/utils.ts 75% <100%> (ø) ⬆️
packages/jest-cli/src/version.ts 100% <100%> (ø)
packages/jest-cli/src/init/generate_config_file.ts 100% <100%> (ø)
packages/jest-config/src/normalize.ts 79.52% <100%> (ø) ⬆️
packages/jest-cli/src/init/questions.ts 100% <100%> (ø)
... and 4 more

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 c15b7a5...fe83d64. Read the comment docs.

@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 11, 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.

None yet

5 participants