aboutsummaryrefslogtreecommitdiff
path: root/node_modules/events/tests
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/events/tests')
-rw-r--r--node_modules/events/tests/add-listeners.js63
-rw-r--r--node_modules/events/tests/check-listener-leaks.js86
-rw-r--r--node_modules/events/tests/common.js42
-rw-r--r--node_modules/events/tests/index.js25
-rw-r--r--node_modules/events/tests/legacy-compat.js18
-rw-r--r--node_modules/events/tests/listener-count.js36
-rw-r--r--node_modules/events/tests/listeners-side-effects.js55
-rw-r--r--node_modules/events/tests/listeners.js51
-rw-r--r--node_modules/events/tests/max-listeners.js50
-rw-r--r--node_modules/events/tests/modify-in-emit.js76
-rw-r--r--node_modules/events/tests/num-args.js44
-rw-r--r--node_modules/events/tests/once.js59
-rw-r--r--node_modules/events/tests/remove-all-listeners.js80
-rw-r--r--node_modules/events/tests/remove-listeners.js84
-rw-r--r--node_modules/events/tests/set-max-listeners-side-effects.js29
-rw-r--r--node_modules/events/tests/subclass.js51
16 files changed, 849 insertions, 0 deletions
diff --git a/node_modules/events/tests/add-listeners.js b/node_modules/events/tests/add-listeners.js
new file mode 100644
index 000000000..5ab874cea
--- /dev/null
+++ b/node_modules/events/tests/add-listeners.js
@@ -0,0 +1,63 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+var assert = require('assert');
+var events = require('../');
+
+var e = new events.EventEmitter();
+
+var events_new_listener_emited = [];
+var listeners_new_listener_emited = [];
+var times_hello_emited = 0;
+
+// sanity check
+assert.equal(e.addListener, e.on);
+
+e.on('newListener', function(event, listener) {
+ console.log('newListener: ' + event);
+ events_new_listener_emited.push(event);
+ listeners_new_listener_emited.push(listener);
+});
+
+function hello(a, b) {
+ console.log('hello');
+ times_hello_emited += 1;
+ assert.equal('a', a);
+ assert.equal('b', b);
+}
+e.on('hello', hello);
+
+var foo = function() {};
+e.once('foo', foo);
+
+console.log('start');
+
+e.emit('hello', 'a', 'b');
+
+
+// just make sure that this doesn't throw:
+var f = new events.EventEmitter();
+f.setMaxListeners(0);
+
+assert.deepEqual(['hello', 'foo'], events_new_listener_emited);
+assert.deepEqual([hello, foo], listeners_new_listener_emited);
+assert.equal(1, times_hello_emited);
+
diff --git a/node_modules/events/tests/check-listener-leaks.js b/node_modules/events/tests/check-listener-leaks.js
new file mode 100644
index 000000000..e07866a50
--- /dev/null
+++ b/node_modules/events/tests/check-listener-leaks.js
@@ -0,0 +1,86 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+var assert = require('assert');
+var events = require('../');
+
+var e = new events.EventEmitter();
+
+// default
+for (var i = 0; i < 10; i++) {
+ e.on('default', function() {});
+}
+assert.ok(!e._events['default'].hasOwnProperty('warned'));
+e.on('default', function() {});
+assert.ok(e._events['default'].warned);
+
+// specific
+e.setMaxListeners(5);
+for (var i = 0; i < 5; i++) {
+ e.on('specific', function() {});
+}
+assert.ok(!e._events['specific'].hasOwnProperty('warned'));
+e.on('specific', function() {});
+assert.ok(e._events['specific'].warned);
+
+// only one
+e.setMaxListeners(1);
+e.on('only one', function() {});
+assert.ok(!e._events['only one'].hasOwnProperty('warned'));
+e.on('only one', function() {});
+assert.ok(e._events['only one'].hasOwnProperty('warned'));
+
+// unlimited
+e.setMaxListeners(0);
+for (var i = 0; i < 1000; i++) {
+ e.on('unlimited', function() {});
+}
+assert.ok(!e._events['unlimited'].hasOwnProperty('warned'));
+
+// process-wide
+events.EventEmitter.defaultMaxListeners = 42;
+e = new events.EventEmitter();
+
+for (var i = 0; i < 42; ++i) {
+ e.on('fortytwo', function() {});
+}
+assert.ok(!e._events['fortytwo'].hasOwnProperty('warned'));
+e.on('fortytwo', function() {});
+assert.ok(e._events['fortytwo'].hasOwnProperty('warned'));
+delete e._events['fortytwo'].warned;
+
+events.EventEmitter.defaultMaxListeners = 44;
+e.on('fortytwo', function() {});
+assert.ok(!e._events['fortytwo'].hasOwnProperty('warned'));
+e.on('fortytwo', function() {});
+assert.ok(e._events['fortytwo'].hasOwnProperty('warned'));
+
+// but _maxListeners still has precedence over defaultMaxListeners
+events.EventEmitter.defaultMaxListeners = 42;
+e = new events.EventEmitter();
+e.setMaxListeners(1);
+e.on('uno', function() {});
+assert.ok(!e._events['uno'].hasOwnProperty('warned'));
+e.on('uno', function() {});
+assert.ok(e._events['uno'].hasOwnProperty('warned'));
+
+// chainable
+assert.strictEqual(e, e.setMaxListeners(1));
diff --git a/node_modules/events/tests/common.js b/node_modules/events/tests/common.js
new file mode 100644
index 000000000..66f70a390
--- /dev/null
+++ b/node_modules/events/tests/common.js
@@ -0,0 +1,42 @@
+var assert = require('assert');
+
+var mustCallChecks = [];
+
+function runCallChecks() {
+ var failed_count = 0;
+ for (var i=0 ; i< mustCallChecks.length; ++i) {
+ var context = mustCallChecks[i];
+ if (context.actual === context.expected) {
+ continue;
+ }
+
+ failed_count++;
+ console.log('Mismatched %s function calls. Expected %d, actual %d.',
+ context.name,
+ context.expected,
+ context.actual);
+ console.log(context.stack.split('\n').slice(2).join('\n'));
+ }
+
+ assert(failed_count === 0);
+}
+
+after(runCallChecks);
+
+exports.mustCall = function(fn, expected) {
+ if (typeof expected !== 'number') expected = 1;
+
+ var context = {
+ expected: expected,
+ actual: 0,
+ stack: (new Error).stack,
+ name: fn.name || '<anonymous>'
+ };
+
+ mustCallChecks.push(context);
+
+ return function() {
+ context.actual++;
+ return fn.apply(this, arguments);
+ };
+};
diff --git a/node_modules/events/tests/index.js b/node_modules/events/tests/index.js
new file mode 100644
index 000000000..f144530b9
--- /dev/null
+++ b/node_modules/events/tests/index.js
@@ -0,0 +1,25 @@
+
+require('./legacy-compat');
+
+// we do this to easily wrap each file in a mocha test
+// and also have browserify be able to statically analyze this file
+var orig_require = require;
+var require = function(file) {
+ test(file, function() {
+ orig_require(file);
+ });
+}
+
+require('./add-listeners.js');
+require('./check-listener-leaks.js');
+require('./listener-count.js');
+require('./listeners-side-effects.js');
+require('./listeners.js');
+require('./max-listeners.js');
+require('./modify-in-emit.js');
+require('./num-args.js');
+require('./once.js');
+require('./set-max-listeners-side-effects.js');
+require('./subclass.js');
+require('./remove-all-listeners.js');
+require('./remove-listeners.js');
diff --git a/node_modules/events/tests/legacy-compat.js b/node_modules/events/tests/legacy-compat.js
new file mode 100644
index 000000000..afbc0ab83
--- /dev/null
+++ b/node_modules/events/tests/legacy-compat.js
@@ -0,0 +1,18 @@
+// sigh... life is hard
+if (!global.console) {
+ console = {}
+}
+
+var fns = ['log', 'error', 'trace'];
+for (var i=0 ; i<fns.length ; ++i) {
+ var fn = fns[i];
+ if (!console[fn]) {
+ console[fn] = function() {};
+ }
+}
+
+if (!Array.isArray) {
+ Array.isArray = function(arr) {
+ return Object.prototype.toString.call(arr) === '[object Array]';
+ }
+}
diff --git a/node_modules/events/tests/listener-count.js b/node_modules/events/tests/listener-count.js
new file mode 100644
index 000000000..94cfa82bc
--- /dev/null
+++ b/node_modules/events/tests/listener-count.js
@@ -0,0 +1,36 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+var assert = require('assert');
+var EventEmitter = require('../');
+
+var emitter = new EventEmitter();
+emitter.on('foo', function() {});
+emitter.on('foo', function() {});
+emitter.on('baz', function() {});
+// Allow any type
+emitter.on(123, function() {});
+
+assert.strictEqual(EventEmitter.listenerCount(emitter, 'foo'), 2);
+assert.strictEqual(emitter.listenerCount('foo'), 2);
+assert.strictEqual(emitter.listenerCount('bar'), 0);
+assert.strictEqual(emitter.listenerCount('baz'), 1);
+assert.strictEqual(emitter.listenerCount(123), 1);
diff --git a/node_modules/events/tests/listeners-side-effects.js b/node_modules/events/tests/listeners-side-effects.js
new file mode 100644
index 000000000..15ff3d328
--- /dev/null
+++ b/node_modules/events/tests/listeners-side-effects.js
@@ -0,0 +1,55 @@
+
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+var assert = require('assert');
+var EventEmitter = require('../').EventEmitter;
+
+var e = new EventEmitter;
+var fl; // foo listeners
+
+fl = e.listeners('foo');
+assert(Array.isArray(fl));
+assert(fl.length === 0);
+assert.deepEqual(e._events, {});
+
+e.on('foo', assert.fail);
+fl = e.listeners('foo');
+assert(e._events.foo === assert.fail);
+assert(Array.isArray(fl));
+assert(fl.length === 1);
+assert(fl[0] === assert.fail);
+
+e.listeners('bar');
+assert(!e._events.hasOwnProperty('bar'));
+
+e.on('foo', assert.ok);
+fl = e.listeners('foo');
+
+assert(Array.isArray(e._events.foo));
+assert(e._events.foo.length === 2);
+assert(e._events.foo[0] === assert.fail);
+assert(e._events.foo[1] === assert.ok);
+
+assert(Array.isArray(fl));
+assert(fl.length === 2);
+assert(fl[0] === assert.fail);
+assert(fl[1] === assert.ok);
diff --git a/node_modules/events/tests/listeners.js b/node_modules/events/tests/listeners.js
new file mode 100644
index 000000000..0ed9a5319
--- /dev/null
+++ b/node_modules/events/tests/listeners.js
@@ -0,0 +1,51 @@
+
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+var assert = require('assert');
+var events = require('../');
+
+function listener() {}
+function listener2() {}
+
+var e1 = new events.EventEmitter();
+e1.on('foo', listener);
+var fooListeners = e1.listeners('foo');
+assert.deepEqual(e1.listeners('foo'), [listener]);
+e1.removeAllListeners('foo');
+assert.deepEqual(e1.listeners('foo'), []);
+assert.deepEqual(fooListeners, [listener]);
+
+var e2 = new events.EventEmitter();
+e2.on('foo', listener);
+var e2ListenersCopy = e2.listeners('foo');
+assert.deepEqual(e2ListenersCopy, [listener]);
+assert.deepEqual(e2.listeners('foo'), [listener]);
+e2ListenersCopy.push(listener2);
+assert.deepEqual(e2.listeners('foo'), [listener]);
+assert.deepEqual(e2ListenersCopy, [listener, listener2]);
+
+var e3 = new events.EventEmitter();
+e3.on('foo', listener);
+var e3ListenersCopy = e3.listeners('foo');
+e3.on('foo', listener2);
+assert.deepEqual(e3.listeners('foo'), [listener, listener2]);
+assert.deepEqual(e3ListenersCopy, [listener]);
diff --git a/node_modules/events/tests/max-listeners.js b/node_modules/events/tests/max-listeners.js
new file mode 100644
index 000000000..75e8f7376
--- /dev/null
+++ b/node_modules/events/tests/max-listeners.js
@@ -0,0 +1,50 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+var assert = require('assert');
+var events = require('../');
+
+var gotEvent = false;
+
+var e = new events.EventEmitter();
+
+e.on('maxListeners', function() {
+ gotEvent = true;
+});
+
+// Should not corrupt the 'maxListeners' queue.
+e.setMaxListeners(42);
+
+assert.throws(function() {
+ e.setMaxListeners(NaN);
+});
+
+assert.throws(function() {
+ e.setMaxListeners(-1);
+});
+
+assert.throws(function() {
+ e.setMaxListeners("and even this");
+});
+
+e.emit('maxListeners');
+
+assert(gotEvent);
diff --git a/node_modules/events/tests/modify-in-emit.js b/node_modules/events/tests/modify-in-emit.js
new file mode 100644
index 000000000..3470270aa
--- /dev/null
+++ b/node_modules/events/tests/modify-in-emit.js
@@ -0,0 +1,76 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+var assert = require('assert');
+var events = require('../');
+
+var callbacks_called = [];
+
+var e = new events.EventEmitter();
+
+function callback1() {
+ callbacks_called.push('callback1');
+ e.on('foo', callback2);
+ e.on('foo', callback3);
+ e.removeListener('foo', callback1);
+}
+
+function callback2() {
+ callbacks_called.push('callback2');
+ e.removeListener('foo', callback2);
+}
+
+function callback3() {
+ callbacks_called.push('callback3');
+ e.removeListener('foo', callback3);
+}
+
+e.on('foo', callback1);
+assert.equal(1, e.listeners('foo').length);
+
+e.emit('foo');
+assert.equal(2, e.listeners('foo').length);
+assert.deepEqual(['callback1'], callbacks_called);
+
+e.emit('foo');
+assert.equal(0, e.listeners('foo').length);
+assert.deepEqual(['callback1', 'callback2', 'callback3'], callbacks_called);
+
+e.emit('foo');
+assert.equal(0, e.listeners('foo').length);
+assert.deepEqual(['callback1', 'callback2', 'callback3'], callbacks_called);
+
+e.on('foo', callback1);
+e.on('foo', callback2);
+assert.equal(2, e.listeners('foo').length);
+e.removeAllListeners('foo');
+assert.equal(0, e.listeners('foo').length);
+
+// Verify that removing callbacks while in emit allows emits to propagate to
+// all listeners
+callbacks_called = [];
+
+e.on('foo', callback2);
+e.on('foo', callback3);
+assert.equal(2, e.listeners('foo').length);
+e.emit('foo');
+assert.deepEqual(['callback2', 'callback3'], callbacks_called);
+assert.equal(0, e.listeners('foo').length);
diff --git a/node_modules/events/tests/num-args.js b/node_modules/events/tests/num-args.js
new file mode 100644
index 000000000..1e49d8a6f
--- /dev/null
+++ b/node_modules/events/tests/num-args.js
@@ -0,0 +1,44 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+var assert = require('assert');
+var events = require('../');
+
+var e = new events.EventEmitter(),
+ num_args_emited = [];
+
+e.on('numArgs', function() {
+ var numArgs = arguments.length;
+ console.log('numArgs: ' + numArgs);
+ num_args_emited.push(numArgs);
+});
+
+console.log('start');
+
+e.emit('numArgs');
+e.emit('numArgs', null);
+e.emit('numArgs', null, null);
+e.emit('numArgs', null, null, null);
+e.emit('numArgs', null, null, null, null);
+e.emit('numArgs', null, null, null, null, null);
+
+assert.deepEqual([0, 1, 2, 3, 4, 5], num_args_emited);
+
diff --git a/node_modules/events/tests/once.js b/node_modules/events/tests/once.js
new file mode 100644
index 000000000..61453191f
--- /dev/null
+++ b/node_modules/events/tests/once.js
@@ -0,0 +1,59 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+var assert = require('assert');
+var events = require('../');
+
+var e = new events.EventEmitter();
+var times_hello_emited = 0;
+
+e.once('hello', function(a, b) {
+ times_hello_emited++;
+});
+
+e.emit('hello', 'a', 'b');
+e.emit('hello', 'a', 'b');
+e.emit('hello', 'a', 'b');
+e.emit('hello', 'a', 'b');
+
+var remove = function() {
+ assert.fail(1, 0, 'once->foo should not be emitted', '!');
+};
+
+e.once('foo', remove);
+e.removeListener('foo', remove);
+e.emit('foo');
+
+var times_recurse_emitted = 0;
+
+e.once('e', function() {
+ e.emit('e');
+ times_recurse_emitted++;
+});
+
+e.once('e', function() {
+ times_recurse_emitted++;
+});
+
+e.emit('e');
+
+assert.equal(1, times_hello_emited);
+assert.equal(2, times_recurse_emitted);
diff --git a/node_modules/events/tests/remove-all-listeners.js b/node_modules/events/tests/remove-all-listeners.js
new file mode 100644
index 000000000..b3dc886e7
--- /dev/null
+++ b/node_modules/events/tests/remove-all-listeners.js
@@ -0,0 +1,80 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+var common = require('./common');
+var assert = require('assert');
+var events = require('../');
+
+var after_checks = [];
+after(function() {
+ for (var i=0 ; i<after_checks.length ; ++i) {
+ after_checks[i]();
+ }
+});
+
+function expect(expected) {
+ var actual = [];
+ after_checks.push(function() {
+ assert.deepEqual(actual.sort(), expected.sort());
+ });
+
+ function listener(name) {
+ actual.push(name)
+ }
+ return common.mustCall(listener, expected.length);
+}
+
+function listener() {}
+
+var e1 = new events.EventEmitter();
+e1.on('foo', listener);
+e1.on('bar', listener);
+e1.on('baz', listener);
+e1.on('baz', listener);
+var fooListeners = e1.listeners('foo');
+var barListeners = e1.listeners('bar');
+var bazListeners = e1.listeners('baz');
+e1.on('removeListener', expect(['bar', 'baz', 'baz']));
+e1.removeAllListeners('bar');
+e1.removeAllListeners('baz');
+assert.deepEqual(e1.listeners('foo'), [listener]);
+assert.deepEqual(e1.listeners('bar'), []);
+assert.deepEqual(e1.listeners('baz'), []);
+// after calling removeAllListeners,
+// the old listeners array should stay unchanged
+assert.deepEqual(fooListeners, [listener]);
+assert.deepEqual(barListeners, [listener]);
+assert.deepEqual(bazListeners, [listener, listener]);
+// after calling removeAllListeners,
+// new listeners arrays are different from the old
+assert.notEqual(e1.listeners('bar'), barListeners);
+assert.notEqual(e1.listeners('baz'), bazListeners);
+
+var e2 = new events.EventEmitter();
+e2.on('foo', listener);
+e2.on('bar', listener);
+// expect LIFO order
+e2.on('removeListener', expect(['foo', 'bar', 'removeListener']));
+e2.on('removeListener', expect(['foo', 'bar']));
+e2.removeAllListeners();
+console.error(e2);
+assert.deepEqual([], e2.listeners('foo'));
+assert.deepEqual([], e2.listeners('bar'));
diff --git a/node_modules/events/tests/remove-listeners.js b/node_modules/events/tests/remove-listeners.js
new file mode 100644
index 000000000..401e6a98f
--- /dev/null
+++ b/node_modules/events/tests/remove-listeners.js
@@ -0,0 +1,84 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+var common = require('./common');
+var assert = require('assert');
+var events = require('../');
+
+var count = 0;
+
+function listener1() {
+ console.log('listener1');
+ count++;
+}
+
+function listener2() {
+ console.log('listener2');
+ count++;
+}
+
+function listener3() {
+ console.log('listener3');
+ count++;
+}
+
+function remove1() {
+ assert(0);
+}
+
+function remove2() {
+ assert(0);
+}
+
+var e1 = new events.EventEmitter();
+e1.on('hello', listener1);
+e1.on('removeListener', common.mustCall(function(name, cb) {
+ assert.equal(name, 'hello');
+ assert.equal(cb, listener1);
+}));
+e1.removeListener('hello', listener1);
+assert.deepEqual([], e1.listeners('hello'));
+
+var e2 = new events.EventEmitter();
+e2.on('hello', listener1);
+e2.on('removeListener', assert.fail);
+e2.removeListener('hello', listener2);
+assert.deepEqual([listener1], e2.listeners('hello'));
+
+var e3 = new events.EventEmitter();
+e3.on('hello', listener1);
+e3.on('hello', listener2);
+e3.on('removeListener', common.mustCall(function(name, cb) {
+ assert.equal(name, 'hello');
+ assert.equal(cb, listener1);
+}));
+e3.removeListener('hello', listener1);
+assert.deepEqual([listener2], e3.listeners('hello'));
+
+var e4 = new events.EventEmitter();
+e4.on('removeListener', common.mustCall(function(name, cb) {
+ if (cb !== remove1) return;
+ this.removeListener('quux', remove2);
+ this.emit('quux');
+}, 2));
+e4.on('quux', remove1);
+e4.on('quux', remove2);
+e4.removeListener('quux', remove1);
diff --git a/node_modules/events/tests/set-max-listeners-side-effects.js b/node_modules/events/tests/set-max-listeners-side-effects.js
new file mode 100644
index 000000000..654b01ccb
--- /dev/null
+++ b/node_modules/events/tests/set-max-listeners-side-effects.js
@@ -0,0 +1,29 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+var assert = require('assert');
+var events = require('../');
+
+var e = new events.EventEmitter;
+
+assert.deepEqual(e._events, {});
+e.setMaxListeners(5);
+assert.deepEqual(e._events, {});
diff --git a/node_modules/events/tests/subclass.js b/node_modules/events/tests/subclass.js
new file mode 100644
index 000000000..775938153
--- /dev/null
+++ b/node_modules/events/tests/subclass.js
@@ -0,0 +1,51 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+var assert = require('assert');
+var EventEmitter = require('../').EventEmitter;
+var util = require('util');
+
+util.inherits(MyEE, EventEmitter);
+
+function MyEE(cb) {
+ this.once(1, cb);
+ this.emit(1);
+ this.removeAllListeners();
+ EventEmitter.call(this);
+}
+
+var called = false;
+var myee = new MyEE(function() {
+ called = true;
+});
+
+
+util.inherits(ErrorEE, EventEmitter);
+function ErrorEE() {
+ this.emit('error', new Error('blerg'));
+}
+
+assert.throws(function() {
+ new ErrorEE();
+}, /blerg/);
+
+assert(called);
+assert.deepEqual(myee._events, {});