Skip to content

Instantly share code, notes, and snippets.

@mutewinter
Created October 4, 2016 21:28
Show Gist options
  • Save mutewinter/4024a569c70d7dda87a6b22a194d0d11 to your computer and use it in GitHub Desktop.
Save mutewinter/4024a569c70d7dda87a6b22a194d0d11 to your computer and use it in GitHub Desktop.
Use Jest with CoffeeScript
{
"jest": {
"moduleFileExtensions": [
"js",
"json",
"jsx",
"node",
"coffee"
],
"preprocessorIgnorePatterns": [ ],
"scriptPreprocessor": "<rootDir>/test/preprocessor.js"
}
}
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;
}
};
@dima4p
Copy link

dima4p commented Jan 21, 2022

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