[solved] _meteor_ npm run causes Jest syntax error

I’ve been trying to figure this issue out for a few days and I’ve finally figured out that it’s something to do with meteor!
Here’s my repo: https://github.com/Falieson/react-typescript-meteor

When I run npm run test:jest all the tests pass, but when I run when I meteor npm run test:jest I get the error:

  ● Test suite failed to run

    SyntaxError: Unexpected token {

      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/ScriptTransformer.js:289:17)
      at Object.<anonymous> (client/CounterComponent.test.tsx:5:35)

Thank you for whatever help/insight you can give to this issue.

Probably because meteor npm uses a different node/npm than the rest of your system. Just use npm run test:jest.

Shouldn’t jest be able to run w/o npm installed locally on my system?
We debated pretty much this point in Announcing meteor-husky, the husky git hooks package for Meteor

I know it doesn’t solve your problem but I just ran meteor npm test (Jest) on one of my apps and the tests ran just fine (except for a part of my app that used Proxies, which aren’t available Meteor’s Node).

I encountered this error as well, as @manuel said it’s because Meteor is using node 4 and in order to parse some newer syntax in your tests without babel you need to use a newer version of node. Luckily the new Meteor 1.6 uses node 8 and it’s very stable, I’ve been using the Meteor 1.6 betas for awhile now without a hitch. So if you’re able to upgrade to a beta release, your jest tests will run fine.

You can see the list of Meteor release tags here, then choose one and run this in your project to upgrade:

meteor update --release 1.6-beta.16 

Then you can run meteor npm run test:jest and it will work. I wouldn’t ever recommend running npm for a Meteor project directly, you should always use meteor npm.


Thanks a lot @efrancis and @manuel . I’m going to take your advice and upgrade to the 1.6 beta. I’ve been looking forward to getting off node4 for a while!