|
| 1 | +/* eslint-env jest */ |
| 2 | +'use strict'; |
| 3 | + |
| 4 | +const stripAnsi = require('../stripAnsi'); |
| 5 | + |
| 6 | +describe('stripAnsi tests', () => { |
| 7 | + it('It should handle an empty string', () => { |
| 8 | + const output = stripAnsi(''); |
| 9 | + expect(output).toBe(''); |
| 10 | + }); |
| 11 | + |
| 12 | + it('It should return the same string if there are no ANSI codes', () => { |
| 13 | + const input = 'Hello'; |
| 14 | + const output = stripAnsi(input); |
| 15 | + expect(output).toBe('Hello'); |
| 16 | + }); |
| 17 | + |
| 18 | + it('It should remove ANSI codes from a string', () => { |
| 19 | + const input = '\u001B[4mHello\u001B[0m'; |
| 20 | + const output = stripAnsi(input); |
| 21 | + expect(output).toBe('Hello'); |
| 22 | + }); |
| 23 | + |
| 24 | + it('It should strip color from string', () => { |
| 25 | + const input = '\u001B[0m\u001B[4m\u001B[42m\u001B[31mHe\u001B[39m\u001B[49m\u001B[24mllo\u001B[0m'; |
| 26 | + const output = stripAnsi(input); |
| 27 | + expect(output).toBe('Hello'); |
| 28 | + }); |
| 29 | + |
| 30 | + it('It should strip color from ls command', () => { |
| 31 | + const input = |
| 32 | + '\u001B[00m\u001B[01;34mHello\u001B[00m'; |
| 33 | + const output = stripAnsi(input); |
| 34 | + expect(output).toBe('Hello'); |
| 35 | + }); |
| 36 | + |
| 37 | + it('It should reset;setfg;setbg;italics;strike;underline sequence from string', () => { |
| 38 | + const input = '\u001B[0;33;49;3;9;4mHello\u001B[0m'; |
| 39 | + const output = stripAnsi(input); |
| 40 | + expect(output).toBe('Hello'); |
| 41 | + }); |
| 42 | + |
| 43 | + it('It should strip link from terminal link', () => { |
| 44 | + const input = '\u001B]8;;https://github.com\u0007click\u001B]8;;\u0007'; |
| 45 | + const output = stripAnsi(input); |
| 46 | + expect(output).toBe('click'); |
| 47 | + }); |
| 48 | +}); |
0 commit comments