JestJS – JEST custom transformer – Can I improve their performance?

I am using Jest to test the performance of a custom transformer. Currently, the transformer only returns the code it gets from Jest. The transformer implements the getCacheKey function.

This is the complete code of 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 configuration in package.json is as follows:

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

Link to package.json

When using Jest to test this setting, it needs the same with and without –no-cache (about 9 seconds) Time

When using Mocha to test this setting, it takes about 7 seconds for the first run, and about 4 seconds for subsequent runs.

In two cases (using j est and mocha), test subsequent runs without changing any source or test files.

My question:

>Because of caching, subsequent Jest runs should not be faster NS?
>Are there any problems in the transformer that hinder the improvement of the test duration?
> Will Jest incur minimal overhead, which will cast a shadow over this problem?

It may be faster to update the fragments (fileData, filePath, configStr) separately, so there is no need to copy on the series File content.

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 the encoding is not provided, and the data is a string, the’utf8′ encoding is mandatory.

I am using Jest to test customization The performance of the transformer. Currently, the transformer will only return the code it obtains from Jest. The transformer implements the getCacheKey function.

This is the complete code of the transformer:

< /p>

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 configuration in package.json is as follows:

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

Link to package.json

When using Jest to test this setting, it takes the same time to use and not use –no-cache (about 9 seconds)

When using Mocha to test this setting, the first run takes about 7 seconds. The subsequent run takes about 4 seconds.

In both cases (using jest and mocha), test the subsequent run without changing any source or test files.

My Question:

>Because of caching, shouldn’t subsequent Jest run faster?
>Are there any problems in the transformer that hinder the improvement of the test duration?
> Will Jest incur minimal overhead, which will cast a shadow over this problem?

It may be faster to update the fragments (fileData, filePath, configStr) separately, so there is no need to copy the file content on the series.

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 not provided Encoding, and the data is a string, the’utf8′ encoding is mandatory.

Leave a Comment

Your email address will not be published.