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

[WIP EXPERIMENT] attempt to use babel preset-typescript instead of ts-jest #492

Closed
wants to merge 4 commits into from

Conversation

toolness
Copy link
Collaborator

@toolness toolness commented Feb 27, 2019

While attempting to experiment with lingui for #12 I ran into some more issues related to ts-jest's support for the latest version of Jest. It turns out that Babel 7 added support for TypeScript, which means that we can potentially use that instead of ts-jest to do TypeScript stuff in Jest.

One advantage of this might be speed: right now ts-jest does type-checking, which we don't really need since we separately run tsc --noEmit during CI, and it could potentially speed up test runs. But also, it seems like ts-jest might just be deprecated in favor of the built-in support.

That said, it seems like the built-in TS support simply removes type information, which means we need to lean on Babel plugins to do all the things that TS's transpilation functionality normally does for us.

@toolness
Copy link
Collaborator Author

To expand on why I'm doing this PR: basically, using lingui requires that we set "jsx": "preserve" in our tsconfig.json, because lingui uses some fancy Babel macros to do its thing. This necessarily means that we'd need to modify our jest config (among other parts of our build pipeline) to do the JSX conversion itself. Doing this with ts-jest should mean adding the following inline compiler options to our jest.config.js:

module.exports = {
  "globals": {
    "ts-jest": {
      "babelConfig": {
        "plugins": [
          "@babel/plugin-transform-react-jsx"
        ]
      }
    }
  },
  /* ... */
}

However, doing this causes the test suite to fail with the error Passing cached plugin instances is not supported in babel.loadPartialConfig.

One solution to this problem is to wait for it to get fixed in ts-jest, but another is to simply remove ts-jest and use Babel 7's built-in TypeScript support.

@toolness
Copy link
Collaborator Author

toolness commented Feb 28, 2019

Ok, this is frustrating. It looks like the rest of the world has not yet caught up with Babel 7. After a lot of investigation, I discovered that there's a bug with Jest's test coverage system, Instanbul, and Babel's built-in TypeScript support, so I had to disable test coverage.

Aside from that, there's still one failing test because it seems like the weird dynamic import polyfill I had to use for node, babel-plugin-dynamic-import-node-babel-7, isn't exporting default module exports properly. (Update: It actually looks like the original babel-plugin-dynamic-import-node supports Babel 7, and also exports default module exports properly; we're using it in the master branch now, as of #494.)

Given that using Babel's "built-in" TypeScript support actually means bringing in a bunch more third-party modules and disabling test coverage for the time being, I don't think it's a good idea to pursue this right now, so I'm going to close this PR.

@ahnpnl
Copy link

ahnpnl commented Apr 21, 2020

FYI: kulshekhar/ts-jest#1549 will be in alpha version of ts-jest (possibly today). You can test the alpha version and give some feedbacks for kulshekhar/ts-jest#1115

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants