0

I have a UI framework that is maintained by my company. and This library doesn't provide cjm module. instead only provide esm module.

And I aware that this library is not failed to be imported from the test condition running by jest.

through some gogooling, I found that the Jest doesn't support ESM module import, and it is only on experimental stage to support esm module on Jest(https://jestjs.io/docs/ecmascript-modules). So I tried to make my library as cjs module version, and test againg. This is perfectly works. So I convinced that the previous bug was caused because Jest doesn't support esm module import.

But at this point, I wonder something below.

  1. If Jest don't support ESM, every library should have cjs module regardless of providing esm module??

  2. Jest always find only cjs module from libraries?

  3. How React test works on jest? even thought every react component and other modules are ESM? This is why we need react-test-renderer or babel-jest as dependencies for the react test?

  4. Finally, There is some resources that I can find some information about this subject??

Minsik Park
  • 557
  • 3
  • 9
  • 22
  • @MariosNikolaou Yes I did, I linked same page on my post above. My jest version is 26.4.2 – Minsik Park Apr 11 '21 at 10:12
  • You can have native support for modules without esm or babel from Jest version `jest@25.4.0` and above. – Marios Nikolaou Apr 11 '21 at 10:15
  • umm... Then Why my test was failed when my library don't have cjm module? My jest version is up v26, and my node version was also v14.13.1 – Minsik Park Apr 11 '21 at 10:18
  • This might help [here](https://stackoverflow.com/questions/60372790/node-v13-jest-es6-native-support-for-modules-without-babel-or-esm/61653104#61653104) – Marios Nikolaou Apr 11 '21 at 10:20
  • 1
    *even thought every react component and other modules are ESM* - because of Babel. React's JSX is invalid JS and would result in syntax error yet it works somehow. That's why. Native ESM support in Jest is far from practical, you shouldn't really consider it unless proven otherwise. – Estus Flask Apr 11 '21 at 21:12

0 Answers0