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

View File

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

View File

@ -1,18 +1,15 @@
import pTimeout from 'p-timeout';
export default ({Assertion}, utils) => { export default ({Assertion}, utils) => {
utils.addProperty(Assertion.prototype, 'timeout', function () { utils.addProperty(Assertion.prototype, 'timeout', async function () {
return new Promise(resolve => { let timeouted = false;
const timer = setTimeout(() => resolve(true), 150); await pTimeout(this._obj, 150, () => {
this._obj.then(() => { timeouted = true;
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'
);
}); });
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);
});
}