-
Notifications
You must be signed in to change notification settings - Fork 573
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1279 from snyk/fix/abridge-call-graph-error-message
fix: abridge call graph creation error messages in analytics
- Loading branch information
Showing
4 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export function abridgeErrorMessage( | ||
msg: string, | ||
maxLen: number, | ||
ellipsis?: string, | ||
): string { | ||
if (msg.length <= maxLen) { | ||
return msg; | ||
} | ||
const e = ellipsis || ' ... '; | ||
const toKeep = (maxLen - e.length) / 2; | ||
return msg.slice(0, toKeep) + e + msg.slice(msg.length - toKeep, msg.length); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { test } from 'tap'; | ||
import { abridgeErrorMessage } from '../src/lib/error-format'; | ||
|
||
test('abridge empty string', async (t) => { | ||
t.equal(abridgeErrorMessage('', 10), ''); | ||
}); | ||
|
||
test('abridge shorter than max length', async (t) => { | ||
t.equal(abridgeErrorMessage('hello', 10), 'hello'); | ||
}); | ||
|
||
test('abridge same length as max length', async (t) => { | ||
t.equal(abridgeErrorMessage('hello', 5), 'hello'); | ||
}); | ||
|
||
test('abridge longer than max length', async (t) => { | ||
t.equal(abridgeErrorMessage('hello there', 10), 'he ... ere'); | ||
}); | ||
|
||
test('abridge longer than max length (custom ellipsis)', async (t) => { | ||
t.equal(abridgeErrorMessage('hello there', 10, '--'), 'hell--here'); | ||
}); |