Jest custom transformer - can its performance be improved?

Viewed 1507

I'm testing the performance of a custom transformer with Jest. Currently, the transformer does nothing but return the code that it gets from Jest. The transformer has implemented the getCacheKey function.

Here's the entire code for the transformer:

function process(src, path, config, transformOptions) {
  return src;
}
exports.process = process;

function getCacheKey(fileData, filePath, configStr, options) {
  return crypto.createHash('md5')
    .update(fileData + filePath + configStr, 'utf8')
    .digest('hex');
}
exports.getCacheKey = getCacheKey;

Link to the transformer

The jest config, in package.json is as follows:

"jest": {
  "transform": {
    "^.+\\.tsx?$": "<rootDir>/ts-transformer.js"
  },
  "testMatch": [
    "<rootDir>/test-jest/**/*.ts"
  ],
  "moduleFileExtensions": [
    "ts",
    "tsx",
    "js",
    "json"
  ]
}

Link to package.json

When testing this setup with Jest, it takes the same amount of time with and without --no-cache (around 9 seconds)

When testing this setup with Mocha, the first run takes around 7 seconds and subsequent runs take around 4 seconds.

In both cases (with jest and mocha), the subsequent runs were tested without changing any source or test file.

My questions:

  • Shouldn't subsequent Jest runs be faster due to caching?
  • Is there something in the transformer that is preventing an improvement in the testing duration?
  • Is there a minimum overhead that Jest incurs which is clouding this issue?
1 Answers
Related