How to capture the arguments passed to a Jest transformer

Viewed 370

I have a Jest transformer that intercepts handlebar files, compiles them, and returns the template function.

const createCacheKeyFunction = require('fbjs-scripts/jest/createCacheKeyFunction')
const handlebars = require('handlebars')

module.exports = {
  process: (src, filename, config, options) => {
    const template = handlebars.compile(src)
    return `module.exports = (options) => ${JSON.stringify(template())}`
  },
  getCacheKey: createCacheKeyFunction([__filename])
}

This works superficially and it's "good enough" for my testing but in reality the template() method it returns accepts a parameter (in this case, whatever the calling function passes into options). Obviously the parameter changes the output of based on this parameter. Now I realize that mocks shouldn't build out complete functionality... BUT.. is there a way to capture the data being passed into options and pass it into the stringified call to template()?

0 Answers
Related