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