1
votes

I'm using some files from another repository which is written in es6 syntax.

The current project also is written with es6 syntax, but Babel is configured so tests don't fail on the imports. but when it tries to import file from that repository it fails. When I rewrite es6 imports and exports into CommonJS require syntax tests does not fail.

Do I need some additional configuration of Jest or Babel?

1
Do you have a jest config file? I know that with karma testing, there is a karma.conf.js file, that tells karma to essentially use your webpack file and with that, babel.Brett East
@Brett East yeah, I have Babel and Jest configs. Jest works properly if tests don't try to import files from that repository.Andrew Korin
I don't know enough about the jest setup, so I can only try and help based on my karma knowledge, although I did find this - jestjs.io/docs/en/getting-started#using-babel - do you have these dependencies installed?Brett East
@Brett East yep, everything is installed and set upAndrew Korin
In that case, I don't think I can helpBrett East

1 Answers

1
votes

Yes, you just need some additional configuration of Jest.

By default Jest does not transform anything in node_modules.

That behavior is controlled by the configuration option transformIgnorePatterns which defaults to["/node_modules/"].

If there is code within node_modules that needs to be transformed then you can whitelist those modules by modifying transformIgnorePatterns in your Jest config:

"transformIgnorePatterns": [
  "node_modules/(?!(first-module-to-transform|second-module-to-transform)/)"
]