Skip to content

Commit 7ac8d9d

Browse files
committed
test: update tests to handle colors from code-frame package
1 parent d5fed3e commit 7ac8d9d

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

test/unit/formatter/code-frame-formatter.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import mockFs from 'mock-fs';
44
import { createCodeFrameFormatter } from 'src/formatter';
55
import type { Issue } from 'src/issue';
66

7+
import { stripAnsi } from './strip-ansi';
8+
79
describe('formatter/code-frame-formatter', () => {
810
beforeEach(() => {
911
mockFs({
@@ -103,7 +105,7 @@ describe('formatter/code-frame-formatter', () => {
103105
linesAbove: 1,
104106
linesBelow: 1,
105107
});
106-
const formatted = formatter(issue);
108+
const formatted = stripAnsi(formatter(issue));
107109

108110
expect(formatted).toEqual(expectedFormatted);
109111
});

test/unit/formatter/formatter-config.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import type { FormatterOptions } from 'src/formatter';
55
import { createFormatterConfig } from 'src/formatter';
66
import type { Issue } from 'src/issue';
77

8+
import { stripAnsi } from './strip-ansi';
9+
810
describe('formatter/formatter-config', () => {
911
beforeEach(() => {
1012
mockFs({
@@ -79,8 +81,9 @@ describe('formatter/formatter-config', () => {
7981
[{ type: 'codeframe', pathType: 'absolute' }, CODEFRAME_FORMATTER_OUTPUT, 'absolute'],
8082
])('creates configuration from options', (options, expectedFormat, expectedPathType) => {
8183
const formatter = createFormatterConfig(options as FormatterOptions);
84+
const format = stripAnsi(formatter.format(issue));
8285

83-
expect(formatter.format(issue)).toEqual(expectedFormat);
86+
expect(format).toEqual(expectedFormat);
8487
expect(formatter.pathType).toEqual(expectedPathType);
8588
});
8689
});

test/unit/formatter/strip-ansi.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Removes ANSI escape codes from a string
2+
// eslint-disable-next-line no-control-regex
3+
export const stripAnsi = (text: string) => text.replace(/\u001b[^m]*?m/g, '');

0 commit comments

Comments
 (0)