fix: handle edge case when formatting reporter titles #712
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I hereby confirm that I followed the code guidelines found at engineering guidelines
Affected Components
Notes for the Reviewer
The linked issue reports
checkly trigger
causing an out of bounds error. This appears to happen in a CI environment:This is caused by the terminal width being 0 in some CI environments (aws/aws-cdk#2253).
When we format the section title, we then get a negative number and cause this out of bounds error:
checkly-cli/packages/cli/src/reporters/util.ts
Line 234 in e1b75b6
To fix the issue, this PR uses
Math.max(..., 0)
to ensure that the padding length is always non-negative. When working on the PR, I also noticed that the formula doesn't take the indentation and extra left-side--
into account when calculating the right padding. This causes always 6 characters of wrap-around in the title (see first screenshot below). This PR also updates the calculation for the right padding to take this into account and avoid the wraparound (see second screenshot below).Before PR:

After PR:
