Improve test error messages from flutter

For some reason the error message from flutter SDK might contain no useful information. Basically it just says that test failed and you should see the logs. Logs itself are provided as content of `print` event. This commit adds special processing for this behavior - it parses actual error message out of print event.
This commit is contained in:
Michal Dorner 2021-03-31 21:25:54 +02:00
parent 2c87efac07
commit ea36be4653
No known key found for this signature in database
GPG key ID: 9EEE04B48DA36786
4 changed files with 37 additions and 6 deletions

View file

@ -161,7 +161,6 @@ export class DartJsonParser implements TestParser {
}
const {trackedFiles} = this.options
const message = test.error?.error ?? ''
const stackTrace = test.error?.stackTrace ?? ''
const print = test.print
.filter(p => p.messageType === 'print')
@ -169,6 +168,7 @@ export class DartJsonParser implements TestParser {
.join('\n')
const details = [print, stackTrace].filter(str => str !== '').join('\n')
const src = this.exceptionThrowSource(details, trackedFiles)
const message = this.getErrorMessage(test.error?.error ?? '', print)
let path
let line
@ -191,6 +191,21 @@ export class DartJsonParser implements TestParser {
}
}
private getErrorMessage(message: string, print: string): string {
if (this.sdk === 'flutter') {
const uselessMessageRe = /^Test failed\. See exception logs above\.\nThe test description was:/m
const flutterPrintRe = /^ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK +\s+(.*)\s+When the exception was thrown, this was the stack:/ms
if (uselessMessageRe.test(message)) {
const match = print.match(flutterPrintRe)
if (match !== null) {
return match[1]
}
}
}
return message || print
}
private exceptionThrowSource(ex: string, trackedFiles: string[]): {path: string; line: number} | undefined {
const lines = ex.split(/\r?\n/g)