Skip to content

Commit 72ca86a

Browse files
authored
test: fix failing tests (#2097)
* test: increase timeout for some redirect- tests * test: fixes * test: fixes * test: fixes * test: fixes * test: fixes * test: fixes * test: fixes * test: fixes
1 parent 56e7624 commit 72ca86a

10 files changed

+61
-152
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"lint:fix": "standard --fix | snazzy",
4949
"test": "npm run test:tap && npm run test:node-fetch && npm run test:fetch && npm run test:cookies && npm run test:wpt && npm run test:websocket && npm run test:jest && npm run test:typescript",
5050
"test:cookies": "node scripts/verifyVersion 16 || tap test/cookie/*.js",
51-
"test:node-fetch": "node scripts/verifyVersion.js 16 || mocha test/node-fetch",
51+
"test:node-fetch": "node scripts/verifyVersion.js 16 || mocha --exit test/node-fetch",
5252
"test:fetch": "node scripts/verifyVersion.js 16 || (npm run build:node && tap --expose-gc test/fetch/*.js && tap test/webidl/*.js)",
5353
"test:jest": "node scripts/verifyVersion.js 14 || jest",
5454
"test:tap": "tap test/*.js test/diagnostics-channel/*.js",

test/agent.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const { test } = require('tap')
3+
const { test, teardown } = require('tap')
44
const http = require('http')
55
const { PassThrough } = require('stream')
66
const { kRunning } = require('../lib/core/symbols')
@@ -705,3 +705,5 @@ test('the dispatcher is truly global', t => {
705705
t.equal(agent, undiciFresh.getGlobalDispatcher())
706706
t.end()
707707
})
708+
709+
teardown(() => process.exit())

test/connect-timeout.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ const sleep = require('atomic-sleep')
88
test('priotorise socket errors over timeouts', (t) => {
99
t.plan(1)
1010
const connectTimeout = 1000
11-
const client = new Pool('http://foobar.bar:1234', { connectTimeout })
11+
const client = new Pool('http://foobar.bar:1234', { connectTimeout: 1 })
1212

1313
client.request({ method: 'GET', path: '/foobar' })
1414
.then(() => t.fail())
1515
.catch((err) => {
1616
t.equal(err.code, 'ENOTFOUND')
1717
})
1818

19-
// block for 2s which is enough for the dns lookup to complete and TO to fire
20-
sleep(connectTimeout * 2)
19+
// block for 1s which is enough for the dns lookup to complete and TO to fire
20+
sleep(connectTimeout)
2121
})
2222

2323
// never connect

test/fetch/client-fetch.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
'use strict'
44

5-
const { test } = require('tap')
5+
const { test, teardown } = require('tap')
66
const { createServer } = require('http')
77
const { ReadableStream } = require('stream/web')
88
const { Blob } = require('buffer')
@@ -672,3 +672,5 @@ test('Receiving non-Latin1 headers', async (t) => {
672672
t.same(lengths, [30, 34, 94, 104, 90])
673673
t.end()
674674
})
675+
676+
teardown(() => process.exit())

test/fetch/jsdom-abortcontroller-1910-1464495619.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@ const { JSDOM } = require('jsdom')
1010
test('third party AbortControllers', async (t) => {
1111
const server = createServer((_, res) => res.end()).listen(0)
1212

13-
t.teardown(server.close.bind(server))
14-
await once(server, 'listening')
15-
1613
const { AbortController } = new JSDOM().window
17-
const controller = new AbortController()
14+
let controller = new AbortController()
15+
16+
t.teardown(() => {
17+
controller.abort()
18+
controller = null
19+
return server.close()
20+
})
21+
await once(server, 'listening')
1822

1923
await t.resolves(fetch(`http://localhost:${server.address().port}`, {
2024
signal: controller.signal

test/fetch/request.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
'use strict'
44

5-
const { test } = require('tap')
5+
const { test, teardown } = require('tap')
66
const {
77
Request,
88
Headers,
99
fetch
1010
} = require('../../')
11-
const { kState } = require('../../lib/fetch/symbols.js')
1211
const {
1312
Blob: ThirdPartyBlob,
1413
FormData: ThirdPartyFormData
@@ -199,7 +198,7 @@ test('undefined window', t => {
199198

200199
test('undefined body', t => {
201200
const req = new Request('http://asd', { body: undefined })
202-
t.equal(req[kState].body, null)
201+
t.equal(req.body, null)
203202
t.end()
204203
})
205204

@@ -298,7 +297,7 @@ test('post aborted signal', t => {
298297
} else {
299298
t.pass()
300299
}
301-
})
300+
}, { once: true })
302301
ac.abort('gwak')
303302
})
304303

@@ -346,7 +345,7 @@ test('post aborted signal cloned', t => {
346345
} else {
347346
t.pass()
348347
}
349-
})
348+
}, { once: true })
350349
ac.abort('gwak')
351350
})
352351

@@ -476,3 +475,5 @@ test('set-cookie headers get cleared when passing a Request as first param', (t)
476475
t.same(req2.headers.getSetCookie(), [])
477476
t.end()
478477
})
478+
479+
teardown(() => process.exit())

test/proxy-agent.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const { test } = require('tap')
3+
const { test, teardown } = require('tap')
44
const { request, fetch, setGlobalDispatcher, getGlobalDispatcher } = require('..')
55
const { InvalidArgumentError } = require('../lib/core/errors')
66
const { nodeMajor } = require('../lib/core/util')
@@ -692,3 +692,5 @@ function buildSSLProxy () {
692692
server.listen(0, () => resolve(server))
693693
})
694694
}
695+
696+
teardown(() => process.exit())

0 commit comments

Comments
 (0)