envs icon indicating copy to clipboard operation
envs copied to clipboard

Jest + Typescript Error (Code 2)

Open rap0so opened this issue 5 years ago • 17 comments

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

  • Bit version: 14.7.1
  • Node version: v10.16.3
  • npm / yarn version: yarn 1.19.1
  • Platform: Windows 10 Pro
  • Compiler / Tester (include version): Jest + Ts

Additional context

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

rap0so avatar Dec 27 '19 20:12 rap0so

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.

vatsalm-scaleup avatar Jan 02 '20 08:01 vatsalm-scaleup

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 :(

rap0so avatar Jan 02 '20 12:01 rap0so

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

rapowell9 avatar Jan 17 '20 15:01 rapowell9

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

GiladShoham avatar Jan 19 '20 10:01 GiladShoham

@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?

wannadream avatar Feb 10 '20 22:02 wannadream

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

GiladShoham avatar Feb 11 '20 16:02 GiladShoham

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?

wannadream avatar Feb 11 '20 18:02 wannadream

@itaymendel or anyone else, any updates/workarounds?

saltman424 avatar Mar 31 '20 14:03 saltman424

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

alextuppen avatar May 25 '20 17:05 alextuppen

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

rotimi-babalola avatar May 28 '20 09:05 rotimi-babalola

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

wannadream avatar May 28 '20 17:05 wannadream

@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.

GiladShoham avatar Jun 02 '20 17:06 GiladShoham

@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.

alextuppen avatar Jun 06 '20 13:06 alextuppen

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

GiladShoham avatar Jun 14 '20 20:06 GiladShoham

Any update on the new version?

speelbarrow avatar Aug 25 '20 21:08 speelbarrow

Are there any updates on this at all?

GrmpyPmpkin avatar Nov 09 '20 14:11 GrmpyPmpkin

Any update on the new version? Thanks

ldelia avatar Jan 13 '21 18:01 ldelia