Using Jest with SystemJS and JSPM

362 views
Skip to first unread message

halfs...@gmail.com

unread,
Sep 1, 2015, 12:47:52 AM9/1/15
to Jest
I have been developing a project that uses ES6, Babel, SystemJS and JSPM and I found there were some shortcomings to using Jest along with this setup.

The primary issue is that Jest mocking only supports loading modules in the CommonJS format. The "haste module loader" within Jest could be refactored to support the ES6 module loader, but it would require making a lot of it async.

The babel-jest plugin exists, and it could be modified to spit out modules that use the System.register format. However, this still would result in an improperly configured loader.

My solution was to implement a systemjs-jest plugin that loads the JSPM config file and preprocesses the tests with the SystemJS builder: https://www.npmjs.com/package/systemjs-jest

The downside is that mocking in Jest doesn't work with this, unless you explicitly use "require" to pull in the dependencies you want mocked. This seems to defeat a lot of the purpose of using ES6 modules to begin with, so we may go back to using mocha/sinon at some point.

- Jason

yoav...@gmail.com

unread,
Dec 24, 2016, 2:44:53 PM12/24/16
to Jest

In case someone reaches this thread looking for a solution to using Jest with a JSPM/SystemJS based app. I've created a Gulp plugin that generates the necessary Jest configuration based on the SystemJS config: https://www.npmjs.com/package/gulp-jest-jspm.

It can even be used without gulp by simply calling the getJestConfig() method and passing it to Jest.

As far as I know it doesnt have any drawbacks and allows to use Jest to the fullest.

Yoav

Reply all
Reply to author
Forward
0 new messages