Skip to content

Commit

Permalink
tests: add stream option tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Apr 17, 2017
1 parent d265d9f commit fb33e99
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions test/morgan.js
Expand Up @@ -139,6 +139,56 @@ describe('morgan()', function () {
})
})
})

describe('stream', function () {
beforeEach(function () {
this.stdout = process.stdout
})

afterEach(function () {
Object.defineProperty(process, 'stdout', {
value: this.stdout
})
})

it('should default to process.stdout', function (done) {
var cb = after(2, function (err, res, line) {
if (err) return done(err)
assert(res.text.length > 0)
assert.equal(line.substr(0, res.text.length), res.text)
done()
})

var stream = createLineStream(function (line) {
cb(null, null, line)
})

Object.defineProperty(process, 'stdout', {
value: stream
})

request(createServer(undefined, { stream: undefined }))
.get('/')
.expect(200, cb)
})

it('should set stream to write logs to', function (done) {
var cb = after(2, function (err, res, line) {
if (err) return done(err)
assert(res.text.length > 0)
assert.equal(line.substr(0, res.text.length), res.text)
done()
})

var stream = createLineStream(function (line) {
cb(null, null, line)
})

request(createServer(undefined, { stream: stream }))
.get('/')
.expect(200, cb)
})
})
})

describe('tokens', function () {
Expand Down

0 comments on commit fb33e99

Please sign in to comment.