Skip to content

Commit 68300f7

Browse files
committed
refactor: simple
1 parent 67edb0e commit 68300f7

File tree

3 files changed

+10
-22
lines changed

3 files changed

+10
-22
lines changed

test/node-fetch/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const crypto = require('crypto')
1010
const chaiPromised = require('chai-as-promised')
1111
const chaiIterator = require('chai-iterator')
1212
const chaiString = require('chai-string')
13-
const { delay } = require('../utils/timeout')
13+
const { timeout } = require('../utils/timeout')
1414
const { Blob } = require('buffer')
1515

1616
const {
@@ -761,7 +761,7 @@ describe('node-fetch', () => {
761761

762762
it('should collect handled errors on the body stream to reject if the body is used later', () => {
763763
const url = `${base}invalid-content-encoding`
764-
return fetch(url).then(delay(20)).then(res => {
764+
return fetch(url).then(timeout(20, { rejection: false })).then(res => {
765765
expect(res.headers.get('content-type')).to.equal('text/plain')
766766
return expect(res.text()).to.eventually.be.rejected
767767
})

test/node-fetch/utils/chai-timeout.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
const { pTimeout } = require('../../utils/timeout')
1+
const { timeout } = require('../../utils/timeout')
22

33
module.exports = ({ Assertion }, utils) => {
44
utils.addProperty(Assertion.prototype, 'timeout', async function () {
55
let timeouted = false
6-
await pTimeout(this._obj, 150, () => {
7-
timeouted = true
6+
await timeout(150, {
7+
promise: this._obj,
8+
fallback: () => {
9+
timeouted = true
10+
}
811
})
12+
913
return this.assert(
1014
timeouted,
1115
'expected promise to timeout but it was resolved',

test/utils/timeout.js

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,6 @@ async function timeout (time, options = {}) {
4444
}
4545
}
4646

47-
/**
48-
* @type {<T, R = T>(promise: Promise<T>, time: number, fallback?: () => R | Promise<R>) => Promise<Awaited<R> | T>}
49-
*/
50-
function pTimeout (promise, time, fallback) {
51-
return timeout(time, { promise, fallback })
52-
}
53-
54-
/**
55-
* @param {number} time
56-
*/
57-
function delay (time) {
58-
return timeout(time, { rejection: false })
59-
}
60-
6147
module.exports = {
62-
timeout,
63-
delay,
64-
pTimeout
48+
timeout
6549
}

0 commit comments

Comments
 (0)