Skip to content

Commit 2e9ea3a

Browse files
committed
Fix control character regex patterns in test assertions
- Replace regex patterns with string methods for ANSI codes - Change .toMatch() to .toContain() for escape sequences - Improve test assertion readability
1 parent 729bebd commit 2e9ea3a

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

test/helpers/output-assertions.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ export function expectValidJson<T = unknown>(output: string): T {
389389
* ```
390390
*/
391391
export function expectNoAnsiCodes(output: string): void {
392-
const ansiPattern = /\u001b\[\d+m/
392+
const ansiPattern = /\x1B\[\d+m/
393393
expect(output).not.toMatch(ansiPattern)
394394
}
395395

test/utils/output-formatting-tables.test.mts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
/** @fileoverview Tests for table formatting utilities. */
22

3-
import type { TableColumn } from '@socketsecurity/registry/tables'
4-
import { formatSimpleTable, formatTable } from '@socketsecurity/registry/tables'
53
import { describe, expect, it } from 'vitest'
64
import colors from 'yoctocolors-cjs'
75

6+
import { formatSimpleTable, formatTable } from '@socketsecurity/registry/tables'
7+
8+
import type { TableColumn } from '@socketsecurity/registry/tables'
9+
810
describe('formatTable', () => {
911
it('should format empty data', () => {
1012
const columns: TableColumn[] = [{ key: 'name', header: 'Name' }]
@@ -92,7 +94,7 @@ describe('formatTable', () => {
9294

9395
// Should contain ANSI color codes
9496

95-
expect(result).toMatch(/\u001b\[/)
97+
expect(result).toContain('\u001b[')
9698
})
9799

98100
it('should handle missing values', () => {
@@ -202,7 +204,7 @@ describe('formatSimpleTable', () => {
202204

203205
// Should contain ANSI color codes
204206

205-
expect(result).toMatch(/\u001b\[/)
207+
expect(result).toContain('\u001b[')
206208
})
207209

208210
it('should handle missing values in simple tables', () => {

0 commit comments

Comments
 (0)