refactor(Cypress): add nodemodules
This commit is contained in:
111
node_modules/events/tests/add-listeners.js
generated
vendored
Normal file
111
node_modules/events/tests/add-listeners.js
generated
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
// 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 EventEmitter = require('../');
|
||||
|
||||
{
|
||||
var ee = new EventEmitter();
|
||||
var events_new_listener_emitted = [];
|
||||
var listeners_new_listener_emitted = [];
|
||||
|
||||
// Sanity check
|
||||
assert.strictEqual(ee.addListener, ee.on);
|
||||
|
||||
ee.on('newListener', function(event, listener) {
|
||||
// Don't track newListener listeners.
|
||||
if (event === 'newListener')
|
||||
return;
|
||||
|
||||
events_new_listener_emitted.push(event);
|
||||
listeners_new_listener_emitted.push(listener);
|
||||
});
|
||||
|
||||
var hello = common.mustCall(function(a, b) {
|
||||
assert.strictEqual('a', a);
|
||||
assert.strictEqual('b', b);
|
||||
});
|
||||
|
||||
ee.once('newListener', function(name, listener) {
|
||||
assert.strictEqual(name, 'hello');
|
||||
assert.strictEqual(listener, hello);
|
||||
|
||||
var listeners = this.listeners('hello');
|
||||
assert.ok(Array.isArray(listeners));
|
||||
assert.strictEqual(listeners.length, 0);
|
||||
});
|
||||
|
||||
ee.on('hello', hello);
|
||||
ee.once('foo', assert.fail);
|
||||
|
||||
assert.ok(Array.isArray(events_new_listener_emitted));
|
||||
assert.strictEqual(events_new_listener_emitted.length, 2);
|
||||
assert.strictEqual(events_new_listener_emitted[0], 'hello');
|
||||
assert.strictEqual(events_new_listener_emitted[1], 'foo');
|
||||
|
||||
assert.ok(Array.isArray(listeners_new_listener_emitted));
|
||||
assert.strictEqual(listeners_new_listener_emitted.length, 2);
|
||||
assert.strictEqual(listeners_new_listener_emitted[0], hello);
|
||||
assert.strictEqual(listeners_new_listener_emitted[1], assert.fail);
|
||||
|
||||
ee.emit('hello', 'a', 'b');
|
||||
}
|
||||
|
||||
// just make sure that this doesn't throw:
|
||||
{
|
||||
var f = new EventEmitter();
|
||||
|
||||
f.setMaxListeners(0);
|
||||
}
|
||||
|
||||
{
|
||||
var listen1 = function() {};
|
||||
var listen2 = function() {};
|
||||
var ee = new EventEmitter();
|
||||
|
||||
ee.once('newListener', function() {
|
||||
var listeners = ee.listeners('hello');
|
||||
assert.ok(Array.isArray(listeners));
|
||||
assert.strictEqual(listeners.length, 0);
|
||||
ee.once('newListener', function() {
|
||||
var listeners = ee.listeners('hello');
|
||||
assert.ok(Array.isArray(listeners));
|
||||
assert.strictEqual(listeners.length, 0);
|
||||
});
|
||||
ee.on('hello', listen2);
|
||||
});
|
||||
ee.on('hello', listen1);
|
||||
// The order of listeners on an event is not always the order in which the
|
||||
// listeners were added.
|
||||
var listeners = ee.listeners('hello');
|
||||
assert.ok(Array.isArray(listeners));
|
||||
assert.strictEqual(listeners.length, 2);
|
||||
assert.strictEqual(listeners[0], listen2);
|
||||
assert.strictEqual(listeners[1], listen1);
|
||||
}
|
||||
|
||||
// Verify that the listener must be a function
|
||||
assert.throws(function() {
|
||||
var ee = new EventEmitter();
|
||||
|
||||
ee.on('foo', null);
|
||||
}, /^TypeError: "listener" argument must be a function$/);
|
93
node_modules/events/tests/check-listener-leaks.js
generated
vendored
Normal file
93
node_modules/events/tests/check-listener-leaks.js
generated
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
// 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('../');
|
||||
|
||||
// default
|
||||
{
|
||||
var e = new events.EventEmitter();
|
||||
|
||||
for (var i = 0; i < 10; i++) {
|
||||
e.on('default', common.mustNotCall());
|
||||
}
|
||||
assert.ok(!e._events['default'].hasOwnProperty('warned'));
|
||||
e.on('default', common.mustNotCall());
|
||||
assert.ok(e._events['default'].warned);
|
||||
|
||||
// specific
|
||||
e.setMaxListeners(5);
|
||||
for (var i = 0; i < 5; i++) {
|
||||
e.on('specific', common.mustNotCall());
|
||||
}
|
||||
assert.ok(!e._events['specific'].hasOwnProperty('warned'));
|
||||
e.on('specific', common.mustNotCall());
|
||||
assert.ok(e._events['specific'].warned);
|
||||
|
||||
// only one
|
||||
e.setMaxListeners(1);
|
||||
e.on('only one', common.mustNotCall());
|
||||
assert.ok(!e._events['only one'].hasOwnProperty('warned'));
|
||||
e.on('only one', common.mustNotCall());
|
||||
assert.ok(e._events['only one'].hasOwnProperty('warned'));
|
||||
|
||||
// unlimited
|
||||
e.setMaxListeners(0);
|
||||
for (var i = 0; i < 1000; i++) {
|
||||
e.on('unlimited', common.mustNotCall());
|
||||
}
|
||||
assert.ok(!e._events['unlimited'].hasOwnProperty('warned'));
|
||||
}
|
||||
|
||||
// process-wide
|
||||
{
|
||||
events.EventEmitter.defaultMaxListeners = 42;
|
||||
var e = new events.EventEmitter();
|
||||
|
||||
for (var i = 0; i < 42; ++i) {
|
||||
e.on('fortytwo', common.mustNotCall());
|
||||
}
|
||||
assert.ok(!e._events['fortytwo'].hasOwnProperty('warned'));
|
||||
e.on('fortytwo', common.mustNotCall());
|
||||
assert.ok(e._events['fortytwo'].hasOwnProperty('warned'));
|
||||
delete e._events['fortytwo'].warned;
|
||||
|
||||
events.EventEmitter.defaultMaxListeners = 44;
|
||||
e.on('fortytwo', common.mustNotCall());
|
||||
assert.ok(!e._events['fortytwo'].hasOwnProperty('warned'));
|
||||
e.on('fortytwo', common.mustNotCall());
|
||||
assert.ok(e._events['fortytwo'].hasOwnProperty('warned'));
|
||||
}
|
||||
|
||||
// but _maxListeners still has precedence over defaultMaxListeners
|
||||
{
|
||||
events.EventEmitter.defaultMaxListeners = 42;
|
||||
var e = new events.EventEmitter();
|
||||
e.setMaxListeners(1);
|
||||
e.on('uno', common.mustNotCall());
|
||||
assert.ok(!e._events['uno'].hasOwnProperty('warned'));
|
||||
e.on('uno', common.mustNotCall());
|
||||
assert.ok(e._events['uno'].hasOwnProperty('warned'));
|
||||
|
||||
// chainable
|
||||
assert.strictEqual(e, e.setMaxListeners(1));
|
||||
}
|
103
node_modules/events/tests/common.js
generated
vendored
Normal file
103
node_modules/events/tests/common.js
generated
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
// 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 noop = function() {};
|
||||
|
||||
var mustCallChecks = [];
|
||||
|
||||
function runCallChecks(exitCode) {
|
||||
if (exitCode !== 0) return;
|
||||
|
||||
var failed = filter(mustCallChecks, function(context) {
|
||||
if ('minimum' in context) {
|
||||
context.messageSegment = 'at least ' + context.minimum;
|
||||
return context.actual < context.minimum;
|
||||
} else {
|
||||
context.messageSegment = 'exactly ' + context.exact;
|
||||
return context.actual !== context.exact;
|
||||
}
|
||||
});
|
||||
|
||||
for (var i = 0; i < failed.length; i++) {
|
||||
var context = failed[i];
|
||||
console.log('Mismatched %s function calls. Expected %s, actual %d.',
|
||||
context.name,
|
||||
context.messageSegment,
|
||||
context.actual);
|
||||
// IE8 has no .stack
|
||||
if (context.stack) console.log(context.stack.split('\n').slice(2).join('\n'));
|
||||
}
|
||||
|
||||
assert.strictEqual(failed.length, 0);
|
||||
}
|
||||
|
||||
exports.mustCall = function(fn, exact) {
|
||||
return _mustCallInner(fn, exact, 'exact');
|
||||
};
|
||||
|
||||
function _mustCallInner(fn, criteria, field) {
|
||||
if (typeof criteria == 'undefined') criteria = 1;
|
||||
|
||||
if (typeof fn === 'number') {
|
||||
criteria = fn;
|
||||
fn = noop;
|
||||
} else if (fn === undefined) {
|
||||
fn = noop;
|
||||
}
|
||||
|
||||
if (typeof criteria !== 'number')
|
||||
throw new TypeError('Invalid ' + field + ' value: ' + criteria);
|
||||
|
||||
var context = {
|
||||
actual: 0,
|
||||
stack: (new Error()).stack,
|
||||
name: fn.name || '<anonymous>'
|
||||
};
|
||||
|
||||
context[field] = criteria;
|
||||
|
||||
// add the exit listener only once to avoid listener leak warnings
|
||||
if (mustCallChecks.length === 0) after(function() { runCallChecks(0); });
|
||||
|
||||
mustCallChecks.push(context);
|
||||
|
||||
return function() {
|
||||
context.actual++;
|
||||
return fn.apply(this, arguments);
|
||||
};
|
||||
}
|
||||
|
||||
exports.mustNotCall = function(msg) {
|
||||
return function mustNotCall() {
|
||||
assert.fail(msg || 'function should not have been called');
|
||||
};
|
||||
};
|
||||
|
||||
function filter(arr, fn) {
|
||||
if (arr.filter) return arr.filter(fn);
|
||||
var filtered = [];
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
if (fn(arr[i], i, arr)) filtered.push(arr[i]);
|
||||
}
|
||||
return filtered
|
||||
}
|
25
node_modules/events/tests/index.js
generated
vendored
Normal file
25
node_modules/events/tests/index.js
generated
vendored
Normal file
@@ -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');
|
16
node_modules/events/tests/legacy-compat.js
generated
vendored
Normal file
16
node_modules/events/tests/legacy-compat.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
// 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 = require('isarray');
|
||||
}
|
37
node_modules/events/tests/listener-count.js
generated
vendored
Normal file
37
node_modules/events/tests/listener-count.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
// 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.
|
||||
|
||||
require('./common');
|
||||
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);
|
57
node_modules/events/tests/listeners-side-effects.js
generated
vendored
Normal file
57
node_modules/events/tests/listeners-side-effects.js
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
// 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.
|
||||
|
||||
require('./common');
|
||||
var assert = require('assert');
|
||||
|
||||
var EventEmitter = require('../').EventEmitter;
|
||||
var objectKeys = require('object-keys');
|
||||
|
||||
var e = new EventEmitter();
|
||||
var fl; // foo listeners
|
||||
|
||||
fl = e.listeners('foo');
|
||||
assert.ok(Array.isArray(fl));
|
||||
assert.strictEqual(fl.length, 0);
|
||||
if (Object.create) assert.ok(!(e._events instanceof Object));
|
||||
assert.strictEqual(objectKeys(e._events).length, 0);
|
||||
|
||||
e.on('foo', assert.fail);
|
||||
fl = e.listeners('foo');
|
||||
assert.strictEqual(e._events.foo, assert.fail);
|
||||
assert.ok(Array.isArray(fl));
|
||||
assert.strictEqual(fl.length, 1);
|
||||
assert.strictEqual(fl[0], assert.fail);
|
||||
|
||||
e.listeners('bar');
|
||||
|
||||
e.on('foo', assert.ok);
|
||||
fl = e.listeners('foo');
|
||||
|
||||
assert.ok(Array.isArray(e._events.foo));
|
||||
assert.strictEqual(e._events.foo.length, 2);
|
||||
assert.strictEqual(e._events.foo[0], assert.fail);
|
||||
assert.strictEqual(e._events.foo[1], assert.ok);
|
||||
|
||||
assert.ok(Array.isArray(fl));
|
||||
assert.strictEqual(fl.length, 2);
|
||||
assert.strictEqual(fl[0], assert.fail);
|
||||
assert.strictEqual(fl[1], assert.ok);
|
149
node_modules/events/tests/listeners.js
generated
vendored
Normal file
149
node_modules/events/tests/listeners.js
generated
vendored
Normal file
@@ -0,0 +1,149 @@
|
||||
// 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.
|
||||
|
||||
require('./common');
|
||||
var assert = require('assert');
|
||||
var events = require('../');
|
||||
var util = require('util');
|
||||
|
||||
var listener = function listener() {};
|
||||
var listener2 = function listener2() {};
|
||||
function TestStream() {}
|
||||
util.inherits(TestStream, events.EventEmitter);
|
||||
|
||||
{
|
||||
var ee = new events.EventEmitter();
|
||||
ee.on('foo', listener);
|
||||
var fooListeners = ee.listeners('foo');
|
||||
|
||||
var listeners = ee.listeners('foo');
|
||||
assert.ok(Array.isArray(listeners));
|
||||
assert.strictEqual(listeners.length, 1);
|
||||
assert.strictEqual(listeners[0], listener);
|
||||
|
||||
ee.removeAllListeners('foo');
|
||||
listeners = ee.listeners('foo');
|
||||
assert.ok(Array.isArray(listeners));
|
||||
assert.strictEqual(listeners.length, 0);
|
||||
|
||||
assert.ok(Array.isArray(fooListeners));
|
||||
assert.strictEqual(fooListeners.length, 1);
|
||||
assert.strictEqual(fooListeners[0], listener);
|
||||
}
|
||||
|
||||
{
|
||||
var ee = new events.EventEmitter();
|
||||
ee.on('foo', listener);
|
||||
|
||||
var eeListenersCopy = ee.listeners('foo');
|
||||
assert.ok(Array.isArray(eeListenersCopy));
|
||||
assert.strictEqual(eeListenersCopy.length, 1);
|
||||
assert.strictEqual(eeListenersCopy[0], listener);
|
||||
|
||||
var listeners = ee.listeners('foo');
|
||||
assert.ok(Array.isArray(listeners));
|
||||
assert.strictEqual(listeners.length, 1);
|
||||
assert.strictEqual(listeners[0], listener);
|
||||
|
||||
eeListenersCopy.push(listener2);
|
||||
listeners = ee.listeners('foo');
|
||||
|
||||
assert.ok(Array.isArray(listeners));
|
||||
assert.strictEqual(listeners.length, 1);
|
||||
assert.strictEqual(listeners[0], listener);
|
||||
|
||||
assert.strictEqual(eeListenersCopy.length, 2);
|
||||
assert.strictEqual(eeListenersCopy[0], listener);
|
||||
assert.strictEqual(eeListenersCopy[1], listener2);
|
||||
}
|
||||
|
||||
{
|
||||
var ee = new events.EventEmitter();
|
||||
ee.on('foo', listener);
|
||||
var eeListenersCopy = ee.listeners('foo');
|
||||
ee.on('foo', listener2);
|
||||
|
||||
var listeners = ee.listeners('foo');
|
||||
assert.ok(Array.isArray(listeners));
|
||||
assert.strictEqual(listeners.length, 2);
|
||||
assert.strictEqual(listeners[0], listener);
|
||||
assert.strictEqual(listeners[1], listener2);
|
||||
|
||||
assert.ok(Array.isArray(eeListenersCopy));
|
||||
assert.strictEqual(eeListenersCopy.length, 1);
|
||||
assert.strictEqual(eeListenersCopy[0], listener);
|
||||
}
|
||||
|
||||
{
|
||||
var ee = new events.EventEmitter();
|
||||
ee.once('foo', listener);
|
||||
var listeners = ee.listeners('foo');
|
||||
assert.ok(Array.isArray(listeners));
|
||||
assert.strictEqual(listeners.length, 1);
|
||||
assert.strictEqual(listeners[0], listener);
|
||||
}
|
||||
|
||||
{
|
||||
var ee = new events.EventEmitter();
|
||||
ee.on('foo', listener);
|
||||
ee.once('foo', listener2);
|
||||
|
||||
var listeners = ee.listeners('foo');
|
||||
assert.ok(Array.isArray(listeners));
|
||||
assert.strictEqual(listeners.length, 2);
|
||||
assert.strictEqual(listeners[0], listener);
|
||||
assert.strictEqual(listeners[1], listener2);
|
||||
}
|
||||
|
||||
{
|
||||
var ee = new events.EventEmitter();
|
||||
ee._events = undefined;
|
||||
var listeners = ee.listeners('foo');
|
||||
assert.ok(Array.isArray(listeners));
|
||||
assert.strictEqual(listeners.length, 0);
|
||||
}
|
||||
|
||||
{
|
||||
var s = new TestStream();
|
||||
var listeners = s.listeners('foo');
|
||||
assert.ok(Array.isArray(listeners));
|
||||
assert.strictEqual(listeners.length, 0);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
var ee = new events.EventEmitter();
|
||||
ee.on('foo', listener);
|
||||
var wrappedListener = ee.rawListeners('foo');
|
||||
assert.strictEqual(wrappedListener.length, 1);
|
||||
assert.strictEqual(wrappedListener[0], listener);
|
||||
assert.notStrictEqual(wrappedListener, ee.rawListeners('foo'));
|
||||
ee.once('foo', listener);
|
||||
var wrappedListeners = ee.rawListeners('foo');
|
||||
assert.strictEqual(wrappedListeners.length, 2);
|
||||
assert.strictEqual(wrappedListeners[0], listener);
|
||||
assert.notStrictEqual(wrappedListeners[1], listener);
|
||||
assert.strictEqual(wrappedListeners[1].listener, listener);
|
||||
assert.notStrictEqual(wrappedListeners, ee.rawListeners('foo'));
|
||||
ee.emit('foo');
|
||||
assert.strictEqual(wrappedListeners.length, 2);
|
||||
assert.strictEqual(wrappedListeners[1].listener, listener);
|
||||
}
|
47
node_modules/events/tests/max-listeners.js
generated
vendored
Normal file
47
node_modules/events/tests/max-listeners.js
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
// 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 e = new events.EventEmitter();
|
||||
|
||||
var hasDefineProperty = !!Object.defineProperty;
|
||||
try { Object.defineProperty({}, 'x', { value: 0 }); } catch (err) { hasDefineProperty = false }
|
||||
|
||||
e.on('maxListeners', common.mustCall());
|
||||
|
||||
// Should not corrupt the 'maxListeners' queue.
|
||||
e.setMaxListeners(42);
|
||||
|
||||
var throwsObjs = [NaN, -1, 'and even this'];
|
||||
var maxError = /^TypeError: "n" argument must be a positive number$/;
|
||||
var defError = /^TypeError: "defaultMaxListeners" must be a positive number$/;
|
||||
|
||||
for (var i = 0; i < throwsObjs.length; i++) {
|
||||
var obj = throwsObjs[i];
|
||||
assert.throws(function() { e.setMaxListeners(obj); }, maxError);
|
||||
if (hasDefineProperty) {
|
||||
assert.throws(function() { events.defaultMaxListeners = obj; }, defError);
|
||||
}
|
||||
}
|
||||
|
||||
e.emit('maxListeners');
|
90
node_modules/events/tests/modify-in-emit.js
generated
vendored
Normal file
90
node_modules/events/tests/modify-in-emit.js
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
// 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.
|
||||
|
||||
require('./common');
|
||||
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.strictEqual(e.listeners('foo').length, 1);
|
||||
|
||||
e.emit('foo');
|
||||
assert.strictEqual(e.listeners('foo').length, 2);
|
||||
assert.ok(Array.isArray(callbacks_called));
|
||||
assert.strictEqual(callbacks_called.length, 1);
|
||||
assert.strictEqual(callbacks_called[0], 'callback1');
|
||||
|
||||
e.emit('foo');
|
||||
assert.strictEqual(e.listeners('foo').length, 0);
|
||||
assert.ok(Array.isArray(callbacks_called));
|
||||
assert.strictEqual(callbacks_called.length, 3);
|
||||
assert.strictEqual(callbacks_called[0], 'callback1');
|
||||
assert.strictEqual(callbacks_called[1], 'callback2');
|
||||
assert.strictEqual(callbacks_called[2], 'callback3');
|
||||
|
||||
e.emit('foo');
|
||||
assert.strictEqual(e.listeners('foo').length, 0);
|
||||
assert.ok(Array.isArray(callbacks_called));
|
||||
assert.strictEqual(callbacks_called.length, 3);
|
||||
assert.strictEqual(callbacks_called[0], 'callback1');
|
||||
assert.strictEqual(callbacks_called[1], 'callback2');
|
||||
assert.strictEqual(callbacks_called[2], 'callback3');
|
||||
|
||||
e.on('foo', callback1);
|
||||
e.on('foo', callback2);
|
||||
assert.strictEqual(e.listeners('foo').length, 2);
|
||||
e.removeAllListeners('foo');
|
||||
assert.strictEqual(e.listeners('foo').length, 0);
|
||||
|
||||
// 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.strictEqual(2, e.listeners('foo').length);
|
||||
e.emit('foo');
|
||||
assert.ok(Array.isArray(callbacks_called));
|
||||
assert.strictEqual(callbacks_called.length, 2);
|
||||
assert.strictEqual(callbacks_called[0], 'callback2');
|
||||
assert.strictEqual(callbacks_called[1], 'callback3');
|
||||
assert.strictEqual(0, e.listeners('foo').length);
|
69
node_modules/events/tests/num-args.js
generated
vendored
Normal file
69
node_modules/events/tests/num-args.js
generated
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
// 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.
|
||||
|
||||
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]();
|
||||
}
|
||||
});
|
||||
|
||||
var e = new events.EventEmitter();
|
||||
var num_args_emitted = [];
|
||||
|
||||
e.on('numArgs', function() {
|
||||
var numArgs = arguments.length;
|
||||
num_args_emitted.push(numArgs);
|
||||
});
|
||||
|
||||
e.on('foo', function() {
|
||||
num_args_emitted.push(arguments.length);
|
||||
});
|
||||
|
||||
e.on('foo', function() {
|
||||
num_args_emitted.push(arguments.length);
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
e.emit('foo', null, null, null, null);
|
||||
|
||||
after_checks.push(function() {
|
||||
assert.ok(Array.isArray(num_args_emitted));
|
||||
assert.strictEqual(num_args_emitted.length, 8);
|
||||
assert.strictEqual(num_args_emitted[0], 0);
|
||||
assert.strictEqual(num_args_emitted[1], 1);
|
||||
assert.strictEqual(num_args_emitted[2], 2);
|
||||
assert.strictEqual(num_args_emitted[3], 3);
|
||||
assert.strictEqual(num_args_emitted[4], 4);
|
||||
assert.strictEqual(num_args_emitted[5], 5);
|
||||
assert.strictEqual(num_args_emitted[6], 4);
|
||||
assert.strictEqual(num_args_emitted[6], 4);
|
||||
});
|
83
node_modules/events/tests/once.js
generated
vendored
Normal file
83
node_modules/events/tests/once.js
generated
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
// 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 EventEmitter = require('../');
|
||||
|
||||
var e = new EventEmitter();
|
||||
|
||||
e.once('hello', common.mustCall());
|
||||
|
||||
e.emit('hello', 'a', 'b');
|
||||
e.emit('hello', 'a', 'b');
|
||||
e.emit('hello', 'a', 'b');
|
||||
e.emit('hello', 'a', 'b');
|
||||
|
||||
function remove() {
|
||||
assert.fail('once->foo should not be emitted');
|
||||
}
|
||||
|
||||
e.once('foo', remove);
|
||||
e.removeListener('foo', remove);
|
||||
e.emit('foo');
|
||||
|
||||
e.once('e', common.mustCall(function() {
|
||||
e.emit('e');
|
||||
}));
|
||||
|
||||
e.once('e', common.mustCall());
|
||||
|
||||
e.emit('e');
|
||||
|
||||
// Verify that the listener must be a function
|
||||
assert.throws(function() {
|
||||
var ee = new EventEmitter();
|
||||
|
||||
ee.once('foo', null);
|
||||
}, /^TypeError: "listener" argument must be a function$/);
|
||||
|
||||
{
|
||||
// once() has different code paths based on the number of arguments being
|
||||
// emitted. Verify that all of the cases are covered.
|
||||
var maxArgs = 4;
|
||||
|
||||
for (var i = 0; i <= maxArgs; ++i) {
|
||||
var ee = new EventEmitter();
|
||||
var args = ['foo'];
|
||||
|
||||
for (var j = 0; j < i; ++j)
|
||||
args.push(j);
|
||||
|
||||
ee.once('foo', common.mustCall(function() {
|
||||
var params = Array.prototype.slice.call(arguments);
|
||||
var restArgs = args.slice(1);
|
||||
assert.ok(Array.isArray(params));
|
||||
assert.strictEqual(params.length, restArgs.length);
|
||||
for (var index = 0; index < params.length; index++) {
|
||||
var param = params[index];
|
||||
assert.strictEqual(param, restArgs[index]);
|
||||
}
|
||||
}));
|
||||
|
||||
EventEmitter.prototype.emit.apply(ee, args);
|
||||
}
|
||||
}
|
139
node_modules/events/tests/remove-all-listeners.js
generated
vendored
Normal file
139
node_modules/events/tests/remove-all-listeners.js
generated
vendored
Normal file
@@ -0,0 +1,139 @@
|
||||
// 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() {
|
||||
var sortedActual = actual.sort();
|
||||
var sortedExpected = expected.sort();
|
||||
assert.strictEqual(sortedActual.length, sortedExpected.length);
|
||||
for (var index = 0; index < sortedActual.length; index++) {
|
||||
var value = sortedActual[index];
|
||||
assert.strictEqual(value, sortedExpected[index]);
|
||||
}
|
||||
});
|
||||
function listener(name) {
|
||||
actual.push(name);
|
||||
}
|
||||
return common.mustCall(listener, expected.length);
|
||||
}
|
||||
|
||||
{
|
||||
var ee = new events.EventEmitter();
|
||||
var noop = common.mustNotCall();
|
||||
ee.on('foo', noop);
|
||||
ee.on('bar', noop);
|
||||
ee.on('baz', noop);
|
||||
ee.on('baz', noop);
|
||||
var fooListeners = ee.listeners('foo');
|
||||
var barListeners = ee.listeners('bar');
|
||||
var bazListeners = ee.listeners('baz');
|
||||
ee.on('removeListener', expect(['bar', 'baz', 'baz']));
|
||||
ee.removeAllListeners('bar');
|
||||
ee.removeAllListeners('baz');
|
||||
|
||||
var listeners = ee.listeners('foo');
|
||||
assert.ok(Array.isArray(listeners));
|
||||
assert.strictEqual(listeners.length, 1);
|
||||
assert.strictEqual(listeners[0], noop);
|
||||
|
||||
listeners = ee.listeners('bar');
|
||||
assert.ok(Array.isArray(listeners));
|
||||
assert.strictEqual(listeners.length, 0);
|
||||
listeners = ee.listeners('baz');
|
||||
assert.ok(Array.isArray(listeners));
|
||||
assert.strictEqual(listeners.length, 0);
|
||||
// After calling removeAllListeners(),
|
||||
// the old listeners array should stay unchanged.
|
||||
assert.strictEqual(fooListeners.length, 1);
|
||||
assert.strictEqual(fooListeners[0], noop);
|
||||
assert.strictEqual(barListeners.length, 1);
|
||||
assert.strictEqual(barListeners[0], noop);
|
||||
assert.strictEqual(bazListeners.length, 2);
|
||||
assert.strictEqual(bazListeners[0], noop);
|
||||
assert.strictEqual(bazListeners[1], noop);
|
||||
// After calling removeAllListeners(),
|
||||
// new listeners arrays is different from the old.
|
||||
assert.notStrictEqual(ee.listeners('bar'), barListeners);
|
||||
assert.notStrictEqual(ee.listeners('baz'), bazListeners);
|
||||
}
|
||||
|
||||
{
|
||||
var ee = new events.EventEmitter();
|
||||
ee.on('foo', common.mustNotCall());
|
||||
ee.on('bar', common.mustNotCall());
|
||||
// Expect LIFO order
|
||||
ee.on('removeListener', expect(['foo', 'bar', 'removeListener']));
|
||||
ee.on('removeListener', expect(['foo', 'bar']));
|
||||
ee.removeAllListeners();
|
||||
|
||||
var listeners = ee.listeners('foo');
|
||||
assert.ok(Array.isArray(listeners));
|
||||
assert.strictEqual(listeners.length, 0);
|
||||
listeners = ee.listeners('bar');
|
||||
assert.ok(Array.isArray(listeners));
|
||||
assert.strictEqual(listeners.length, 0);
|
||||
}
|
||||
|
||||
{
|
||||
var ee = new events.EventEmitter();
|
||||
ee.on('removeListener', common.mustNotCall());
|
||||
// Check for regression where removeAllListeners() throws when
|
||||
// there exists a 'removeListener' listener, but there exists
|
||||
// no listeners for the provided event type.
|
||||
assert.doesNotThrow(function () { ee.removeAllListeners(ee, 'foo') });
|
||||
}
|
||||
|
||||
{
|
||||
var ee = new events.EventEmitter();
|
||||
var expectLength = 2;
|
||||
ee.on('removeListener', function() {
|
||||
assert.strictEqual(expectLength--, this.listeners('baz').length);
|
||||
});
|
||||
ee.on('baz', common.mustNotCall());
|
||||
ee.on('baz', common.mustNotCall());
|
||||
ee.on('baz', common.mustNotCall());
|
||||
assert.strictEqual(ee.listeners('baz').length, expectLength + 1);
|
||||
ee.removeAllListeners('baz');
|
||||
assert.strictEqual(ee.listeners('baz').length, 0);
|
||||
}
|
||||
|
||||
{
|
||||
var ee = new events.EventEmitter();
|
||||
assert.strictEqual(ee, ee.removeAllListeners());
|
||||
}
|
||||
|
||||
{
|
||||
var ee = new events.EventEmitter();
|
||||
ee._events = undefined;
|
||||
assert.strictEqual(ee, ee.removeAllListeners());
|
||||
}
|
212
node_modules/events/tests/remove-listeners.js
generated
vendored
Normal file
212
node_modules/events/tests/remove-listeners.js
generated
vendored
Normal file
@@ -0,0 +1,212 @@
|
||||
// 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 EventEmitter = require('../');
|
||||
|
||||
var listener1 = function listener1() {};
|
||||
var listener2 = function listener2() {};
|
||||
|
||||
{
|
||||
var ee = new EventEmitter();
|
||||
ee.on('hello', listener1);
|
||||
ee.on('removeListener', common.mustCall(function(name, cb) {
|
||||
assert.strictEqual(name, 'hello');
|
||||
assert.strictEqual(cb, listener1);
|
||||
}));
|
||||
ee.removeListener('hello', listener1);
|
||||
var listeners = ee.listeners('hello');
|
||||
assert.ok(Array.isArray(listeners));
|
||||
assert.strictEqual(listeners.length, 0);
|
||||
}
|
||||
|
||||
{
|
||||
var ee = new EventEmitter();
|
||||
ee.on('hello', listener1);
|
||||
ee.on('removeListener', common.mustNotCall());
|
||||
ee.removeListener('hello', listener2);
|
||||
|
||||
var listeners = ee.listeners('hello');
|
||||
assert.ok(Array.isArray(listeners));
|
||||
assert.strictEqual(listeners.length, 1);
|
||||
assert.strictEqual(listeners[0], listener1);
|
||||
}
|
||||
|
||||
{
|
||||
var ee = new EventEmitter();
|
||||
ee.on('hello', listener1);
|
||||
ee.on('hello', listener2);
|
||||
|
||||
var listeners;
|
||||
ee.once('removeListener', common.mustCall(function(name, cb) {
|
||||
assert.strictEqual(name, 'hello');
|
||||
assert.strictEqual(cb, listener1);
|
||||
listeners = ee.listeners('hello');
|
||||
assert.ok(Array.isArray(listeners));
|
||||
assert.strictEqual(listeners.length, 1);
|
||||
assert.strictEqual(listeners[0], listener2);
|
||||
}));
|
||||
ee.removeListener('hello', listener1);
|
||||
listeners = ee.listeners('hello');
|
||||
assert.ok(Array.isArray(listeners));
|
||||
assert.strictEqual(listeners.length, 1);
|
||||
assert.strictEqual(listeners[0], listener2);
|
||||
ee.once('removeListener', common.mustCall(function(name, cb) {
|
||||
assert.strictEqual(name, 'hello');
|
||||
assert.strictEqual(cb, listener2);
|
||||
listeners = ee.listeners('hello');
|
||||
assert.ok(Array.isArray(listeners));
|
||||
assert.strictEqual(listeners.length, 0);
|
||||
}));
|
||||
ee.removeListener('hello', listener2);
|
||||
listeners = ee.listeners('hello');
|
||||
assert.ok(Array.isArray(listeners));
|
||||
assert.strictEqual(listeners.length, 0);
|
||||
}
|
||||
|
||||
{
|
||||
var ee = new EventEmitter();
|
||||
|
||||
function remove1() {
|
||||
assert.fail('remove1 should not have been called');
|
||||
}
|
||||
|
||||
function remove2() {
|
||||
assert.fail('remove2 should not have been called');
|
||||
}
|
||||
|
||||
ee.on('removeListener', common.mustCall(function(name, cb) {
|
||||
if (cb !== remove1) return;
|
||||
this.removeListener('quux', remove2);
|
||||
this.emit('quux');
|
||||
}, 2));
|
||||
ee.on('quux', remove1);
|
||||
ee.on('quux', remove2);
|
||||
ee.removeListener('quux', remove1);
|
||||
}
|
||||
|
||||
{
|
||||
var ee = new EventEmitter();
|
||||
ee.on('hello', listener1);
|
||||
ee.on('hello', listener2);
|
||||
|
||||
var listeners;
|
||||
ee.once('removeListener', common.mustCall(function(name, cb) {
|
||||
assert.strictEqual(name, 'hello');
|
||||
assert.strictEqual(cb, listener1);
|
||||
listeners = ee.listeners('hello');
|
||||
assert.ok(Array.isArray(listeners));
|
||||
assert.strictEqual(listeners.length, 1);
|
||||
assert.strictEqual(listeners[0], listener2);
|
||||
ee.once('removeListener', common.mustCall(function(name, cb) {
|
||||
assert.strictEqual(name, 'hello');
|
||||
assert.strictEqual(cb, listener2);
|
||||
listeners = ee.listeners('hello');
|
||||
assert.ok(Array.isArray(listeners));
|
||||
assert.strictEqual(listeners.length, 0);
|
||||
}));
|
||||
ee.removeListener('hello', listener2);
|
||||
listeners = ee.listeners('hello');
|
||||
assert.ok(Array.isArray(listeners));
|
||||
assert.strictEqual(listeners.length, 0);
|
||||
}));
|
||||
ee.removeListener('hello', listener1);
|
||||
listeners = ee.listeners('hello');
|
||||
assert.ok(Array.isArray(listeners));
|
||||
assert.strictEqual(listeners.length, 0);
|
||||
}
|
||||
|
||||
{
|
||||
var ee = new EventEmitter();
|
||||
var listener3 = common.mustCall(function() {
|
||||
ee.removeListener('hello', listener4);
|
||||
}, 2);
|
||||
var listener4 = common.mustCall();
|
||||
|
||||
ee.on('hello', listener3);
|
||||
ee.on('hello', listener4);
|
||||
|
||||
// listener4 will still be called although it is removed by listener 3.
|
||||
ee.emit('hello');
|
||||
// This is so because the interal listener array at time of emit
|
||||
// was [listener3,listener4]
|
||||
|
||||
// Interal listener array [listener3]
|
||||
ee.emit('hello');
|
||||
}
|
||||
|
||||
{
|
||||
var ee = new EventEmitter();
|
||||
|
||||
ee.once('hello', listener1);
|
||||
ee.on('removeListener', common.mustCall(function(eventName, listener) {
|
||||
assert.strictEqual(eventName, 'hello');
|
||||
assert.strictEqual(listener, listener1);
|
||||
}));
|
||||
ee.emit('hello');
|
||||
}
|
||||
|
||||
{
|
||||
var ee = new EventEmitter();
|
||||
|
||||
assert.strictEqual(ee, ee.removeListener('foo', function() {}));
|
||||
}
|
||||
|
||||
// Verify that the removed listener must be a function
|
||||
assert.throws(function() {
|
||||
var ee = new EventEmitter();
|
||||
|
||||
ee.removeListener('foo', null);
|
||||
}, /^TypeError: "listener" argument must be a function$/);
|
||||
|
||||
{
|
||||
var ee = new EventEmitter();
|
||||
var listener = function() {};
|
||||
ee._events = undefined;
|
||||
var e = ee.removeListener('foo', listener);
|
||||
assert.strictEqual(e, ee);
|
||||
}
|
||||
|
||||
{
|
||||
var ee = new EventEmitter();
|
||||
|
||||
ee.on('foo', listener1);
|
||||
ee.on('foo', listener2);
|
||||
var listeners = ee.listeners('foo');
|
||||
assert.ok(Array.isArray(listeners));
|
||||
assert.strictEqual(listeners.length, 2);
|
||||
assert.strictEqual(listeners[0], listener1);
|
||||
assert.strictEqual(listeners[1], listener2);
|
||||
|
||||
ee.removeListener('foo', listener1);
|
||||
assert.strictEqual(ee._events.foo, listener2);
|
||||
|
||||
ee.on('foo', listener1);
|
||||
listeners = ee.listeners('foo');
|
||||
assert.ok(Array.isArray(listeners));
|
||||
assert.strictEqual(listeners.length, 2);
|
||||
assert.strictEqual(listeners[0], listener2);
|
||||
assert.strictEqual(listeners[1], listener1);
|
||||
|
||||
ee.removeListener('foo', listener1);
|
||||
assert.strictEqual(ee._events.foo, listener2);
|
||||
}
|
32
node_modules/events/tests/set-max-listeners-side-effects.js
generated
vendored
Normal file
32
node_modules/events/tests/set-max-listeners-side-effects.js
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
// 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.
|
||||
|
||||
require('./common');
|
||||
var assert = require('assert');
|
||||
var events = require('../');
|
||||
var objectKeys = require('object-keys');
|
||||
|
||||
var e = new events.EventEmitter();
|
||||
|
||||
if (Object.create) assert.ok(!(e._events instanceof Object));
|
||||
assert.strictEqual(objectKeys(e._events).length, 0);
|
||||
e.setMaxListeners(5);
|
||||
assert.strictEqual(objectKeys(e._events).length, 0);
|
73
node_modules/events/tests/subclass.js
generated
vendored
Normal file
73
node_modules/events/tests/subclass.js
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
// 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 EventEmitter = require('../').EventEmitter;
|
||||
var util = require('util');
|
||||
var objectKeys = require('object-keys');
|
||||
|
||||
var after_checks = [];
|
||||
after(function() {
|
||||
for (var i = 0 ; i < after_checks.length ; ++i) {
|
||||
after_checks[i]();
|
||||
}
|
||||
});
|
||||
|
||||
util.inherits(MyEE, EventEmitter);
|
||||
|
||||
function MyEE(cb) {
|
||||
this.once(1, cb);
|
||||
this.emit(1);
|
||||
this.removeAllListeners();
|
||||
EventEmitter.call(this);
|
||||
}
|
||||
|
||||
var myee = new MyEE(common.mustCall());
|
||||
|
||||
|
||||
util.inherits(ErrorEE, EventEmitter);
|
||||
function ErrorEE() {
|
||||
this.emit('error', new Error('blerg'));
|
||||
}
|
||||
|
||||
assert.throws(function() {
|
||||
new ErrorEE();
|
||||
}, /blerg/);
|
||||
|
||||
after_checks.push(function() {
|
||||
if (Object.create) assert.ok(!(myee._events instanceof Object));
|
||||
assert.strictEqual(objectKeys(myee._events).length, 0);
|
||||
});
|
||||
|
||||
|
||||
function MyEE2() {
|
||||
EventEmitter.call(this);
|
||||
}
|
||||
|
||||
MyEE2.prototype = new EventEmitter();
|
||||
|
||||
var ee1 = new MyEE2();
|
||||
var ee2 = new MyEE2();
|
||||
|
||||
ee1.on('x', function() {});
|
||||
|
||||
assert.strictEqual(ee2.listenerCount('x'), 0);
|
Reference in New Issue
Block a user