teambit / envs

Component development environments for the Bit community
https://bit.dev/bit/envs
Other
63 stars 9 forks source link

Jest + Typescript Error (Code 2) #65

Open rap0so opened 4 years ago

rap0so commented 4 years ago

Describe the bug

I'm following the doc, but when i run bit test

Steps to Reproduce

  1. bit import bit.envs/testers/jest -t
  2. bit import -c bit.envs/compilers/typescript
  3. bit add src/project --main src/project/index.ts --tests specs/hello-world.spec.ts --id project
  4. bit test project

Expected Behavior

Result of tests

Screenshots, exceptions and logs

image

image

Specifications

Additional context

I've already cleaned the project and restarted from scratch by running git init --reset-hard and still doesnt work

vatsalm-scaleup commented 4 years ago

Hi, I am also facing the same issue., However I am working on React app (with typescript) also I noticed you are using only typescript compiler. In case you also have a react app with typescript you need to use another compiler, react-typescript.

rap0so commented 4 years ago

Hi, I am also facing the same issue., However I am working on React app (with typescript) also I noticed you are using only typescript compiler. In case you also have a react app with typescript you need to use another compiler, react-typescript.

Actually there´s no problem by using typescript compiler, as u can see in the doc it can handle react components too, anyway it happens on both compilers :(

rapowell9 commented 4 years ago

Running bit build on the component provides a more detailed error message, and at least for my component it appears to be a problem with the compiler not finding the jest type definitions. "Cannot find name 'test'. Do you need to install type definitions for a test runner? Try npm i @types/jest or npm i @types/mocha." Adding an overrides clause to the bit config to add @types/jest to the dependencies fixed the error

GiladShoham commented 4 years ago

you should add the jest types using the overrides feature. read more here

wannadream commented 4 years ago

@GiladShoham I added overrides but another error pops up.

Screenshot from 2020-02-10 15-06-12

Here is the reproducible repo. I was simply adding one component and did a 'bit test'. https://github.com/wannadream/bit-dev-bug

Looks like tester cannot find React module?

GiladShoham commented 4 years ago

Try changing the target and module props for the compiler as described in the bottom of this page https://bit.dev/bit/envs/compilers/typescript

wannadream commented 4 years ago

image

I am using https://bit.dev/bit/envs/compilers/react-typescript, but I believe the TS compiler is the same as I see the dependency. Jest was not configured properly?

saltman424 commented 4 years ago

@itaymendel or anyone else, any updates/workarounds?

alextuppen commented 4 years ago

@itaymendel I'd also appreciate any updates or workarounds if you've got them, I'm having the same problem as @wannadream

rotimi-babalola commented 4 years ago

I'm also having this problem as well. Are there any work arounds now?

wannadream commented 4 years ago

What I am doing is to ignore test files when pushing component to Bit. We have CI with GitLab to handle unit testing. Awkward.

GiladShoham commented 4 years ago

@saltman424 @Exitialis1 @rotimi-babalola @wannadream Have you tried to configure the target and module in the compiler config? Also, soon a much better version of the extensions infrastructure (along with a new jest version based on the new infra), is coming. I don't have an exact eta, but it will be much more powerful, extendable, performing and stable. I estimate it will take a few more weeks.

alextuppen commented 4 years ago

@GiladShoham Thank you for the update, I am not sure if I have or not, but I am happy waiting for the new version and running tests else where for now if the new version is only a few weeks away.

GiladShoham commented 4 years ago

@Exitialis1 Sound like a good plan:) it will be really awesome with the new version. stay tuned:)

speelbarrow commented 3 years ago

Any update on the new version?

GrmpyPmpkin commented 3 years ago

Are there any updates on this at all?

ldelia commented 3 years ago

Any update on the new version? Thanks