Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/npmlog/node_modules/are-we-there-yet/test/lib/test-event.js')
-rw-r--r--node_modules/npmlog/node_modules/are-we-there-yet/test/lib/test-event.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/node_modules/npmlog/node_modules/are-we-there-yet/test/lib/test-event.js b/node_modules/npmlog/node_modules/are-we-there-yet/test/lib/test-event.js
new file mode 100644
index 000000000..2aa7c05c5
--- /dev/null
+++ b/node_modules/npmlog/node_modules/are-we-there-yet/test/lib/test-event.js
@@ -0,0 +1,29 @@
+'use strict'
+var util = require('util')
+
+module.exports = function (obj, event, next) {
+ var timeout = setTimeout(gotTimeout, 10)
+ obj.once(event, gotResult)
+
+ function gotTimeout () {
+ obj.removeListener(event, gotResult)
+ next(new Error('Timeout listening for ' + event))
+ }
+ var result = []
+ function gotResult () {
+ result = Array.prototype.slice.call(arguments)
+ clearTimeout(timeout)
+ timeout = setTimeout(gotNoMoreResults, 10)
+ obj.once(event, gotTooManyResults)
+ }
+ function gotNoMoreResults () {
+ obj.removeListener(event, gotTooManyResults)
+ var args = [null].concat(result)
+ next.apply(null, args)
+ }
+ function gotTooManyResults () {
+ var secondResult = Array.prototype.slice.call(arguments)
+ clearTimeout(timeout)
+ next(new Error('Got too many results, first ' + util.inspect(result) + ' and then ' + util.inspect(secondResult)))
+ }
+}