看起来所有内置的报告程序都使用不同数量的行描述错误。而为这种类型的报告构建VSCode问题匹配器是不受支持的 - 多行支持非常有限。
但我们可以根据自己喜欢的格式构建自己的报告程序,然后轻松地进行匹配!
这里是一个简单的报告程序,它扩展了默认的Spec报告程序,输出与$tsc-watch匹配器兼容的错误格式:
var StackTraceParser = require('stacktrace-parser');
var path = require('path');
var mocha = require('mocha');
module.exports = MyReporter;
function MyReporter(runner) {
mocha.reporters.Spec.call(this, runner);
runner.on('fail', function(test, err){
var lines = StackTraceParser.parse(err.stack)
var line = lines.find(line => line.file.startsWith('test'))
if (line) {
console.log(`${line.file}(${line.lineNumber},${line.column}): error TS0000: ${err.message.split('\n')[0]}`)
}
});
}
mocha.utils.inherits(MyReporter, mocha.reporters.Spec);
在
package.json
文件的
scripts
部分中添加命令:
"test": "mocha --reporter my-reporter.js"
然后您需要在tasks.json
中添加:
{
"type": "npm",
"script": "test",
"problemMatcher": [
{
"applyTo": "allDocuments",
"fileLocation": "relative",
"base": "$tsc-watch",
"source": "mocha"
}
],
"group": {
"kind": "test",
"isDefault": true
}
}
Error: Cannot find module 'stacktrace-parser'
的错误信息。有什么想法吗? - Zach