From f6f6b3439b16af9183e1629c516b26087c9517a0 Mon Sep 17 00:00:00 2001 From: Pamella Bezerra Date: Mon, 8 Jan 2024 12:34:38 -0300 Subject: [PATCH] Add unit tests --- lib/utils/tests/stripAnsi.test.js | 48 +++++++++++++++++++++++++++++++ tsconfig.json | 2 +- 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 lib/utils/tests/stripAnsi.test.js diff --git a/lib/utils/tests/stripAnsi.test.js b/lib/utils/tests/stripAnsi.test.js new file mode 100644 index 0000000..288aa3a --- /dev/null +++ b/lib/utils/tests/stripAnsi.test.js @@ -0,0 +1,48 @@ +/* eslint-env jest */ +'use strict'; + +const stripAnsi = require('../stripAnsi'); + +describe('stripAnsi tests', () => { + it('It should handle an empty string', () => { + const output = stripAnsi(''); + expect(output).toBe(''); + }); + + it('It should return the same string if there are no ANSI codes', () => { + const input = 'Hello'; + const output = stripAnsi(input); + expect(output).toBe('Hello'); + }); + + it('It should remove ANSI codes from a string', () => { + const input = '\u001B[4mHello\u001B[0m'; + const output = stripAnsi(input); + expect(output).toBe('Hello'); + }); + + it('It should strip color from string', () => { + const input = '\u001B[0m\u001B[4m\u001B[42m\u001B[31mHe\u001B[39m\u001B[49m\u001B[24mllo\u001B[0m'; + const output = stripAnsi(input); + expect(output).toBe('Hello'); + }); + + it('It should strip color from ls command', () => { + const input = + '\u001B[00m\u001B[01;34mHello\u001B[00m'; + const output = stripAnsi(input); + expect(output).toBe('Hello'); + }); + + it('It should reset;setfg;setbg;italics;strike;underline sequence from string', () => { + const input = '\u001B[0;33;49;3;9;4mHello\u001B[0m'; + const output = stripAnsi(input); + expect(output).toBe('Hello'); + }); + + it('It should strip link from terminal link', () => { + const input = '\u001B]8;;https://github.com\u0007click\u001B]8;;\u0007'; + const output = stripAnsi(input); + expect(output).toBe('click'); + }); +}); diff --git a/tsconfig.json b/tsconfig.json index ca34c20..e5d289c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -33,7 +33,7 @@ "spec", "examples", "dist", - "tests", + "**/tests", "coverage" ] }