Initial commit
[yaffs-website] / node_modules / are-we-there-yet / test / lib / test-event.js
1 'use strict'
2 var util = require('util')
3
4 module.exports = function (obj, event, next) {
5   var timeout = setTimeout(gotTimeout, 10)
6   obj.once(event, gotResult)
7
8   function gotTimeout () {
9     obj.removeListener(event, gotResult)
10     next(new Error('Timeout listening for ' + event))
11   }
12   var result = []
13   function gotResult () {
14     result = Array.prototype.slice.call(arguments)
15     clearTimeout(timeout)
16     timeout = setTimeout(gotNoMoreResults, 10)
17     obj.once(event, gotTooManyResults)
18   }
19   function gotNoMoreResults () {
20     obj.removeListener(event, gotTooManyResults)
21     var args = [null].concat(result)
22     next.apply(null, args)
23   }
24   function gotTooManyResults () {
25     var secondResult = Array.prototype.slice.call(arguments)
26     clearTimeout(timeout)
27     next(new Error('Got too many results, first ' + util.inspect(result) + ' and then ' + util.inspect(secondResult)))
28   }
29 }