Skip to content
This repository has been archived by the owner on Jan 26, 2024. It is now read-only.

Jest types didn't found #7

Closed
dianjuar opened this issue Sep 3, 2019 · 10 comments
Closed

Jest types didn't found #7

dianjuar opened this issue Sep 3, 2019 · 10 comments
Assignees
Milestone

Comments

@dianjuar
Copy link
Collaborator

dianjuar commented Sep 3, 2019

When you are writing test, jest types are not found and you miss the auto-completion feature of typescript

To reproduce this bug, just open any test file and see that everything related with jest is not defined

@JohannesHoppe
Copy link
Member

JohannesHoppe commented Sep 3, 2019

I can confirm that but haven't found the reason until now. Honestly, I ignored the red lines in VSCode because the tests still execute flawlessly. Any help is appreciated! ☺️

(written on my mobile phone)

@dianjuar
Copy link
Collaborator Author

dianjuar commented Sep 3, 2019

I have a clone of this repo and there, following an issue I can solve it...

Also, I see that the jest and typescript configurations need a little tweak, it runs the test that are in the dist folder. That means that the typescript compiler is compiling the test and the test runner is searching for test in the dist folder...

@JohannesHoppe
Copy link
Member

Thanks for your investigation. Could you make a PR to fix this?

@dianjuar
Copy link
Collaborator Author

dianjuar commented Sep 3, 2019

Sure!

@JohannesHoppe
Copy link
Member

@dianjuar Did you found out how to include the jest types? The red curled lines in VSCode drive me crazy! 😵

@dianjuar
Copy link
Collaborator Author

dianjuar commented Nov 7, 2019

Yes I did. I'm not an expert about tsconfig.json but did the following

remove "files": ["index.ts"],

and add the following to the end of the file

"exclude": ["node_modules", "dist"],
"typeRoots": ["node_modules/@types"]
I think the last one was just typescript tweaking and is not related to this issue

I lost the reference of the place were I took the solution but was an specific issue related about the types on the test files without a direct solution. Someone on the comments with lots of reactions said something like ummm, you may have "files": ["index.ts"] in your tsconfig.json but was almost in a rhetorical way, he was not pointing directly to that solution, so I just removed it, saw that it worked and my development process was not affected at all so I just move forward.


I didn't make the PR because I was not sure about how this works, so though let's wait and see if this comes with a bug or an issue in my project but everything is more than fine, my test has their shiny auto-completion and the rest of the project works like a charm.

Maybe you can research more about "files": ["index.ts"], and come with a explanation.

You can compare your tsconfig.json with mine

JohannesHoppe added a commit to angular-schule/angular-cli-ghpages that referenced this issue Nov 17, 2020
@JohannesHoppe JohannesHoppe reopened this Nov 17, 2020
@dianjuar
Copy link
Collaborator Author

dianjuar commented Dec 6, 2020

I think the right way to solve this is to have two separate tsconfig.json files, one for development and the other one just for building. I notice this on a nest project and an Angular project, they have separate tsconfig.json files, one for development, another for building, and another for testing (this is the Angular case).

I'm also noticing that at the moment of the build it is taking the test files, if some test file has a type problem the build fails.

@dianjuar
Copy link
Collaborator Author

dianjuar commented Dec 6, 2020

I'm migrating my builder to V11, and I need to do some experiments through TDD, maybe at the end of the integration I have experimented enough to make a PR to solve this

@JohannesHoppe
Copy link
Member

Already fixed in angular-cli-ghpages. I just need some time to port everything back! 😅

@JohannesHoppe
Copy link
Member

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

2 participants