Simplify test delaying

Signed-off-by: Richie Bendall <richiebendall@gmail.com>
This commit is contained in:
Richie Bendall 2020-05-24 17:36:22 +12:00
parent a6a933fa5a
commit 26966e561d
No known key found for this signature in database
GPG Key ID: 1C6A99DFA9D306FC
4 changed files with 18 additions and 27 deletions

View File

@ -52,8 +52,10 @@
"chai-iterator": "^3.0.2",
"chai-string": "^1.5.0",
"coveralls": "^3.1.0",
"delay": "^4.3.0",
"form-data": "^3.0.0",
"mocha": "^7.2.0",
"p-timeout": "^3.2.0",
"parted": "^0.1.1",
"promise": "^8.1.0",
"resumer": "0.0.0",
@ -82,8 +84,8 @@
"@typescript-eslint/prefer-readonly-parameter-types": 0,
"import/extensions": 0,
"import/no-useless-path-segments": 0,
"unicorn/import-index": 0,
"capitalized-comments": 0
"unicorn/import-index": 0,
"capitalized-comments": 0
},
"ignores": [
"dist",

View File

@ -15,11 +15,11 @@ import then from 'promise';
import resumer from 'resumer';
import FormData from 'form-data';
import stringToArrayBuffer from 'string-to-arraybuffer';
import polyfill from 'abortcontroller-polyfill/dist/abortcontroller.js';
import delay from 'delay';
import AbortControllerPolyfill from 'abortcontroller-polyfill/dist/abortcontroller.js';
import AbortController2 from 'abort-controller';
const {AbortController} = polyfill;
const {AbortController} = AbortControllerPolyfill;
// Test subjects
import Blob from 'fetch-blob';
@ -35,7 +35,6 @@ import HeadersOrig, {createHeadersLenient} from '../src/headers.js';
import RequestOrig from '../src/request.js';
import ResponseOrig from '../src/response.js';
import Body, {getTotalBytes, extractContentType} from '../src/body.js';
import delay from './utils/delay.js';
import TestServer from './utils/server.js';
const {

View File

@ -1,18 +1,15 @@
import pTimeout from 'p-timeout';
export default ({Assertion}, utils) => {
utils.addProperty(Assertion.prototype, 'timeout', function () {
return new Promise(resolve => {
const timer = setTimeout(() => resolve(true), 150);
this._obj.then(() => {
clearTimeout(timer);
resolve(false);
});
}).then(timeouted => {
this.assert(
timeouted,
'expected promise to timeout but it was resolved',
'expected promise not to timeout but it timed out'
);
utils.addProperty(Assertion.prototype, 'timeout', async function () {
let timeouted = false;
await pTimeout(this._obj, 150, () => {
timeouted = true;
});
return this.assert(
timeouted,
'expected promise to timeout but it was resolved',
'expected promise not to timeout but it timed out'
);
});
};

View File

@ -1,7 +0,0 @@
export default function delay(ms) {
return value => new Promise(resolve => {
setTimeout(() => {
resolve(value);
}, ms);
});
}