|
5 | 5 |
|
6 | 6 | import * as assert from 'assert'
|
7 | 7 | import {
|
| 8 | + collectAcceptedErrorMessages, |
8 | 9 | logAndThrowIfUnexpectedExitCode,
|
9 | 10 | makeUnexpectedExitCodeError,
|
10 | 11 | } from '../../../../shared/sam/cli/samCliInvokerUtils'
|
@@ -42,3 +43,41 @@ describe('logAndThrowIfUnexpectedExitCode', async function () {
|
42 | 43 | await assertLogContainsBadExitInformation(getTestLogger(), childProcessResult, 456)
|
43 | 44 | })
|
44 | 45 | })
|
| 46 | + |
| 47 | +/** |
| 48 | + * Returns a string with the 'Escape' character |
| 49 | + * prepended to the given text. |
| 50 | + * |
| 51 | + * This exists because using '\e' does not |
| 52 | + * work. |
| 53 | + */ |
| 54 | +function prependEscapeCode(text: string): string { |
| 55 | + return String.fromCharCode(27) + text |
| 56 | +} |
| 57 | + |
| 58 | +describe('collectAcceptedErrorMessages()', async () => { |
| 59 | + let result: string[] |
| 60 | + |
| 61 | + before(async () => { |
| 62 | + const input = [ |
| 63 | + prependEscapeCode('[33m This is an accepted escape sequence'), |
| 64 | + prependEscapeCode('[100m This is not an accepted escape sequence'), |
| 65 | + 'This will be ignored', |
| 66 | + 'Error: This is accepted due to the prefix', |
| 67 | + ].join('\n') |
| 68 | + result = collectAcceptedErrorMessages(input) |
| 69 | + }) |
| 70 | + |
| 71 | + it('has the expected amount of messages', async () => { |
| 72 | + assert.strictEqual(result.length, 2) |
| 73 | + }) |
| 74 | + it('collects the "Error:" prefix', async () => { |
| 75 | + assert(result.includes('Error: This is accepted due to the prefix')) |
| 76 | + }) |
| 77 | + it('collects accepted escape sequence prefixes', async () => { |
| 78 | + assert(result.includes(prependEscapeCode('[33m This is an accepted escape sequence'))) |
| 79 | + }) |
| 80 | + it('ignores non-accepted escape sequence prefixes', async () => { |
| 81 | + assert(!result.includes(prependEscapeCode('[100m This is not an accepted escape sequence'))) |
| 82 | + }) |
| 83 | +}) |
0 commit comments