mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-15 22:07:09 +01:00
Merge pull request #87 from dorny/dart-error-message
Improve test error messages from flutter
This commit is contained in:
commit
3c4d3b3836
4 changed files with 37 additions and 6 deletions
|
|
@ -160,8 +160,11 @@ The test description was:
|
|||
pass updateShouldNotify
|
||||
════════════════════════════════════════════════════════════════════════════════════════════════════",
|
||||
"line": 112,
|
||||
"message": "Test failed. See exception logs above.
|
||||
The test description was: pass updateShouldNotify",
|
||||
"message": "The following TestFailure object was thrown running a test:
|
||||
Expected: <2>
|
||||
Actual: <1>
|
||||
Unexpected number of calls
|
||||
",
|
||||
"path": "test/value_listenable_provider_test.dart",
|
||||
},
|
||||
"name": "pass updateShouldNotify",
|
||||
|
|
|
|||
17
dist/index.js
generated
vendored
17
dist/index.js
generated
vendored
|
|
@ -512,14 +512,14 @@ class DartJsonParser {
|
|||
return undefined;
|
||||
}
|
||||
const { trackedFiles } = this.options;
|
||||
const message = (_b = (_a = test.error) === null || _a === void 0 ? void 0 : _a.error) !== null && _b !== void 0 ? _b : '';
|
||||
const stackTrace = (_d = (_c = test.error) === null || _c === void 0 ? void 0 : _c.stackTrace) !== null && _d !== void 0 ? _d : '';
|
||||
const stackTrace = (_b = (_a = test.error) === null || _a === void 0 ? void 0 : _a.stackTrace) !== null && _b !== void 0 ? _b : '';
|
||||
const print = test.print
|
||||
.filter(p => p.messageType === 'print')
|
||||
.map(p => p.message)
|
||||
.join('\n');
|
||||
const details = [print, stackTrace].filter(str => str !== '').join('\n');
|
||||
const src = this.exceptionThrowSource(details, trackedFiles);
|
||||
const message = this.getErrorMessage((_d = (_c = test.error) === null || _c === void 0 ? void 0 : _c.error) !== null && _d !== void 0 ? _d : '', print);
|
||||
let path;
|
||||
let line;
|
||||
if (src !== undefined) {
|
||||
|
|
@ -540,6 +540,19 @@ class DartJsonParser {
|
|||
details
|
||||
};
|
||||
}
|
||||
getErrorMessage(message, print) {
|
||||
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;
|
||||
}
|
||||
exceptionThrowSource(ex, trackedFiles) {
|
||||
const lines = ex.split(/\r?\n/g);
|
||||
// regexp to extract file path and line number from stack trace
|
||||
|
|
|
|||
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue