1 var Stream = require('stream')
2 var tap = require('tap')
3 var MS = require('../mute.js')
10 function PassThrough () {
12 this.readable = this.writable = true
15 PassThrough.prototype = Object.create(Stream.prototype, {
43 tap.test('incoming', function (t) {
45 var str = new PassThrough
48 var expect = ['foo', 'boo', END]
49 ms.on('data', function (c) {
50 t.equal(c, expect.shift())
52 ms.on('end', function () {
53 t.equal(END, expect.shift())
66 tap.test('outgoing', function (t) {
68 var str = new PassThrough
71 var expect = ['foo', 'boo', END]
72 str.on('data', function (c) {
73 t.equal(c, expect.shift())
75 str.on('end', function () {
76 t.equal(END, expect.shift())
90 tap.test('isTTY', function (t) {
91 var str = new PassThrough
97 t.equal(ms.isTTY, false)
98 t.equal(ms.columns, undefined)
99 t.equal(ms.rows, undefined)
101 t.equal(ms.isTTY, true)
102 t.equal(ms.columns, 80)
105 t.equal(ms.isTTY, false)
106 t.equal(ms.columns, 80)
109 t.equal(ms.isTTY, true)
110 t.equal(ms.columns, 80)
113 t.equal(ms.isTTY, false)
114 t.equal(ms.columns, 80)
118 t.equal(ms.isTTY, false)
120 t.equal(ms.isTTY, true)
122 t.equal(ms.isTTY, false)
124 t.equal(ms.isTTY, true)
126 t.equal(ms.isTTY, false)
131 tap.test('pause/resume incoming', function (t) {
132 var str = new PassThrough
134 str.on('pause', function () {
135 t.equal(PAUSE, expect.shift())
137 str.on('resume', function () {
138 t.equal(RESUME, expect.shift())
140 var expect = [PAUSE, RESUME, PAUSE, RESUME]
146 t.equal(expect.length, 0, 'saw all events')
150 tap.test('replace with *', function (t) {
151 var str = new PassThrough
152 var ms = new MS({replace: '*'})
154 var expect = ['foo', '*****', 'bar', '***', 'baz', 'boo', '**', '****']
156 ms.on('data', function (c) {
157 t.equal(c, expect.shift())
174 t.equal(expect.length, 0)
178 tap.test('replace with ~YARG~', function (t) {
179 var str = new PassThrough
180 var ms = new MS({replace: '~YARG~'})
182 var expect = ['foo', '~YARG~~YARG~~YARG~~YARG~~YARG~', 'bar',
183 '~YARG~~YARG~~YARG~', 'baz', 'boo', '~YARG~~YARG~',
184 '~YARG~~YARG~~YARG~~YARG~']
186 ms.on('data', function (c) {
187 t.equal(c, expect.shift())
190 // also throw some unicode in there, just for good measure.
205 t.equal(expect.length, 0)