Traceur with Jest / React

121 views
Skip to first unread message

Phillip Perry

unread,
Nov 28, 2014, 4:29:21 PM11/28/14
to jes...@googlegroups.com
Has anyone successfully setup Jest with React + ES6 preprocessor? I'm fumbling around and can't manage to get it to work.

// in package.json
 
"jest": {
   
"setupEnvScriptFile": "node_modules/traceur/bin/traceur-runtime.js",
   
"scriptPreprocessor": "jest.conf.js",
   
"unmockedModulePathPatterns": [
     
"node_modules/react"
   
]
 
}

// jest.conf.js
var ReactTools = require('react-tools'),
    traceur
= require('traceur');
module.exports = {
    process
: function (src, path) {
       
if (path.indexOf('node_modules') === -1) {
            src
= traceur.compile(
               
ReactTools.transform(src),
               
{ experimental: true }
           
);
       
}
       
return src;
   
}
};

When I try to run the tests, I get the following error:

Found 1 matching test...
/Users/pperry/example/node_modules/traceur/bin/traceur.js:22696

 
var require = function(id) {
     
^^^^^^^
 FAIL  app
/js/models/__tests__/example-class-test.js

SyntaxError: /Users/pperry/example/jest.conf.js: Variable 'require' has already been declared


The module I'm trying to test exports an ES6 class (it has no imports). The test just tries to create an instance of the class and verify a property on it.

Am I wiring the preprocessor wrong or something? Or is there some trick to the runtime that I'm not getting?
Reply all
Reply to author
Forward
0 new messages