-
-
Notifications
You must be signed in to change notification settings - Fork 243
Adding callback to res.write and res.end for streaming support #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
ed51c3a
f9c95f9
c4ba4af
bd60b96
5cd1fe2
2b85837
31792c1
bda469c
5f122e8
eb1bad8
ac8914b
866775d
c1f3aab
b0055d2
3ab2f0d
79c6b75
0f617c7
4b50f90
2e995d0
74fdf7b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -676,6 +676,35 @@ describe('compression()', function () { | |
.end() | ||
}) | ||
}) | ||
|
||
describe('when callbacks are used', function () { | ||
it('should call the passed callbacks', function(done){ | ||
var callbacks = 0; | ||
var server = createServer({ threshold: '1kb' }, function (req, res) { | ||
res.setHeader('Content-Type', 'text/plain') | ||
res.write('Hello', null, function(){ | ||
callbacks++ | ||
res.flush() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the test is labeled "when callbacks are used should call the passed callbacks", it doesn't sound like the test should be testing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, I'll remove it. I was simply including There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gotcha. So perhaps that would call for two different tests? Testing the callback when not flushed vs testing with flushed? DO you think that would be a meaningful test? |
||
}); | ||
res.write(' World', null, function(){ | ||
callbacks++ | ||
res.flush() | ||
}); | ||
res.end(null, null, function(){ | ||
callbacks++ | ||
}); | ||
}) | ||
|
||
request(server) | ||
.get('/') | ||
.set('Accept-Encoding', 'gzip') | ||
.expect('Content-Encoding', 'gzip') | ||
.end(function(){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The first argument to this callback is an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The first argument to this callback is an |
||
assert.equal(callbacks, 3) | ||
done(); | ||
}); | ||
}) | ||
}) | ||
}) | ||
|
||
function createServer (opts, fn) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typically you should only pass in the options that are relevant to the test. Here you are passing in
threshold: '1kb'
, which doesn't seem to be necessary for the test (and is even the default setting). Can this be removed? If not, what is the purpose for specifying it explicitly?