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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support synthetic default imports #172

Merged
merged 3 commits into from Apr 25, 2017

Conversation

ds300
Copy link
Contributor

@ds300 ds300 commented Apr 24, 2017

Hey, thanks for this lib. It has been super helpful 馃憤

As discussed in #146, TypeScript doesn't implement default synthetic imports, so if you want to use those while targeting CommonJS (which Jest requires) you have to add an extra compile step, e.g. with Babel.

Usage of babel-jest as a post-ts-transform step was briefly discussed in #63, and that's what I have done in this PR.

Perf obviously takes a hit, but thanks to Jest's caching you rarely notice.

@kulshekhar
Copy link
Owner

@ds300 thanks for the PR!

Would it be possible for you to add some tests for this functionality so that future changes don't inadvertently break what this PR adds?

@ds300
Copy link
Contributor Author

ds300 commented Apr 24, 2017

Sure, no problem. I'll try to add some tomorrow morning.

@ds300
Copy link
Contributor Author

ds300 commented Apr 24, 2017

@kulshekhar Tests done.

@kulshekhar kulshekhar merged commit 34da50d into kulshekhar:master Apr 25, 2017
@kulshekhar
Copy link
Owner

Thanks @ds300 :)

@zamiang
Copy link

zamiang commented Apr 25, 2017

Been using this lib for a while, but after this change, getting ReferenceError: regeneratorRuntime is not defined in all tests. Happy to include some more detail but does that ring any bells? Am using async/await in tests.

@kulshekhar
Copy link
Owner

@zamiang can you open this as an issue with link to a minimal repo that reproduces this? It'll help track, debug and fix this much quicker

@ds300
Copy link
Contributor Author

ds300 commented Apr 26, 2017

It sounds like the async/await annotations are being passed through and compiled by babel, which would happen with TypeScript < 2.1. I hadn't considered that might happen, and we need to account for it 馃

@kulshekhar
Copy link
Owner

kulshekhar commented Apr 26, 2017

Based on a quick search, it seems that others who had a similar issue (unrelated to jest) used babel-polyfill to fix it. If we have a minimal repo (ideally with a travis setup), such things can be quickly tested

@zamiang
Copy link

zamiang commented Apr 26, 2017

Ok. Am investigating a repro. FWIW I am using node 6.10, typescript 2.2.2 and my compilation target is ES6.

May be related to #177

@ds300
Copy link
Contributor Author

ds300 commented Apr 26, 2017

May be related to #177

Interesting, what makes you say that?

@zamiang
Copy link

zamiang commented Apr 26, 2017

Both likely relate to code that was not previously being run through babel, now being run through babel and then compiled by typescript w/ the es2015 target rather than their original target. (fundamentally what this PR does)

That is a very large change to the pipeline that causes a difference between the production and testing asset pipeline (at least in my applications which do not use babel and rely on ts-jest + ts-node). In short, the change worries me a lot and makes me question whether it is a good idea more generally.

I'm only a couple hours into debugging this but I can currently repro by using ES6 functionality (such as async/await) in tests with allowSyntheticDefaultImports: true. My theory being that we may need to enable custom babel presets and tsconfig targets when allowSyntheticDefaultImports: true to allow for using functionality newer than es2015 (the current preset).

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

3 participants