-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: pull out test utils into support dir
- Loading branch information
1 parent
f2234b3
commit aaa5b90
Showing
3 changed files
with
75 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
var stream = require('readable-stream') | ||
var util = require('util') | ||
|
||
module.exports = SlowWriteStream | ||
|
||
function SlowWriteStream () { | ||
stream.Writable.call(this) | ||
} | ||
|
||
util.inherits(SlowWriteStream, stream.Writable) | ||
|
||
SlowWriteStream.prototype._write = function _write (chunk, encoding, callback) { | ||
setTimeout(callback, 1000) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
var assert = require('assert') | ||
var finalhandler = require('../..') | ||
var http = require('http') | ||
var request = require('supertest') | ||
var SlowWriteStream = require('./sws') | ||
|
||
exports.assert = assert | ||
exports.createError = createError | ||
exports.createServer = createServer | ||
exports.createSlowWriteStream = createSlowWriteStream | ||
exports.request = request | ||
exports.shouldHaveStatusMessage = shouldHaveStatusMessage | ||
exports.shouldNotHaveHeader = shouldNotHaveHeader | ||
|
||
function createError (message, props) { | ||
var err = new Error(message) | ||
|
||
if (props) { | ||
for (var prop in props) { | ||
err[prop] = props[prop] | ||
} | ||
} | ||
|
||
return err | ||
} | ||
|
||
function createServer (err, opts) { | ||
return http.createServer(function (req, res) { | ||
var done = finalhandler(req, res, opts) | ||
|
||
if (typeof err === 'function') { | ||
err(req, res, done) | ||
return | ||
} | ||
|
||
done(err) | ||
}) | ||
} | ||
|
||
function createSlowWriteStream () { | ||
return new SlowWriteStream() | ||
} | ||
|
||
function shouldHaveStatusMessage (statusMessage) { | ||
return function (test) { | ||
assert.equal(test.res.statusMessage, statusMessage, 'should have statusMessage "' + statusMessage + '"') | ||
} | ||
} | ||
|
||
function shouldNotHaveHeader (header) { | ||
return function (test) { | ||
assert.ok(test.res.headers[header] === undefined, 'response does not have header "' + header + '"') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters