Skip to content

Commit

Permalink
Bump dev dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Jan 20, 2019
1 parent 9a1320a commit eb0564d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 31 deletions.
5 changes: 3 additions & 2 deletions index.js
Expand Up @@ -138,12 +138,10 @@ module.exports.iterator = (emitter, event, options) => {
removeListener(event, valueHandler);

for (const rejectionEvent of options.rejectionEvents) {
// eslint-disable-next-line no-use-before-define
removeListener(rejectionEvent, rejectHandler);
}

for (const resolutionEvent of options.resolutionEvents) {
// eslint-disable-next-line no-use-before-define
removeListener(resolutionEvent, resolveHandler);
}

Expand Down Expand Up @@ -202,13 +200,16 @@ module.exports.iterator = (emitter, event, options) => {
const value = valueQueue.shift();
return Promise.resolve({done: done && valueQueue.length === 0, value});
}

if (hasPendingError) {
hasPendingError = false;
return Promise.reject(error);
}

if (done) {
return Promise.resolve({done: true, value: undefined});
}

return new Promise((resolve, reject) => nextQueue.push({resolve, reject}));
},
return(value) {
Expand Down
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -45,8 +45,8 @@
"p-timeout": "^2.0.1"
},
"devDependencies": {
"ava": "^1.0.1",
"delay": "^3.0.0",
"xo": "^0.23.0"
"ava": "^1.1.0",
"delay": "^4.1.0",
"xo": "^0.24.0"
}
}
52 changes: 26 additions & 26 deletions test.js
@@ -1,7 +1,7 @@
import EventEmitter from 'events';
import test from 'ava';
import delay from 'delay';
import m from '.';
import pEvent from '.';

test('event to promise', async t => {
const emitter = new EventEmitter();
Expand All @@ -10,7 +10,7 @@ test('event to promise', async t => {
emitter.emit('🦄', '🌈');
});

t.is(await m(emitter, '🦄'), '🌈');
t.is(await pEvent(emitter, '🦄'), '🌈');
});

test('error event rejects the promise', async t => {
Expand All @@ -20,7 +20,7 @@ test('error event rejects the promise', async t => {
emitter.emit('error', new Error('💩'));
});

await t.throws(m(emitter, '🦄'), '💩');
await t.throwsAsync(pEvent(emitter, '🦄'), '💩');
});

test('`rejectionEvents` option', async t => {
Expand All @@ -30,7 +30,7 @@ test('`rejectionEvents` option', async t => {
emitter.emit('bar', new Error('💩'));
});

await t.throws(m(emitter, '🦄', {
await t.throwsAsync(pEvent(emitter, '🦄', {
rejectionEvents: ['foo', 'bar']
}), '💩');
});
Expand All @@ -42,7 +42,7 @@ test('`multiArgs` option on resolve', async t => {
emitter.emit('🦄', '🌈', '🌈');
});

t.deepEqual(await m(emitter, '🦄', {
t.deepEqual(await pEvent(emitter, '🦄', {
multiArgs: true
}), ['🌈', '🌈']);
});
Expand All @@ -54,29 +54,29 @@ test('`multiArgs` option on reject', async t => {
emitter.emit('error', '💩', '💩');
});

t.deepEqual(await m(emitter, 'error', {
t.deepEqual(await pEvent(emitter, 'error', {
multiArgs: true
}), ['💩', '💩']);
});

test('`.cancel()` method', t => {
const emitter = new EventEmitter();
const promise = m(emitter, '🦄');
const promise = pEvent(emitter, '🦄');
t.is(emitter.listenerCount('🦄'), 1);
promise.cancel();
t.is(emitter.listenerCount('🦄'), 0);
});

test('`.cancel()` method with `timeout` option', t => {
const emitter = new EventEmitter();
const promise = m(emitter, '🦄', {timeout: 250});
const promise = pEvent(emitter, '🦄', {timeout: 250});
t.is(emitter.listenerCount('🦄'), 1);
promise.cancel();
t.is(emitter.listenerCount('🦄'), 0);
});

test('error on incompatible emitter', async t => {
await t.throws(m({}, '🦄'), /not compatible/);
await t.throwsAsync(pEvent({}, '🦄'), /not compatible/);
});

test('works with DOM events', async t => {
Expand All @@ -91,7 +91,7 @@ test('works with DOM events', async t => {
emitter.emit('🦄', '🌈');
});

t.is(await m(emitter, '🦄'), '🌈');
t.is(await pEvent(emitter, '🦄'), '🌈');
});

test('event to promise - error', async t => {
Expand All @@ -101,7 +101,7 @@ test('event to promise - error', async t => {
emitter.emit('error', new Error('💩'));
});

t.deepEqual(await m(emitter, 'error'), new Error('💩'));
t.deepEqual(await pEvent(emitter, 'error'), new Error('💩'));
});

test('`timeout` option rejects when short enough', async t => {
Expand All @@ -112,7 +112,7 @@ test('`timeout` option rejects when short enough', async t => {
emitter.emit('🦄', '🌈');
});

await t.throws(m(emitter, '🦄', {
await t.throwsAsync(pEvent(emitter, '🦄', {
timeout
}), `Promise timed out after ${timeout} milliseconds`);

Expand All @@ -126,7 +126,7 @@ test('`timeout` option resolves when long enough', async t => {
emitter.emit('🦄', '🌈');
});

t.is(await m(emitter, '🦄', {
t.is(await pEvent(emitter, '🦄', {
timeout: 250
}), '🌈');
});
Expand All @@ -141,7 +141,7 @@ test('filter function to match event', async t => {
emitter.emit('🦄', 3);
});

t.is(await m(emitter, '🦄', x => x >= 3), 4);
t.is(await pEvent(emitter, '🦄', x => x >= 3), 4);
});

test('filter option to match event', async t => {
Expand All @@ -154,7 +154,7 @@ test('filter option to match event', async t => {
emitter.emit('🦄', 3);
});

t.is(await m(emitter, '🦄', {
t.is(await pEvent(emitter, '🦄', {
filter: x => x >= 3
}), 4);
});
Expand All @@ -170,7 +170,7 @@ test('filter option caught with error', async t => {
emitter.emit('🦄', 3);
});

await t.throws(m(emitter, '🦄', {
await t.throwsAsync(pEvent(emitter, '🦄', {
filter: x => x >= 3
}), '💩');
});
Expand All @@ -185,7 +185,7 @@ test('filter option to match event with `multiArgs`', async t => {
emitter.emit('🦄', 3, 4);
});

t.deepEqual(await m(emitter, '🦄', {
t.deepEqual(await pEvent(emitter, '🦄', {
filter: x => x[0] >= 3 && x[1] >= x[0],
multiArgs: true
}), [3, 4]);
Expand All @@ -202,15 +202,15 @@ test('filter option returned with `multiArgs`', async t => {
emitter.emit('🦄', 3, 4);
});

t.deepEqual(await m(emitter, 'error', {
t.deepEqual(await pEvent(emitter, 'error', {
filter: x => (x[0] > 9999) && (x[1] === '💩'),
multiArgs: true
}), [10000, '💩']);
});

test('event to AsyncIterator', async t => {
const emitter = new EventEmitter();
const iterator = m.iterator(emitter, '🦄');
const iterator = pEvent.iterator(emitter, '🦄');

delay(50).then(() => {
emitter.emit('🦄', '🌈');
Expand All @@ -229,7 +229,7 @@ test('event to AsyncIterator', async t => {

test('event to AsyncIterator (backpressure)', async t => {
const emitter = new EventEmitter();
const iterator = m.iterator(emitter, '🦄');
const iterator = pEvent.iterator(emitter, '🦄');

emitter.emit('🦄', '🌈');
emitter.emit('🦄', 'Something else.');
Expand All @@ -242,19 +242,19 @@ test('event to AsyncIterator (backpressure)', async t => {

test('error event rejects the next promise and finishes the iterator', async t => {
const emitter = new EventEmitter();
const iterator = m.iterator(emitter, '🦄');
const iterator = pEvent.iterator(emitter, '🦄');

delay(200).then(() => {
emitter.emit('error', new Error('💩'));
});

await t.throws(iterator.next(), '💩');
await t.throwsAsync(iterator.next(), '💩');
t.deepEqual(await iterator.next(), {done: true, value: undefined});
});

test('resolve event resolves pending promises and finishes the iterator', async t => {
const emitter = new EventEmitter();
const iterator = m.iterator(emitter, '🦄', {resolutionEvents: ['end']});
const iterator = pEvent.iterator(emitter, '🦄', {resolutionEvents: ['end']});

delay(200).then(() => {
emitter.emit('end');
Expand All @@ -266,7 +266,7 @@ test('resolve event resolves pending promises and finishes the iterator', async
test('.multiple()', async t => {
const emitter = new EventEmitter();

const promise = m.multiple(emitter, '🌂', {
const promise = pEvent.multiple(emitter, '🌂', {
count: 3
});

Expand All @@ -281,7 +281,7 @@ test('.multiple()', async t => {
test('.multiple() - `resolveImmediately` option', async t => {
const emitter = new EventEmitter();

const promise = m.multiple(emitter, '🌂', {
const promise = pEvent.multiple(emitter, '🌂', {
resolveImmediately: true,
count: Infinity
});
Expand All @@ -298,7 +298,7 @@ test('.multiple() - `resolveImmediately` option', async t => {
});

test('`count` option should be a zero or more', async t => {
await t.throws(m.multiple(null, null, {
await t.throwsAsync(pEvent.multiple(null, null, {
count: -1
}), 'The `count` option should be at least 0 or more');
});

0 comments on commit eb0564d

Please sign in to comment.