I am testing the performance of a custom transformer using Jest. Currently, the transformer does nothing but return the code it receives from Jest. The transformer has implemented a function getCacheKey.
Here is the whole 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;
Transformer Link
Jest's configuration is package.jsonas 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(about 9 seconds)
When testing this setup with Mocha, the first run takes about 7 seconds, and subsequent runs about 4 seconds.
( ) - .
: