-
Notifications
You must be signed in to change notification settings - Fork 453
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
Compiler options not working as expected when using project references #766
Comments
Fixed in 23.10.2. This was in fact related to the forced |
I believe the issue here may be wider than this. In my testing, no compiler options are respected from the referenced TS project—not just |
Also 23.10.2 does not fix the issue even for the |
Actually I said it was fixed because I did clone, upgrade and then yarn test which succeeded. |
Can you upgrade the minimal repo's master adding an option that makes jest fail while tsc pass? Be sure to upgrade ts-jest (personally I |
Arrrrrrgg wrong button, sorry! |
The original repro is on the
The upgraded repro is on the
Passes:
Fails:
|
Ok I've tested on master, that might be the reason ;-) |
If you have multiple projects, you should have a jest config for each of them as well, and then in the main Update: But your particular use-case here does not make sense (at least for me). Why would you have, in the same project, different compiler options between the sources and the tests files (except |
Separating tests from source code are one of the primary use cases for project references (see https://www.typescriptlang.org/docs/handbook/project-references.html#an-example-project). This separation allows you to have different compiler options, which is useful for specifying different
|
hmmmm... makes sense ok. I'll look deeper into what are the options here. I'll have to look in their API how they handle this, because we're using the language service so it should work out of the box. Anyway, until this get fixed, here is how I deal with the problem they exposed:
|
@OliverJAsh can you come over ts-jest slack? https://bit.ly/ts-jest-slack |
Any updates on this issue? I'm not 100% sure if my issue is related, but I have a hunch it is... I've just spent best part of a day trying to get ts-jest to transpile typescript from another module within a monorepo so that coverage is correct. I think I have jest/ts-jest configured correctly with |
I have similar problem:
When I run project everything works properly but it when I try to test it fails. I use transform: {
"^.+\\.gql$": "jest-transform-graphql",
} Any idea how to solve this problem? |
Any updates or RIP? |
I used this code at
This information helped me a lot https://huafu.github.io/ts-jest/user/config/diagnostics |
@zenby's solution works, but it's the "nuclear" option. To avoid those globals: {
"ts-jest": {
"diagnostics": {
"ignoreCodes": "TS1192"
}
}
} |
It seems like when resolving My test case is removing the built artifacts (i.e. The error is
|
@unional I'm having that same issue... did you find a solution? |
My solution is to not rely on the diagnostic at all. I run You can check out |
Also, I find that having the diagnostic in the there are times that I am in the process of refactoring and the type breaks. With diagnostic turned on, I'm force to fix the type on a solution that I don't know if it is correct or not, which would be a waste of time if I will be throwing the code away anyway. |
I got my mono-repo to compile on jest run without having to build files by using |
@j how did you do it? |
In my case Jest does not even tries to build the project references, it just fails with error:
|
You have to use
Your actual path is:
This can be calculated via:
where Perhaps ts-jest can automatically do this based on |
This is not what happened. Modules themselves are just simple Lerna links, that totally can be found by any Node script. Jest cannot find the module because it does not have build artifacts (JS files that are referred from It happens because JEST does not initiate build of upstream projects, just like I said. |
this might be fixed by #1385, do you have an example repo for your case @kirill-konshin ? |
I checked out your repo and did some following steps:
and there is no error anymore. I think your issue is solved with latest dependencies |
@ahnpnl Are you using the https://github.com/OliverJAsh/jest-ts-project-references/tree/ts-jest-issue I made a new branch that contains the upgrades you mentioned. The branch still fails: https://github.com/OliverJAsh/jest-ts-project-references/tree/ts-jest-issue-upgrade |
Oh right, I’m sorry. It could be that when cloning the repo to my laptop, I forgot to switch branch. I will take a look again. Updated: @OliverJAsh indeed i can see the error (even though it's slightly different from what you reported, about From what I see is your project using typescript project references. When I debug What do you think ? |
That sounds more like the functionality of References is a bit more complicated, since the compiler options inside a referenced TS config should only apply to the files in the scope of that TS project. |
hmm i'm not experienced with this project reference but your explanation makes some clearance for me. However, I don't know how we can tackle this. Do you have any suggested solutions ? In general,
Updated @OliverJAsh I think I found a way to fix the issue. Would you please try:
|
the issue will be fixed by specifying the correct
This will tell |
Also possibly solved by microsoft/TypeScript#37239 |
I know this is an old issue, but if anyone else is running into similar problems... globals: {
'ts-jest': {
isolatedModules: true,
},
} |
@alexbruno this is not a solution, is a workaround with a drawback: you loose type checking |
Issue :
Full reproduction case
Expected behavior :
I have three TS projects:
tsconfig-src.json
tsconfig-tests.json
tsconfig.json
whichreferences
both of the above (using TypeScript's new "project references" feature)When running jest, it should read compiler options from
tsconfig.json
.Because
tsconfig.json
includes no files for itself but just references other projects, ts-jest should read its compiler options from the project reference that corresponds to any given file.For example,
tsconfig.json
references thetsconfig-tests.json
project:In turn,
tsconfig-tests.json
includes
all test files:Given this example, I expect any test file matching the tests TS project (
tsconfig-tests.json
, whichincludes
**/__tests__/**/*
) to use compiler options for that TS project.Actual behaviour
Looking at the logs, I can see
tsconfig.json
is used. However,compilerOptions
is read fromtsconfig.json
, nottsconfig-tests.json
.I have verified this:
tsconfig.json
, ts-jest uses them.tsconfig-tests.json
, ts-jest does not use them.Debug log:
log file content
Minimal repo :
Full reproduction case
In the full reproduction case I have created, you will see that running
tsc -b -f tsconfig.json
has no problems, but runningjest
fails with:This failure suggests that the
allowSyntheticDefaultImports
compiler option, used intsconfig-tests.json
, is not picked up.The text was updated successfully, but these errors were encountered: