question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Different TS-JEST / TS emitted code when importing 3rd party libs

See original GitHub issue

Continuing the discussion from issue 209

For the same code compiled with TS, ts-jest emits a different output.

  • Both tsconfig file are identical (one for regular TS compilation, one for ts-jest)
  • allowSyntheticDefaultImports set to true.

When using this statement:

import * as pathToRegexp from 'path-to-regexp';

In TS compilation without ts-jest pathToRegexp is a function In TS compilation with ts-jest pathToRegexp is an object.

It’s not deterministic, different outcome for the same TS compilation process

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:20 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
kulshekharcommented, May 17, 2017

Another thing going for option 2 is that it makes sure the users know what’s going on.

Currently, as you pointed out as well, users have no idea that ts-jest uses babel when allowSyntheticDefaultImports is set to true. It’s also not very intuitive. If I came across something like this in another library, I’d be at my wits end should something related go wrong and I have to debug it!

It is a breaking change but the fix required at the users’ end would be straightforward - set transformUsingBabel to true in ts-jest config. This would also give us an opportunity to introduce the ts-jest config within the jest config which can be used by #217 later.

0reactions
GeeWeecommented, May 24, 2017

Currently babel is only used when allowSyntheticDefaultImports is set to true, so it covers all cases. I imagine if we end up using babel for every transformation we will make them independent

On Wed, May 24, 2017, 20:43 jupl notifications@github.com wrote:

I’m confused on the conclusion. My understanding is that right now skipBabel is only applicable to allowSyntheticDefaultImports. If that’s the case is the plan to eventually make skipBabel be independent of allowSyntheticDefaultImports?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/kulshekhar/ts-jest/issues/213#issuecomment-303815248, or mute the thread https://github.com/notifications/unsubscribe-auth/AGFg4MgaQUT_E7v11y95og3xGJzpGtnjks5r9Ho1gaJpZM4NaeJh .

– mvh.

Gustav Wengel

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest fails when importing a 3rd party non TS module
I am using an internal 3rd party Design system library, we will call it (3DS) to render components. The 3DS library doesn't support ......
Read more >
Configuring Jest
To read TypeScript configuration files Jest requires ts-node . ... This option tells Jest that all imported modules in your tests should be ......
Read more >
TypeScript library tips: Rollup your types! | by Martin Hochel
Our whole library tree structure is mirrored by emitted declaration .d.ts files. While we have optimized runtime by rollup-ing our source code ......
Read more >
React app testing: Jest and React Testing Library
Learn how to test React applications with Jest and React Testing Library, a popular combination and official recommendation from React.
Read more >
jest-preset-angular - npm
By Angular CLI defaults you'll have a src/test.ts file which will be picked up by jest. To circumvent this you can either rename...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found