Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ava version and related dependencies #96

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9,852 changes: 4,180 additions & 5,672 deletions package-lock.json

Large diffs are not rendered by default.

31 changes: 17 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "blend-promise-utils",
"version": "1.29.1",
"version": "1.30.0",
"author": "Blend",
"license": "MIT",
"homepage": "https://blend.github.io/promise-utils",
Expand Down Expand Up @@ -31,17 +31,18 @@
},
"ava": {
"files": [
"dist/test/**/*.test.js"
],
"sources": [
"src/*.ts",
"src/**/*.ts"
"!dist/test/**/*.test.js",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm very confused by this update. Doesn't this say that it's only testing files that don't satisfy these globs? I would expect this to mean that no tests are run at all.

"!tslint.test.js"
],
"concurrency": 5,
"verbose": true,
"timeout": "10000",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this option no longer supported in ava?

"failFast": false,
"powerAssert": true
"typescript": {
"compile": false,
"rewritePaths": {
"test/": "dist/test/"
}
}
},
"nyc": {
"reporter": [
Expand All @@ -67,20 +68,22 @@
]
},
"devDependencies": {
"@ava/typescript": "^4.1.0",
"@types/lodash": "4.14.136",
"@types/sinon": "7.0.13",
"ava": "2.2.0",
"ava": "^4.3.0",
"coveralls": "3.0.4",
"grunt": "1.3.0",
"grunt": "1.6.1",
"grunt-contrib-watch": "1.1.0",
"grunt-force-task": "2.0.0",
"grunt-run": "0.8.1",
"lodash": "4.17.21",
"nyc": "14.1.1",
"prettier": "1.18.2",
"nyc": "15.0.0",
"prettier": "2.1.0",
"sinon": "7.3.2",
"tslint": "5.18.0",
"source-map-support": "^0.5.21",
"tslint": "5.8.0",
"typedoc": "0.14.2",
"typescript": "3.5.3"
"typescript": "4.6.3"
}
}
5 changes: 3 additions & 2 deletions src/all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ export async function all<T>(promises: readonly Promise<T>[]): Promise<T[]> {
if (intermediateResults.errors && intermediateResults.errors.length > 0) {
const primaryError = intermediateResults.errors[0];
if (intermediateResults.errors.length > 1 && primaryError instanceof Error) {
primaryError.message = `${primaryError.message}... and ${intermediateResults.errors.length -
1} other errors`;
primaryError.message = `${primaryError.message}... and ${
intermediateResults.errors.length - 1
} other errors`;
// tslint:disable-next-line:no-any (intentionally augmenting error)
(primaryError as any).otherErrors = intermediateResults.errors.slice(1);
}
Expand Down
4 changes: 2 additions & 2 deletions src/delay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export async function delay<T>(delayTimeMs: number): Promise<void>;
export async function delay<T>(delayTime: any, value?: T): Promise<void | T> {
return new Promise(
// tslint:disable-next-line:no-any (typed by overload signatures)
resolve => setTimeout(() => resolve(value), delayTime),
(resolve) => setTimeout(() => resolve(value), delayTime),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

personally hate this lint change, but if you feel strongly this is the right strategy I don't really care as long as it's consistent and is handled automatically with the --fix operation

);
}

Expand All @@ -29,6 +29,6 @@ export async function immediate<T>(): Promise<void>;
export async function immediate(value?: any) {
return new Promise(
// tslint:disable-next-line:no-any (typed by overload signatures)
resolve => setImmediate(() => resolve(value)),
(resolve) => setImmediate(() => resolve(value)),
);
}
2 changes: 1 addition & 1 deletion src/invert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ export async function invert(promise: Promise<any>, message?: string): Promise<a
() => {
throw new Error(message);
},
err => err,
(err) => err,
);
}
2 changes: 1 addition & 1 deletion src/memoize.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
type ThenReturn<T> = T extends Promise<infer U>
? U // tslint:disable:no-any
: T extends ((...args: any[]) => Promise<infer V>)
: T extends (...args: any[]) => Promise<infer V>
? V
: T;

