Skip to content

Commit

Permalink
fix: highlight only error indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
syzzana committed Nov 25, 2023
1 parent 57e2982 commit f90e54a
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/testResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,21 +187,18 @@ export const logFailedTests = (failedTests: TestCaseError[]) => {
log(error.value);
}
if(error.snippet !== undefined) {
const highlightedError = highlightErrorInCode(error.snippet);
const highlightedError = highlightErrorIndicator(error.snippet);
log(highlightedError);
}
log(`\t${Color.text('at').gray().valueOf()} ${error.location.file}:${error.location.line}:${error.location.column}`);
});
};

export const highlightErrorInCode = (codeSnippet: string): string => {
export const highlightErrorIndicator = (codeSnippet: string): string => {
const lines = codeSnippet.split("\n");
const lineWithError = lines.find((line) => line.includes(">"));
const errorIndicator = lines.find((line) => line.includes("^"));
const indexOfLineWithError = lines.indexOf(lineWithError);
const indexOfErrorIndicator = lines.indexOf(errorIndicator);
lines[indexOfLineWithError+1] = Color.text(lineWithError).red().valueOf();
lines[indexOfErrorIndicator+1] = Color.text(errorIndicator).red().valueOf();
const errorIndicator = lines.find((line) => line.includes("^"));
const indexOfErrorIndicator = lines.indexOf(errorIndicator);
lines[indexOfErrorIndicator+1] = Color.text(errorIndicator).red().valueOf();

return lines.join("\n");
};
Expand Down

0 comments on commit f90e54a

Please sign in to comment.