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 babel-jest to TypeScript #7862

Merged
merged 9 commits into from
Feb 13, 2019
Merged

Conversation

SimenB
Copy link
Member

@SimenB SimenB commented Feb 11, 2019

Summary

Built diff:

diff --git c/packages/babel-jest/build/index.js w/packages/babel-jest/build/index.js
index 09b426d20..fc3dd7f8d 100644
--- c/packages/babel-jest/build/index.js
+++ w/packages/babel-jest/build/index.js
@@ -102,8 +102,9 @@ const jestPresetPath = require.resolve('babel-preset-jest');
 
 const babelIstanbulPlugin = require.resolve('babel-plugin-istanbul');
 
-const createTransformer = options => {
+const createTransformer = (options = {}) => {
   options = _objectSpread({}, options, {
+    // @ts-ignore: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/32955
     caller: {
       name: 'babel-jest',
       supportsStaticESM: false
@@ -112,9 +113,9 @@ const createTransformer = options => {
     plugins: (options && options.plugins) || [],
     presets: ((options && options.presets) || []).concat(jestPresetPath),
     sourceMaps: 'both'
-  });
+  }); // @ts-ignore: seems like this is removed. Is that true?
+
   delete options.cacheDirectory;
-  delete options.filename;
 
   function loadBabelConfig(cwd, filename) {
     // `cwd` first to allow incoming options to override it
@@ -188,7 +189,7 @@ const createTransformer = options => {
       if (transformOptions && transformOptions.instrument) {
         babelOptions.auxiliaryCommentBefore = ' istanbul ignore next '; // Copied from jest-runtime transform.js
 
-        babelOptions.plugins = babelOptions.plugins.concat([
+        babelOptions.plugins = (babelOptions.plugins || []).concat([
           [
             babelIstanbulPlugin,
             {
@@ -201,10 +202,20 @@ const createTransformer = options => {
       }
 
       const transformResult = (0, _core().transformSync)(src, babelOptions);
-      return transformResult || src;
+
+      if (transformResult && typeof transformResult.code === 'string') {
+        // @ts-ignore: why doesn't TS understand this?
+        return transformResult;
+      }
+
+      return src;
     }
   };
 };
 
-module.exports = createTransformer();
-module.exports.createTransformer = createTransformer;
+const transformer = createTransformer(); // FIXME: This is not part of the exported TS types. When fixed, remember to
+// move @types/babel__core to `dependencies` instead of `devDependencies`
+// (one fix is to use ESM, maybe for Jest 25?)
+
+transformer.createTransformer = createTransformer;
+module.exports = transformer;

Test plan

Green CI

packages/babel-jest/src/index.ts Outdated Show resolved Hide resolved
packages/babel-jest/tsconfig.json Show resolved Hide resolved
@SimenB SimenB force-pushed the ts-babel-jest branch 2 times, most recently from d3e84e6 to cb15d24 Compare February 13, 2019 08:16
@@ -39,10 +38,10 @@ const createTransformer = (options: any): Transformer => {
sourceMaps: 'both',
};

delete options.cacheDirectory;
delete options.filename;
Copy link
Member Author

Choose a reason for hiding this comment

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

overwritten on line 47 anyways

map?: FixedRawSourceMap | string | null;
};

export type TransformResult = {
Copy link
Member Author

Choose a reason for hiding this comment

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

this type is not use now - it will be by jest-runtime later, though

@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