-
Notifications
You must be signed in to change notification settings - Fork 459
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
Type error reporting #79
Comments
@pelotom can you create a tiny repo that illustrates the issue and your expectations. It would help in quickly getting started on this |
@kulshekhar there is an example in linked issue. It do not use |
It doesn't seem that this can be fixed in If there were a way to get I'm closing this for now but if you have alternative solutions or want to discuss this further, feel free to do so here. If tsc were to get such a feature, it might be worth reopening this issue. |
Really, the main problem is that TS needs |
If we can somehow serialize compilation and just restore in subsequent calls to preprocessor. Can we cache compilation results within one run of Jest somehow? |
I have no time now to dig deeper but this looks like what we need. |
@gyzerok, ok it's a good point. I'll try to dig into it later, but at first look it seems that we will have to inform |
It might be instructive to look at how the |
Should we reopen an issue since we might have possible solution? |
I haven't dug deep into this but this doesn't look like a workable solution at first sight. The TS docs linked to and ts-loader both use file watchers to do incremental transpilation. Since a preprocessor doesn't run in it's own process and is only invoked by jest on a file by file basis, the expectation is that the preprocessor would process the file given to it and return the result. I would personally like to limit the scope of ts-jest to that. That said, if there's a PR that extends the capability of ts-jest without adding complexity to the core codebase and functionality (something like a plugin/extension), I'm open to it. (Although it would be somewhat amusing to see a plugin, ts-jest, have its own set of plugins) The only reasonable solution I can see is if All this aside, I'm also curious about why failing on a type error would be needed in a preprocessor. Shouldn't this be part of the build process where the build fails if there's a type error? |
Ok, after small investigation I have some thoughts on how it could be achieved. It definitely wouldn't be a preprocessor itself, but we already have coverage processor in our package, so IMO it's not a problem to provide such functionality as sub-module of |
@Igmat As I mentioned in the earlier comment, I can't see a valid reason for type checking to be the responsibility of a preprocessor. However, if you want to add it, go ahead. Just ensure that this doesn't affect the complexity and performance of the core functionality/code. Bear in mind that it's hard to remove a feature (even a poorly performing one) once it has been added and other people depend on it. |
test code is still code, if there's type errors in such test code, shouldn't it fail? |
As mentioned in #250, it's unclear where else type error reporting could go when using |
Woot! Indeed it does. Thanks! |
@kulshekhar Thanks for the suggestion, but when I enable it, the test is really slow..... say 30sec for a single test... |
@lyy011lyy yes, by keeping type checks out of testing (that's what I do) |
@lyy011lyy I use |
Hi @Dean177 : Thanks for the suggestion and it works well locally. I retried the "enableTsDiagnostics": true and found that seems like this will trigger the type checking for the whole imported dependency tree, which makes it slow. I was wondering that is there a way to make it only check the current test file? Thanks |
Found the issue at Line 45 in 125d06b
I found that ts-jest is now checking the type errors for source codes and all their dependencies if "enableTsDiagnostics" is turned ON. This makes it very slow and I don't think that's what we want since the src code type errors will be detected during the build time. What we need should be a way to report the type errors inside the test files, because usually test code will be excluded when build. It should be easy to check whether the filePath is inside one of the root's pathes to achieve that only check the type errors inside test code. I'm creating the pull request. |
Hold on, this is actually one of the main features that ts-jest is advertising here https://kulshekhar.github.io/ts-jest/docs/ |
Currently it seems that the preprocessor doesn't report type errors. Would it be possible to treat type errors in TS files (whether source or test files) as if they were test failures?
The text was updated successfully, but these errors were encountered: