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

Jest with TypeScript do not report any type errors #2168

Closed
gyzerok opened this issue Nov 25, 2016 · 7 comments
Closed

Jest with TypeScript do not report any type errors #2168

gyzerok opened this issue Nov 25, 2016 · 7 comments

Comments

@gyzerok
Copy link

gyzerok commented Nov 25, 2016

Hello, here is my bug report.

Currently when you use TypeScript in a way shown in example you will not be reported if there are type errors in tests.

Reproduce:

git clone git@github.com:gyzerok/jest-ts-bug.git
cd jest-ts-bug
npm install
npm test

To verify that there is actual type error:

npm run typecheck

I expect type errors to be reported while running tests. Preferably well-formatted.

@cpojer
Copy link
Member

cpojer commented Nov 29, 2016

How are type errors thrown by the TypeScript compiler? If it throws a type error on a file, Jest should catch that and show it inline. If the type error is thrown in a file that hasn't changed, Jest will not compile that particular file because it has a transform cache based on when files change. If that's the case, I'm afraid there is nothing we can do except for you to always run with the (slow) --no-cache option.

@gyzerok
Copy link
Author

gyzerok commented Nov 30, 2016

Hello @cpojer

One should gather type errors by himself inside preprocess script. Currently the function which is used in example do not collect any diagnostics. And even if it would there would be no type errors within it. Note transpile and transpileModule are basically the same function with different signatures.

Also in case it throws there is no source maps, so errors shows completely random line numbers. At least for source maps there is solution.

By writing this I am now thinking that it has nothing to do with Jest. But still maybe it would be nice to use ts-jest in the example instead of providing preprocessor which is kind of broken in so many ways. And of course it would be nice to be explicitly notified about problems with type errors in TypeScript, so one could see the trade-offs before putting his time in technology adoption.

@cpojer
Copy link
Member

cpojer commented Nov 30, 2016

Feel free to send a PR to change the TypeScript example to use ts-jest. Indeed, TypeScript support is not "official". You can use any transformer and TS is just one of them – the problems of showing type errors or source maps etc. are entirely on the transformation side and Jest merely provides hooks for these things.

@cpojer cpojer closed this as completed Nov 30, 2016
@gyzerok
Copy link
Author

gyzerok commented Dec 2, 2016

@cpojer actually if Jest would provide ability to use stuff like babel-register or ts-node/register, like mocha do, issue would be solved I guess.

@cpojer
Copy link
Member

cpojer commented Dec 2, 2016

That would be incredibly slow as we'd have to recompile everything on every run. Jest caches transform results.

@pelotom
Copy link

pelotom commented Dec 6, 2016

BTW, ts-jest doesn't currently display type errors either. I've opened this ticket to request that feature.

@github-actions
Copy link

This issue 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 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants