Created
October 4, 2016 21:28
-
-
Save mutewinter/4024a569c70d7dda87a6b22a194d0d11 to your computer and use it in GitHub Desktop.
Use Jest with CoffeeScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"jest": { | |
"moduleFileExtensions": [ | |
"js", | |
"json", | |
"jsx", | |
"node", | |
"coffee" | |
], | |
"preprocessorIgnorePatterns": [ ], | |
"scriptPreprocessor": "<rootDir>/test/preprocessor.js" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const coffee = require('coffee-script'); | |
const babelJest = require('babel-jest'); | |
module.exports = { | |
process: (src, path) => { | |
// CoffeeScript files can be .coffee, .litcoffee, or .coffee.md | |
if (coffee.helpers.isCoffee(path)) { | |
return coffee.compile(src, { bare: true }); | |
} | |
if (!/node_modules/.test(path)) { | |
return babelJest.process(src, path); | |
} | |
return src; | |
} | |
}; |
@MadcapJake This doesn't seem to work too with packages in node_modules
that are written in coffeescript.
In order to have the line numbers to be correct use this code:
const coffee = require('coffeescript');
const babelJest = require('babel-jest');
module.exports = {
process: (src, filename, options) => {
if (coffee.helpers.isCoffee(filename)) {
let js = coffee.compile(src, {
bare: true,
filename: filename,
inlineMap: true,
});
return babelJest.default.process(js, filename, options);
}
return src;
}
};
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This and only this:
Way easier than fiddling with a
transform
module