【发布时间】:2017-07-29 01:11:09
【问题描述】:
我正在使用 Jest 测试自定义变压器的性能。目前,transformer 只返回从 Jest 获得的代码。 Transformer 实现了getCacheKey 函数。
这是转换器的完整代码:
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;
package.json 中的笑话配置如下:
"jest": {
"transform": {
"^.+\\.tsx?$": "<rootDir>/ts-transformer.js"
},
"testMatch": [
"<rootDir>/test-jest/**/*.ts"
],
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"json"
]
}
使用 Jest 测试此设置时,使用和不使用 --no-cache 所需的时间相同(大约 9 秒)
使用 Mocha 测试此设置时,第一次运行大约需要 7 秒,后续运行大约需要 4 秒。
在这两种情况下(使用 jest 和 mocha),后续运行都在不更改任何源或测试文件的情况下进行了测试。
我的问题:
- 由于缓存,后续 Jest 运行不应该更快吗?
- 变压器中是否有什么东西阻碍了测试持续时间的改进?
- Jest 产生的最小开销是否会影响这个问题?
【问题讨论】:
标签: jestjs