Expand Down
8 changes: 6 additions & 2 deletions src/retry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ export function retry<T extends Function>(fn: T, retryOpts: RetryOpts): T {
try {
return await fn(...args);
} catch (err) {
if (retryOpts.isRetryable && !retryOpts.isRetryable(err)) {
if (err instanceof Error) {
if (retryOpts.isRetryable && !retryOpts.isRetryable(err)) {
throw err;
}
lastErr = err;
} else {
throw err;
}
lastErr = err;
}
if (retryOpts.delayMs && i < retryOpts.maxAttempts - 1) {
await delay(retryOpts.delayMs);
Expand Down
2 changes: 1 addition & 1 deletion src/settleAll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export async function settleAll<T, V>(
export async function settleAll<T, V>(
promises: readonly Promise<T>[],
// tslint:disable-next-line:no-any (no way to guarantee error typings)
errFn: (err: any, ind: number) => V = err => err,
errFn: (err: any, ind: number) => V = (err) => err,
): Promise<SettledPromises<T, V>> {
const intermediateResults: { errors?: V; results?: T }[] = await Promise.all(
(promises || []).map(async (p, i) => {
Expand Down
12 changes: 6 additions & 6 deletions test/all.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import test from 'ava';

import * as promiseUtils from '../src/index';

test('throws errors in order with multiple errors', async t => {
test('throws errors in order with multiple errors', async (t) => {
const testPromises: Promise<any>[] = [
promiseUtils.invert(promiseUtils.delay(500, null), 'delayed error'),
promiseUtils.delay(500, { success: true }),
Expand All @@ -16,7 +16,7 @@ test('throws errors in order with multiple errors', async t => {
t.deepEqual(err.otherErrors, [new Error('failed'), 'also failed']);
});

test('returns values in order of array not execution speed', async t => {
test('returns values in order of array not execution speed', async (t) => {
const testPromises: Promise<any>[] = [
promiseUtils.delay(500, { success: true }),
Promise.resolve(3),
Expand All @@ -26,7 +26,7 @@ test('returns values in order of array not execution speed', async t => {
t.deepEqual(res, [{ success: true }, 3, 'success']);
});

test('throws single error', async t => {
test('throws single error', async (t) => {
const testPromises: Promise<any>[] = [
Promise.reject(new Error('failed')),
Promise.resolve('success'),
Expand All @@ -35,18 +35,18 @@ test('throws single error', async t => {
t.deepEqual(err, new Error('failed'));
});

test('settles null value', async t => {
test('settles null value', async (t) => {
const res = await promiseUtils.all(null as any);
t.deepEqual(res, []);
});

test('works for results', async t => {
test('works for results', async (t) => {
const testPromises: Promise<any>[] = [Promise.resolve('a'), Promise.resolve('b')];
const res = await promiseUtils.all(testPromises);
t.deepEqual(res, ['a', 'b']);
});

test('handles empty promise array', async t => {
test('handles empty promise array', async (t) => {
const res = await promiseUtils.all([]);
t.deepEqual(res, []);
});
9 changes: 5 additions & 4 deletions test/errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import test from 'ava';

import * as promiseUtils from '../src/index';

test('throws wrapped error', async t => {
test('throws wrapped error', async (t) => {
const err = await promiseUtils.invert(
promiseUtils.transformErrors(
async () => {
Expand All @@ -16,12 +16,13 @@ test('throws wrapped error', async t => {
t.is(err.message, 'real error');
});

test('returns a new result', async t => {
const message = await promiseUtils.transformErrors(
test('returns a new result', async (t) => {
const message = await (promiseUtils.transformErrors(
async () => {
throw new Error('broken');
},
() => 'swallowed!',
)();
) as () => Promise<string>)();

t.is(message, 'swallowed!');
});
12 changes: 6 additions & 6 deletions test/filter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,44 @@ import test from 'ava';

import * as promiseUtils from '../src/index';

test('returns empty array when given no input', async t => {
test('returns empty array when given no input', async (t) => {
const output = await promiseUtils.filter(null as any, _.identity);
t.deepEqual(output, []);
});

test('filters arrays', async t => {
test('filters arrays', async (t) => {
const input = [1, 2];
const output = await promiseUtils.filter(input, async (value: any) => {
return value === 2;
});
t.deepEqual(output, [2]);
});

test('filters arrays with indices', async t => {
test('filters arrays with indices', async (t) => {
const input = [1, 2];
const output = await promiseUtils.filter(input, async (value: any, i: number) => {
return i === 1;
});
t.deepEqual(output, [2]);
});

test('filters objects with numeric keys', async t => {
test('filters objects with numeric keys', async (t) => {
const input = { 1: 'asdf', 2: 'abcd' };
const output = await promiseUtils.filter(input, async (value, i) => {
return (i as any) === 1 || (i as any) === 2;
});
t.deepEqual(output, []);
});

test('filters objects', async t => {
test('filters objects', async (t) => {
const input = { a: 1, b: 2 };
const output = await promiseUtils.filter(input, async (value: any) => {
return value === 2;
});
t.deepEqual(output, [2]);
});

test('filters objects without keys', async t => {
test('filters objects without keys', async (t) => {
const input = { a: 1, b: 2 };
const output = await promiseUtils.filter(input, async (value: any, key: any) => {
return key === 'b';
Expand Down
39 changes: 24 additions & 15 deletions test/flatMap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,53 @@ import * as _ from 'lodash';

import * as promiseUtils from '../src/index';

test('returns all values', async t => {
const output = await promiseUtils.flatMap(_.range(10), async n => n * n);
t.deepEqual(output, _.flatMap(_.range(10), n => n * n));
test('returns all values', async (t) => {
const output = await promiseUtils.flatMap(_.range(10), async (n) => n * n);
t.deepEqual(
output,
_.flatMap(_.range(10), (n) => n * n),
);
});

test('flattens', async t => {
const output = await promiseUtils.flatMap(_.range(10), async n => [n, n]);
t.deepEqual(output, _.flatMap(_.range(10), n => [n, n]));
test('flattens', async (t) => {
const output = await promiseUtils.flatMap(_.range(10), async (n) => [n, n]);
t.deepEqual(
output,
_.flatMap(_.range(10), (n) => [n, n]),
);
});

test('ignores empty arrays', async t => {
const output = await promiseUtils.flatMap(_.range(10), async n => (n % 2 === 0 ? [] : [n, n]));
t.deepEqual(output, _.flatMap(_.range(10), n => (n % 2 === 0 ? [] : [n, n])));
test('ignores empty arrays', async (t) => {
const output = await promiseUtils.flatMap(_.range(10), async (n) => (n % 2 === 0 ? [] : [n, n]));
t.deepEqual(
output,
_.flatMap(_.range(10), (n) => (n % 2 === 0 ? [] : [n, n])),
);
});

test('works for objects', async t => {
test('works for objects', async (t) => {
const input = { a: 1, b: 2, c: 3, d: 4 };
const output = await promiseUtils.map(input, async (a, b) => [b, a]);
t.deepEqual(output, _.toPairs(input));
});

test('works for objects without keys', async t => {
test('works for objects without keys', async (t) => {
const input = { a: 1, b: 2, c: 3, d: 4 };
const output = await promiseUtils.flatMap(input, async a => a);
const output = await promiseUtils.flatMap(input, async (a) => a);
t.deepEqual(output, _.flatMap(input));
});

test('handles null input group', async t => {
test('handles null input group', async (t) => {
const output = await promiseUtils.flatMap(null as any, _.identity);
t.deepEqual(output, []);
});

test('handles empty input group', async t => {
test('handles empty input group', async (t) => {
const output = await promiseUtils.flatMap([], _.identity);
t.deepEqual(output, []);
});

test('handles large sub-lists', async t => {
test('handles large sub-lists', async (t) => {
const output = await promiseUtils.flatMap(_.range(10), async () => _.range(1_000_000));
t.is(output.length, 10_000_000);
});
18 changes: 13 additions & 5 deletions test/invert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,33 @@ import test from 'ava';

import * as promiseUtils from '../src/index';

test('throws error when promise resolves', async t => {
test('throws error when promise resolves', async (t) => {
try {
await promiseUtils.invert(Promise.resolve('test'), 'Should not resolve');
t.fail('The promise did not reject');
} catch (err) {
t.is(err.message, 'Should not resolve');
if (err instanceof Error) {
t.is(err.message, 'Should not resolve');
} else {
t.fail('Unexpected error type');
}
}
});

test('uses default message', async t => {
test('uses default message', async (t) => {
try {
await promiseUtils.invert(Promise.resolve('test'));
t.fail('The promise did not reject');
} catch (err) {
t.is(err.message, 'Expected promise to reject');
if (err instanceof Error) {
t.is(err.message, 'Expected promise to reject');
} else {
t.fail('Unexpected error type');
}
}
});

test('returns reject value when promise rejects', async t => {
test('returns reject value when promise rejects', async (t) => {
const ret: any = await promiseUtils.invert(Promise.reject('test'), 'Should not resolve');
t.is(ret, 'test');
});
Loading