Permalink
Browse files

the test

  • Loading branch information...
1 parent 142b919 commit e549acc4a193349812725eea14198d720b3bb43a @isaacs isaacs committed Jul 24, 2012
Showing with 135 additions and 0 deletions.
  1. +135 −0 test/basic.js
View
@@ -0,0 +1,135 @@
+var Stream = require('stream')
+var tap = require('tap')
+var MS = require('../mute.js')
+
+// some marker objects
+var END = {}
+var PAUSE = {}
+var RESUME = {}
+
+function PassThrough () {
+ Stream.call(this)
+ this.readable = this.writable = true
+}
+
+PassThrough.prototype = Object.create(Stream.prototype, {
+ constructor: {
+ value: PassThrough
+ },
+ write: {
+ value: function (c) {
+ this.emit('data', c)
+ }
+ },
+ end: {
+ value: function (c) {
+ if (c) this.write(c)
+ this.emit('end')
+ }
+ },
+ pause: {
+ value: function () {
+ this.emit('pause')
+ }
+ },
+ resume: {
+ value: function () {
+ this.emit('resume')
+ }
+ }
+})
+
+tap.test('incoming', function (t) {
+ var ms = new MS
+ var str = new PassThrough
+ str.pipe(ms)
+
+ var expect = ['foo', 'boo', END]
+ ms.on('data', function (c) {
+ t.equal(c, expect.shift())
+ })
+ ms.on('end', function () {
+ t.equal(END, expect.shift())
+ t.end()
+ })
+ str.write('foo')
+ ms.mute()
+ str.write('bar')
+ ms.unmute()
+ str.write('boo')
+ ms.mute()
+ str.write('blaz')
+ str.end('grelb')
+})
+
+tap.test('outgoing', function (t) {
+ var ms = new MS
+ var str = new PassThrough
+ ms.pipe(str)
+
+ var expect = ['foo', 'boo', END]
+ str.on('data', function (c) {
+ t.equal(c, expect.shift())
+ })
+ str.on('end', function () {
+ t.equal(END, expect.shift())
+ t.end()
+ })
+
+ ms.write('foo')
+ ms.mute()
+ ms.write('bar')
+ ms.unmute()
+ ms.write('boo')
+ ms.mute()
+ ms.write('blaz')
+ ms.end('grelb')
+})
+
+tap.test('isTTY', function (t) {
+ var str = new PassThrough
+ str.isTTY = true
+
+ var ms = new MS
+ t.equal(ms.isTTY, false)
+ ms.pipe(str)
+ t.equal(ms.isTTY, true)
+ str.isTTY = false
+ t.equal(ms.isTTY, false)
+ str.isTTY = true
+ t.equal(ms.isTTY, true)
+ ms.isTTY = false
+ t.equal(ms.isTTY, false)
+
+ ms = new MS
+ t.equal(ms.isTTY, false)
+ str.pipe(ms)
+ t.equal(ms.isTTY, true)
+ str.isTTY = false
+ t.equal(ms.isTTY, false)
+ str.isTTY = true
+ t.equal(ms.isTTY, true)
+ ms.isTTY = false
+ t.equal(ms.isTTY, false)
+
+ t.end()
+})
+
+tap.test('pause/resume incoming', function (t) {
+ var str = new PassThrough
+ var ms = new MS
+ str.on('pause', function () {
+ t.equal(PAUSE, expect.shift())
+ })
+ str.on('resume', function () {
+ t.equal(RESUME, expect.shift())
+ })
+ var expect = [PAUSE, RESUME, PAUSE, RESUME]
+ str.pipe(ms)
+ ms.pause()
+ ms.resume()
+ ms.pause()
+ ms.resume()
+ t.equal(expect.length, 0, 'saw all events')
+ t.end()
+})

0 comments on commit e549acc

Please sign in to comment.