|
| 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