Skip to content

Commit fbab566

Browse files
committed
test: redlint: test: strip
1 parent d753237 commit fbab566

2 files changed

Lines changed: 31 additions & 33 deletions

File tree

lib/test/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export const test = (filesystem, overrides = {}) => {
8888
log(codeFrameColumns(correct, {}, {
8989
highlightCode: true,
9090
}));
91-
log('');
91+
log(' ');
9292
log(`## ❌ Received\n`);
9393
log(codeFrameColumns(transformed, {}, {
9494
highlightCode: true,

lib/test/test.spec.js

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {stripVTControlCharacters} from 'node:util';
2-
import {test} from 'supertape';
2+
import {extend} from 'supertape';
33
import {create} from '@putout/processor-filesystem/create';
44
import montag from 'montag';
55
import {test as redlintTest} from './test.js';
@@ -8,6 +8,19 @@ const {branch} = create({
88
cli: false,
99
});
1010

11+
const trim = (a) => a.trimEnd();
12+
const test = extend({
13+
equalStripped: (operator) => (a, b) => {
14+
const result = stripVTControlCharacters(a)
15+
.split('\n')
16+
.map(trim)
17+
.filter(Boolean)
18+
.join('\n');
19+
20+
return operator.equal(result, b);
21+
},
22+
});
23+
1124
const {stringify} = JSON;
1225

1326
test('redlint: test', (t) => {
@@ -79,12 +92,10 @@ test('redlint: test: success', (t) => {
7992
});
8093

8194
const expected = montag`
82-
8395
# 🍀 hello
84-
8596
`;
8697

87-
t.equal(result, expected);
98+
t.equalStripped(result, expected);
8899
t.end();
89100
});
90101

@@ -116,27 +127,20 @@ test('redlint: test: no files', (t) => {
116127
});
117128

118129
const expected = montag`
119-
120-
# 🍄 hello
121-
122-
## ✅ Expected
123-
124-
\x1b[0m \x1b[90m 1 |\x1b[39m
125-
\x1b[90m 2 |\x1b[39m __putout_processor_filesystem([
126-
\x1b[90m 3 |\x1b[39m \x1b[32m'/'\x1b[39m\x1b[33m,\x1b[39m
127-
\x1b[90m 4 |\x1b[39m \x1b[32m'/hello.txt'\x1b[39m\x1b[33m,\x1b[39m
128-
\x1b[90m 5 |\x1b[39m ])\x1b[33m;\x1b[39m
129-
\x1b[90m 6 |\x1b[39m \x1b[0m
130-
130+
# 🍄 hello
131+
## ✅ Expected
132+
1 |
133+
2 | __putout_processor_filesystem([
134+
3 | '/',
135+
4 | '/hello.txt',
136+
5 | ]);
137+
6 |
131138
## ❌ Received
132-
133-
\x1b[0m \x1b[90m 1 |\x1b[39m __putout_processor_filesystem([\x1b[32m"/"\x1b[39m])\x1b[33m;\x1b[39m
134-
\x1b[90m 2 |\x1b[39m\x1b[0m
135-
136-
139+
1 | __putout_processor_filesystem(["/"]);
140+
2 |
137141
`;
138142

139-
t.equal(result, expected);
143+
t.equalStripped(result, expected);
140144
t.end();
141145
});
142146

@@ -169,17 +173,13 @@ test('redlint: test: diff', (t) => {
169173
});
170174

171175
const expected = montag`
172-
173176
# 🍄 hello
174-
175177
## /hello.txt:1
176-
177-
\x1b[32m- world\x1b[39m
178-
\x1b[31m+ hello\x1b[39m
179-
178+
- world
179+
+ hello
180180
`;
181181

182-
t.equal(result, expected);
182+
t.equalStripped(result, expected);
183183
t.end();
184184
});
185185

@@ -214,12 +214,10 @@ test('redlint: test: same files', (t) => {
214214
const stripped = stripVTControlCharacters(result);
215215

216216
const expected = montag`
217-
218217
# 🍀 hello
219-
220218
`;
221219

222-
t.equal(stripped, expected);
220+
t.equalStripped(stripped, expected);
223221
t.end();
224222
});
225223

0 commit comments

Comments
 (0)