Upgrade Ava to v4
This commit is contained in:
parent
9a40cc5274
commit
ce89f1b611
1153 changed files with 27264 additions and 95308 deletions
135
node_modules/p-timeout/index.d.ts
generated
vendored
135
node_modules/p-timeout/index.d.ts
generated
vendored
|
|
@ -1,72 +1,101 @@
|
|||
declare class TimeoutErrorClass extends Error {
|
||||
/* eslint-disable import/export */
|
||||
|
||||
export class TimeoutError extends Error {
|
||||
readonly name: 'TimeoutError';
|
||||
constructor(message?: string);
|
||||
}
|
||||
|
||||
declare namespace pTimeout {
|
||||
type TimeoutError = TimeoutErrorClass;
|
||||
export interface ClearablePromise<T> extends Promise<T>{
|
||||
/**
|
||||
Clear the timeout.
|
||||
*/
|
||||
clear: () => void;
|
||||
}
|
||||
|
||||
declare const pTimeout: {
|
||||
export type Options = {
|
||||
/**
|
||||
Timeout a promise after a specified amount of time.
|
||||
Custom implementations for the `setTimeout` and `clearTimeout` functions.
|
||||
|
||||
If you pass in a cancelable promise, specifically a promise with a `.cancel()` method, that method will be called when the `pTimeout` promise times out.
|
||||
|
||||
@param input - Promise to decorate.
|
||||
@param milliseconds - Milliseconds before timing out.
|
||||
@param message - Specify a custom error message or error. If you do a custom error, it's recommended to sub-class `pTimeout.TimeoutError`. Default: `'Promise timed out after 50 milliseconds'`.
|
||||
@returns A decorated `input` that times out after `milliseconds` time.
|
||||
Useful for testing purposes, in particular to work around [`sinon.useFakeTimers()`](https://sinonjs.org/releases/latest/fake-timers/).
|
||||
|
||||
@example
|
||||
```
|
||||
import delay = require('delay');
|
||||
import pTimeout = require('p-timeout');
|
||||
import pTimeout from 'p-timeout';
|
||||
import sinon from 'sinon';
|
||||
|
||||
const delayedPromise = delay(200);
|
||||
const originalSetTimeout = setTimeout;
|
||||
const originalClearTimeout = clearTimeout;
|
||||
|
||||
pTimeout(delayedPromise, 50).then(() => 'foo');
|
||||
//=> [TimeoutError: Promise timed out after 50 milliseconds]
|
||||
```
|
||||
*/
|
||||
<ValueType>(
|
||||
input: PromiseLike<ValueType>,
|
||||
milliseconds: number,
|
||||
message?: string | Error
|
||||
): Promise<ValueType>;
|
||||
sinon.useFakeTimers();
|
||||
|
||||
/**
|
||||
Timeout a promise after a specified amount of time.
|
||||
|
||||
If you pass in a cancelable promise, specifically a promise with a `.cancel()` method, that method will be called when the `pTimeout` promise times out.
|
||||
|
||||
@param input - Promise to decorate.
|
||||
@param milliseconds - Milliseconds before timing out. Passing `Infinity` will cause it to never time out.
|
||||
@param fallback - Do something other than rejecting with an error on timeout. You could for example retry.
|
||||
@returns A decorated `input` that times out after `milliseconds` time.
|
||||
|
||||
@example
|
||||
```
|
||||
import delay = require('delay');
|
||||
import pTimeout = require('p-timeout');
|
||||
|
||||
const delayedPromise = () => delay(200);
|
||||
|
||||
pTimeout(delayedPromise(), 50, () => {
|
||||
return pTimeout(delayedPromise(), 300);
|
||||
// Use `pTimeout` without being affected by `sinon.useFakeTimers()`:
|
||||
await pTimeout(doSomething(), 2000, undefined, {
|
||||
customTimers: {
|
||||
setTimeout: originalSetTimeout,
|
||||
clearTimeout: originalClearTimeout
|
||||
}
|
||||
});
|
||||
```
|
||||
*/
|
||||
<ValueType, ReturnType>(
|
||||
input: PromiseLike<ValueType>,
|
||||
milliseconds: number,
|
||||
fallback: () => ReturnType | Promise<ReturnType>
|
||||
): Promise<ValueType | ReturnType>;
|
||||
|
||||
TimeoutError: typeof TimeoutErrorClass;
|
||||
|
||||
// TODO: Remove this for the next major release
|
||||
default: typeof pTimeout;
|
||||
readonly customTimers?: {
|
||||
setTimeout: typeof global.setTimeout;
|
||||
clearTimeout: typeof global.clearTimeout;
|
||||
};
|
||||
};
|
||||
|
||||
export = pTimeout;
|
||||
/**
|
||||
Timeout a promise after a specified amount of time.
|
||||
|
||||
If you pass in a cancelable promise, specifically a promise with a `.cancel()` method, that method will be called when the `pTimeout` promise times out.
|
||||
|
||||
@param input - Promise to decorate.
|
||||
@param milliseconds - Milliseconds before timing out.
|
||||
@param message - Specify a custom error message or error. If you do a custom error, it's recommended to sub-class `pTimeout.TimeoutError`. Default: `'Promise timed out after 50 milliseconds'`.
|
||||
@returns A decorated `input` that times out after `milliseconds` time. It has a `.clear()` method that clears the timeout.
|
||||
|
||||
@example
|
||||
```
|
||||
import {setTimeout} from 'timers/promises';
|
||||
import pTimeout from 'p-timeout';
|
||||
|
||||
const delayedPromise = setTimeout(200);
|
||||
|
||||
await pTimeout(delayedPromise, 50);
|
||||
//=> [TimeoutError: Promise timed out after 50 milliseconds]
|
||||
```
|
||||
*/
|
||||
export default function pTimeout<ValueType>(
|
||||
input: PromiseLike<ValueType>,
|
||||
milliseconds: number,
|
||||
message?: string | Error,
|
||||
options?: Options
|
||||
): ClearablePromise<ValueType>;
|
||||
|
||||
/**
|
||||
Timeout a promise after a specified amount of time.
|
||||
|
||||
If you pass in a cancelable promise, specifically a promise with a `.cancel()` method, that method will be called when the `pTimeout` promise times out.
|
||||
|
||||
@param input - Promise to decorate.
|
||||
@param milliseconds - Milliseconds before timing out. Passing `Infinity` will cause it to never time out.
|
||||
@param fallback - Do something other than rejecting with an error on timeout. You could for example retry.
|
||||
@returns A decorated `input` that times out after `milliseconds` time. It has a `.clear()` method that clears the timeout.
|
||||
|
||||
@example
|
||||
```
|
||||
import {setTimeout} from 'timers/promises';
|
||||
import pTimeout from 'p-timeout';
|
||||
|
||||
const delayedPromise = () => setTimeout(200);
|
||||
|
||||
await pTimeout(delayedPromise(), 50, () => {
|
||||
return pTimeout(delayedPromise(), 300);
|
||||
});
|
||||
```
|
||||
*/
|
||||
export default function pTimeout<ValueType, ReturnType>(
|
||||
input: PromiseLike<ValueType>,
|
||||
milliseconds: number,
|
||||
fallback: () => ReturnType | Promise<ReturnType>,
|
||||
options?: Options
|
||||
): ClearablePromise<ValueType | ReturnType>;
|
||||
|
|
|
|||
90
node_modules/p-timeout/index.js
generated
vendored
90
node_modules/p-timeout/index.js
generated
vendored
|
|
@ -1,57 +1,63 @@
|
|||
'use strict';
|
||||
|
||||
const pFinally = require('p-finally');
|
||||
|
||||
class TimeoutError extends Error {
|
||||
export class TimeoutError extends Error {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = 'TimeoutError';
|
||||
}
|
||||
}
|
||||
|
||||
const pTimeout = (promise, milliseconds, fallback) => new Promise((resolve, reject) => {
|
||||
if (typeof milliseconds !== 'number' || milliseconds < 0) {
|
||||
throw new TypeError('Expected `milliseconds` to be a positive number');
|
||||
}
|
||||
|
||||
if (milliseconds === Infinity) {
|
||||
resolve(promise);
|
||||
return;
|
||||
}
|
||||
|
||||
const timer = setTimeout(() => {
|
||||
if (typeof fallback === 'function') {
|
||||
try {
|
||||
resolve(fallback());
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
export default function pTimeout(promise, milliseconds, fallback, options) {
|
||||
let timer;
|
||||
const cancelablePromise = new Promise((resolve, reject) => {
|
||||
if (typeof milliseconds !== 'number' || Math.sign(milliseconds) !== 1) {
|
||||
throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${milliseconds}\``);
|
||||
}
|
||||
|
||||
if (milliseconds === Number.POSITIVE_INFINITY) {
|
||||
resolve(promise);
|
||||
return;
|
||||
}
|
||||
|
||||
const message = typeof fallback === 'string' ? fallback : `Promise timed out after ${milliseconds} milliseconds`;
|
||||
const timeoutError = fallback instanceof Error ? fallback : new TimeoutError(message);
|
||||
options = {
|
||||
customTimers: {setTimeout, clearTimeout},
|
||||
...options
|
||||
};
|
||||
|
||||
if (typeof promise.cancel === 'function') {
|
||||
promise.cancel();
|
||||
}
|
||||
timer = options.customTimers.setTimeout.call(undefined, () => {
|
||||
if (typeof fallback === 'function') {
|
||||
try {
|
||||
resolve(fallback());
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
|
||||
reject(timeoutError);
|
||||
}, milliseconds);
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Use native `finally` keyword when targeting Node.js 10
|
||||
pFinally(
|
||||
// eslint-disable-next-line promise/prefer-await-to-then
|
||||
promise.then(resolve, reject),
|
||||
() => {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
);
|
||||
});
|
||||
const message = typeof fallback === 'string' ? fallback : `Promise timed out after ${milliseconds} milliseconds`;
|
||||
const timeoutError = fallback instanceof Error ? fallback : new TimeoutError(message);
|
||||
|
||||
module.exports = pTimeout;
|
||||
// TODO: Remove this for the next major release
|
||||
module.exports.default = pTimeout;
|
||||
if (typeof promise.cancel === 'function') {
|
||||
promise.cancel();
|
||||
}
|
||||
|
||||
module.exports.TimeoutError = TimeoutError;
|
||||
reject(timeoutError);
|
||||
}, milliseconds);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
resolve(await promise);
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
} finally {
|
||||
options.customTimers.clearTimeout.call(undefined, timer);
|
||||
}
|
||||
})();
|
||||
});
|
||||
|
||||
cancelablePromise.clear = () => {
|
||||
clearTimeout(timer);
|
||||
timer = undefined;
|
||||
};
|
||||
|
||||
return cancelablePromise;
|
||||
}
|
||||
|
|
|
|||
2
node_modules/p-timeout/license
generated
vendored
2
node_modules/p-timeout/license
generated
vendored
|
|
@ -1,6 +1,6 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
||||
|
||||
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:
|
||||
|
||||
|
|
|
|||
24
node_modules/p-timeout/package.json
generated
vendored
24
node_modules/p-timeout/package.json
generated
vendored
|
|
@ -1,16 +1,19 @@
|
|||
{
|
||||
"name": "p-timeout",
|
||||
"version": "3.2.0",
|
||||
"version": "5.0.2",
|
||||
"description": "Timeout a promise after a specified amount of time",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/p-timeout",
|
||||
"funding": "https://github.com/sponsors/sindresorhus",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
"url": "https://sindresorhus.com"
|
||||
},
|
||||
"type": "module",
|
||||
"exports": "./index.js",
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
"node": ">=12"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava && tsd"
|
||||
|
|
@ -32,14 +35,13 @@
|
|||
"cancel",
|
||||
"bluebird"
|
||||
],
|
||||
"dependencies": {
|
||||
"p-finally": "^1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ava": "^1.4.1",
|
||||
"delay": "^4.1.0",
|
||||
"p-cancelable": "^2.0.0",
|
||||
"tsd": "^0.7.2",
|
||||
"xo": "^0.24.0"
|
||||
"ava": "^3.15.0",
|
||||
"delay": "^5.0.0",
|
||||
"in-range": "^3.0.0",
|
||||
"p-cancelable": "^2.1.0",
|
||||
"time-span": "^4.0.0",
|
||||
"tsd": "^0.14.0",
|
||||
"xo": "^0.38.2"
|
||||
}
|
||||
}
|
||||
64
node_modules/p-timeout/readme.md
generated
vendored
64
node_modules/p-timeout/readme.md
generated
vendored
|
|
@ -1,34 +1,31 @@
|
|||
# p-timeout [](https://travis-ci.org/sindresorhus/p-timeout)
|
||||
# p-timeout
|
||||
|
||||
> Timeout a promise after a specified amount of time
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install p-timeout
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const delay = require('delay');
|
||||
const pTimeout = require('p-timeout');
|
||||
import {setTimeout} from 'timers/promises';
|
||||
import pTimeout from 'p-timeout';
|
||||
|
||||
const delayedPromise = delay(200);
|
||||
const delayedPromise = setTimeout(200);
|
||||
|
||||
pTimeout(delayedPromise, 50).then(() => 'foo');
|
||||
await pTimeout(delayedPromise, 50);
|
||||
//=> [TimeoutError: Promise timed out after 50 milliseconds]
|
||||
```
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### pTimeout(input, milliseconds, message?)
|
||||
### pTimeout(input, milliseconds, fallback?)
|
||||
### pTimeout(input, milliseconds, message?, options?)
|
||||
### pTimeout(input, milliseconds, fallback?, options?)
|
||||
|
||||
Returns a decorated `input` that times out after `milliseconds` time.
|
||||
Returns a decorated `input` that times out after `milliseconds` time. It has a `.clear()` method that clears the timeout.
|
||||
|
||||
If you pass in a cancelable promise, specifically a promise with a `.cancel()` method, that method will be called when the `pTimeout` promise times out.
|
||||
|
||||
|
|
@ -48,7 +45,7 @@ Passing `Infinity` will cause it to never time out.
|
|||
|
||||
#### message
|
||||
|
||||
Type: `string` `Error`<br>
|
||||
Type: `string | Error`\
|
||||
Default: `'Promise timed out after 50 milliseconds'`
|
||||
|
||||
Specify a custom error message or error.
|
||||
|
|
@ -64,21 +61,52 @@ Do something other than rejecting with an error on timeout.
|
|||
You could for example retry:
|
||||
|
||||
```js
|
||||
const delay = require('delay');
|
||||
const pTimeout = require('p-timeout');
|
||||
import {setTimeout} from 'timers/promises';
|
||||
import pTimeout from 'p-timeout';
|
||||
|
||||
const delayedPromise = () => delay(200);
|
||||
const delayedPromise = () => setTimeout(200);
|
||||
|
||||
pTimeout(delayedPromise(), 50, () => {
|
||||
await pTimeout(delayedPromise(), 50, () => {
|
||||
return pTimeout(delayedPromise(), 300);
|
||||
});
|
||||
```
|
||||
|
||||
### pTimeout.TimeoutError
|
||||
#### options
|
||||
|
||||
Type: `object`
|
||||
|
||||
##### customTimers
|
||||
|
||||
Type: `object` with function properties `setTimeout` and `clearTimeout`
|
||||
|
||||
Custom implementations for the `setTimeout` and `clearTimeout` functions.
|
||||
|
||||
Useful for testing purposes, in particular to work around [`sinon.useFakeTimers()`](https://sinonjs.org/releases/latest/fake-timers/).
|
||||
|
||||
Example:
|
||||
|
||||
```js
|
||||
import {setTimeout} from 'timers/promises';
|
||||
import pTimeout from 'p-timeout';
|
||||
|
||||
const originalSetTimeout = setTimeout;
|
||||
const originalClearTimeout = clearTimeout;
|
||||
|
||||
sinon.useFakeTimers();
|
||||
|
||||
// Use `pTimeout` without being affected by `sinon.useFakeTimers()`:
|
||||
await pTimeout(doSomething(), 2000, undefined, {
|
||||
customTimers: {
|
||||
setTimeout: originalSetTimeout,
|
||||
clearTimeout: originalClearTimeout
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### TimeoutError
|
||||
|
||||
Exposed for instance checking and sub-classing.
|
||||
|
||||
|
||||
## Related
|
||||
|
||||
- [delay](https://github.com/sindresorhus/delay) - Delay a promise a specified amount of time
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue