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
Collaborator

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

@SimenB SimenB force-pushed the SimenB:ts-babel-jest branch from 8fc5038 to 8aa7b61 Feb 11, 2019
@SimenB SimenB added this to the TypeScript Migration milestone Feb 11, 2019
@SimenB SimenB requested a review from thymikee Feb 11, 2019
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 SimenB:ts-babel-jest branch from 2e21317 to a38c51b Feb 12, 2019
@SimenB SimenB force-pushed the SimenB:ts-babel-jest branch 2 times, most recently from d3e84e6 to cb15d24 Feb 13, 2019
@@ -39,10 +38,10 @@ const createTransformer = (options: any): Transformer => {
sourceMaps: 'both',
};

delete options.cacheDirectory;
delete options.filename;

This comment has been minimized.

Copy link
@SimenB

SimenB Feb 13, 2019

Author Collaborator

overwritten on line 47 anyways

SimenB and others added 9 commits Feb 11, 2019
@SimenB SimenB force-pushed the SimenB:ts-babel-jest branch from 44557c2 to fb36a69 Feb 13, 2019
map?: FixedRawSourceMap | string | null;
};

export type TransformResult = {

This comment has been minimized.

Copy link
@SimenB

SimenB Feb 13, 2019

Author Collaborator

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

@SimenB SimenB merged commit 00bd060 into facebook:master Feb 13, 2019
9 of 12 checks passed
9 of 12 checks passed
ci/circleci: test-node-6 Your tests failed on CircleCI
Details
continuous-integration/appveyor/pr Waiting for AppVeyor build to complete
Details
facebook.jest in progress
Details
ci/circleci: lint-and-typecheck Your tests passed on CircleCI!
Details
ci/circleci: test-browser Your tests passed on CircleCI!
Details
ci/circleci: test-jest-circus Your tests passed on CircleCI!
Details
ci/circleci: test-node-10 Your tests passed on CircleCI!
Details
ci/circleci: test-node-11 Your tests passed on CircleCI!
Details
ci/circleci: test-node-8 Your tests passed on CircleCI!
Details
ci/circleci: test-or-deploy-website Your tests passed on CircleCI!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
deploy/netlify Deploy preview ready!
Details
@SimenB SimenB deleted the SimenB:ts-babel-jest branch Feb 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.