Skip to content

Commit d48c46f

Browse files
committed
cleaner tests
1 parent 2195720 commit d48c46f

File tree

6 files changed

+45
-4
lines changed

6 files changed

+45
-4
lines changed

packages/inquirerer/__tests__/__snapshots__/autocomplete.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

33
exports[`Inquirerer prompts user and correctly processes delayed input 1`] = `
44
{

packages/inquirerer/__tests__/__snapshots__/prompt.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

33
exports[`Inquirerer checkbox 1`] = `
44
{

packages/inquirerer/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,8 @@
3434
"js-yaml": "^4.1.0",
3535
"minimist": "^1.2.8"
3636
},
37-
"keywords": []
37+
"keywords": [],
38+
"devDependencies": {
39+
"@types/minimist": "^1.2.5"
40+
}
3841
}

packages/inquirerer/test-utils/setup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import readline from 'readline';
22
import { Readable, Transform, Writable } from 'stream';
3-
import stripAnsi from 'strip-ansi';
3+
import { stripAnsi } from './strip-ansi';
44

55
import { CLIOptions } from '../src';
66

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// stripAnsi.ts
2+
/**
3+
* Remove ANSI escape codes from a string.
4+
* Handles:
5+
* - CSI sequences: \u001b[... (color codes, cursor movement, etc.)
6+
* - OSC sequences: \u001b]... (OS commands like window title)
7+
* - Other escape sequences: \u001b followed by single characters
8+
*/
9+
export function stripAnsi(input: string): string {
10+
if (!input) return '';
11+
12+
// Match CSI (Control Sequence Introducer) sequences: ESC[ followed by parameters and final character
13+
// Examples: \u001b[31m, \u001b[A, \u001b[2J, \u001b[?25h
14+
const csiPattern = /\u001b\[[0-9;?]*[A-Za-z]/g;
15+
16+
// Match OSC (Operating System Command) sequences: ESC] followed by parameters and terminator
17+
// Terminated by BEL (\u0007) or ESC\ (\u001b\\)
18+
// Examples: \u001b]0;title\u0007, \u001b]2;title\u001b\\
19+
// Handle BEL-terminated sequences
20+
const oscBelPattern = /\u001b\][^\u0007]*\u0007/g;
21+
// Handle ESC\-terminated sequences (more complex, need to match ESC\ specifically)
22+
const oscEscPattern = /\u001b\][^\u001b]*\u001b\\/g;
23+
24+
// Match other escape sequences: ESC followed by single character
25+
// Examples: \u001bD (index), \u001bM (reverse index), \u001b7 (save cursor), \u001b8 (restore cursor)
26+
const otherEscPattern = /\u001b[0-9A-Za-z]/g;
27+
28+
return input
29+
.replace(csiPattern, '')
30+
.replace(oscBelPattern, '')
31+
.replace(oscEscPattern, '')
32+
.replace(otherEscPattern, '');
33+
}
34+

pnpm-lock.yaml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)