jestjs - Jest custom transformer - can its performance be improved? -
i'm testing performance of custom transformer jest. currently, transformer nothing return code gets jest. transformer has implemented getcachekey function.
here's entire code 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; the jest config, in package.json follows:
"jest": { "transform": { "^.+\\.tsx?$": "<rootdir>/ts-transformer.js" }, "testmatch": [ "<rootdir>/test-jest/**/*.ts" ], "modulefileextensions": [ "ts", "tsx", "js", "json" ] } when testing setup jest, takes same amount of time , without --no-cache (around 9 seconds)
when testing setup mocha, first run takes around 7 seconds , subsequent runs take around 4 seconds.
in both cases (with jest , mocha), subsequent runs tested without changing source or test file.
my questions:
- shouldn't subsequent jest runs faster due caching?
- is there in transformer preventing improvement in testing duration?
- is there minimum overhead jest incurs clouding issue?
it might faster update pieces (filedata, filepath, configstr) separately there not have copy of file contents on concatenation.
function getcachekey(filedata, filepath, configstr, options) { const hash = crypto.createhash('md5'); hash.update(filedata); hash.update(filepath); hash.update(configstr); return hash.digest('hex'); } note: if encoding not provided, , data string, encoding of 'utf8' enforced.
Comments
Post a Comment