0
我可以使用'记者'的笑话配置方法来报告我的测试结果,但它显示了控制台上的所有报告。我想要的东西,它创建像.txt文件将Jest测试结果导出到txt
是否有可能做?
这是我的笑话配置;
"jest": {
"moduleNameMapper": {
"^.+\\.css$": "identity-obj-proxy"
},
"verbose": true,
"bail": true,
"reporters": [
"default",
"<rootDir>/__test__/my-custom-reporter.js"
]
}
and my-custom-reporter.js;
class MyCustomReporter {
constructor(globalConfig, options) {
this._globalConfig = globalConfig;
this._options = options;
}
onRunComplete(contexts, results) {
console.log('Custom reporter output:');
console.log('GlobalConfig: ', contexts);
console.log('Options: ', results);
}
onTestResult(test, testResult, aggregatedResult) {
console.log('onTestResult:');
console.log('test: ', test);
console.log('testResult: ', testResult);
console.log('aggregatedResult: ', aggregatedResult);
}
onRunStart(results, options) {
console.log('onRunStart:');
console.log('results: ', results);
console.log('Options: ', options);
}
onTestStart(test) {
console.log('onTestStart:');
console.log('test: ', test);
}
getLastError() {
if (this._shouldFail) {
return new Error('my-custom-reporter.js reported an error');
}
}
}
module.exports = MyCustomReporter;
您可以改为在调用'console.log'之上追加缓冲区,然后将缓冲区写入文件。或者运行测试并将控制台输出重定向到文件,例如'npm test> testlog.txt'。 – pawel