Skip to content

Commit

Permalink
Bugfix for "Error: TypeError: Cannot read properties of undefined (re…
Browse files Browse the repository at this point in the history
…ading 'trim')" (#18)

* More robust output cleaning

* added comment
  • Loading branch information
MicheleTogni authored May 25, 2022
1 parent 7642c8e commit c07a362
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/utils/tests_parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ export interface ParseOutput {
// Used by load method, does not evaluate whether tests have passed/failed.
export function parseMixOutput(projectDir: string, stdout: string): Map<string, ParseOutput> {
const testsMap = new Map<string, ParseOutput>();
const tests = stdout
.split('Including tags: [:""]')[1] // compilation and other noise before

const cleanOutput = cleanupOutput(stdout);

const tests = cleanOutput
.trim()
.split('\n\n') // tests grouped per files
.map((string) => string.split('\n').filter((string) => string)) // sometimes there are no tests, like an empty doctest
Expand Down Expand Up @@ -64,3 +66,10 @@ export function parseMixOutput(projectDir: string, stdout: string): Map<string,

return testsMap;
}
function cleanupOutput(stdout: string) {
const patternBeforeMeaningfulOutput = /Including tags: \[.*?]/; //we look for a pattern, in order to accomodate for variations (eg :"" and :*)
const indexBeforeMeaningfulOutput = Math.max(stdout.search(patternBeforeMeaningfulOutput), 0);
const meaningfulString = stdout.substring(indexBeforeMeaningfulOutput);
return meaningfulString;
}

0 comments on commit c07a362

Please sign in to comment.