From 03c01e475700c1fb54a88cd756665ef8cb9cb20b Mon Sep 17 00:00:00 2001 From: Jarom Loveridge Date: Sat, 5 Sep 2015 20:46:02 -0600 Subject: [PATCH] Add test to verify end is called at the appropriate time. --- test/querystream.coffee | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/querystream.coffee b/test/querystream.coffee index f66230f..eda7a7f 100644 --- a/test/querystream.coffee +++ b/test/querystream.coffee @@ -1,3 +1,4 @@ +# vim: set sw=2 ts=2 softtabstop=2 expandtab tw=120 : async = require 'async' fs = require 'fs' assert = require 'assert' @@ -28,6 +29,26 @@ describe 'querystream', -> done() ], assert.ifError + it 'does not call end while paused', (done) -> + @timeout 40000 + async.waterfall [ + (cb_w) => + query = @clever.Section.find().count().exec cb_w + (count, cb_w) => + query = @clever.Section.find().limit(100) + stream = query.stream() + cur = 0 + stream.on 'data', (section) => + assert (section instanceof @clever.Section), 'Incorrect type on section object' + stream.pause() + process.nextTick () -> + cur += 1 + stream.resume() + stream.on 'error', (err) -> assert false, "There shouldn't be an error: #{err}" + stream.on 'end', (err) -> + assert cur is count, "Only got #{cur}/#{count} entries!" + done() + ], assert.ifError it 'handles errors correctly', (done) -> clever = Clever 'INVALID_KEY', 'https://api.clever.com'