serge1peshcoff serge1peshcoff - 28 days ago 14
Javascript Question

SyntaxError when running a Jest test containing import of a CoffeeScript file

I am writing a Jest integration test to test my server. Here is my test:

import { app, port } from '../server' // the other lines are not so important

When running
this raises an error:

‚óŹ Test suite failed to run

<project folder>/node_modules/papercut/lib/
{FileStore, S3Store, TestStore } = require('./store')
SyntaxError: Unexpected token =

I am requiring
in my Jest test, this file requires
and this file requires node module called
. The problem is, it's written in CoffeeScript, not pure JS.

At the beginning I had this error: Jest: cannot find module required inside module to be tested (relative path). I added
to my
config like that:

"jest": {
"moduleFileExtensions": ["js", "json", "jsx", "node", "coffee"]

but now I have the error I've described above.

How can I handle this?


I eventually fixed it by doing 2 things:

  • adding a preprocessor for coffee files (like in other question)
  • adding "preprocessorIgnorePatterns": [] to my Jest config. Jest ignores .coffee files inside node_modules/ if you won't tell it explicitly that you want to compile these files as well.