Skip to content

Commit 847e07f

Browse files
committed
test: add color tag tests
The majority of the uses of strong-log-transformer are for prefixing console output from multiple processes with a child process identifier and almost all of them make use of ANSI escape codes in the tags so that the output is suitably colorful. Since that's a common use, these tests will ensure that the current behaviour doesn't accidentally change. Signed-off-by: Ryan Graham <[email protected]>
1 parent ea070ed commit 847e07f

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

test/test-ansi-color-tags.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
var tap = require('tap');
2+
var Log = require('../');
3+
4+
tap.test('tag object with ansi escape codes', function(t) {
5+
var slt = Log({
6+
tag: {
7+
blue: '\u001b[1m\u001b[34mblue\u001b[39m\u001b[22m',
8+
green: '\u001b[32mgreen\u001b[39m',
9+
},
10+
});
11+
var input = [
12+
'good line',
13+
'good line',
14+
'good line',
15+
];
16+
var expected = input.map(function(line) {
17+
return 'blue:\u001b[1m\u001b[34mblue\u001b[39m\u001b[22m green:\u001b[32mgreen\u001b[39m ' + line + '\n';
18+
}).join('');
19+
var received = '';
20+
21+
slt.on('data', function(buf) {
22+
t.comment(buf);
23+
if (Buffer.isBuffer(buf)) {
24+
received += buf.toString('utf8');
25+
} else if (buf !== null) {
26+
received += buf;
27+
}
28+
});
29+
slt.on('end', function() {
30+
t.same(received, expected, 'output is input + trailing newline');
31+
t.end();
32+
});
33+
slt.write(input.join('\n'));
34+
slt.end();
35+
});
36+
37+
tap.test('tag string with ansi escape codes', function(t) {
38+
var slt = Log({
39+
tag: '\u001b[1m\u001b[34mblue\u001b[39m\u001b[22m',
40+
});
41+
var input = [
42+
'good line',
43+
'good line',
44+
'good line',
45+
];
46+
var expected = input.map(function(line) {
47+
return '\u001b[1m\u001b[34mblue\u001b[39m\u001b[22m ' + line + '\n';
48+
}).join('');
49+
var received = '';
50+
51+
slt.on('data', function(buf) {
52+
t.comment(buf);
53+
if (Buffer.isBuffer(buf)) {
54+
received += buf.toString('utf8');
55+
} else if (buf !== null) {
56+
received += buf;
57+
}
58+
});
59+
slt.on('end', function() {
60+
t.same(received, expected, 'output is input + trailing newline');
61+
t.end();
62+
});
63+
slt.write(input.join('\n'));
64+
slt.end();
65+
});

0 commit comments

Comments
 (0)