How can I use Jest to test React components written in CoffeeScript + React jsx?
The only CoffeeScript example provided with Jest uses plain CoffeeScript, and doesn't work with CoffeeScript + React JSX (syntax error when it reaches a <
).
What I have tried
first attempt: execSync
// preprocessor.js
var execSync = require('exec-sync');
module.exports = {
process: function (src, path) {
return execSync('browserify -t coffee-reactify ' + path);
}
};
This works, but takes too much time (a good 12 seconds for a dummy test).
Then I tried:
second attempt: coffee-react-transform
// preprocessor.js
var coffee = require('coffee-script');
var transform = require('coffee-react-transform');
module.exports = {
process: function(src, path) {
if (path.match(/\.coffee$/)) {
return coffee.compile(transform(src), {'bare': true});
}
return src;
}
};
This throws a strange error, like:
TypeError: function() {...} has no method 'getPooled'
The only Google result for "has no method 'getPooled'" is this gist, that shows exactly the error I get, but offers no other insights.
third possible attempt
I think I could use coffee-reactify, but it returns a stream, which is asynchronous, while the process
function in preprocess.js
is used synchronously, and have found no way, so far, to read a stream synchronously.
What can I do?