Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve test error messages from flutter #87

Merged
merged 1 commit into from
Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions __tests__/__snapshots__/dart-json.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 15 additions & 2 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

17 changes: 16 additions & 1 deletion src/parsers/dart-json/dart-json-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,14 @@ 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')
.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(test.error?.error ?? '', print)
let path
let line

Expand All @@ -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)

Expand Down