Skip to content

Commit

Permalink
test: fix failing tests (nodejs#2097)
Browse files Browse the repository at this point in the history
* test: increase timeout for some redirect- tests

* test: fixes

* test: fixes

* test: fixes

* test: fixes

* test: fixes

* test: fixes

* test: fixes

* test: fixes
  • Loading branch information
KhafraDev authored and metcoder95 committed Jul 21, 2023
1 parent c1429e2 commit eb4a4fd
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 152 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"lint:fix": "standard --fix | snazzy",
"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",
"test:cookies": "node scripts/verifyVersion 16 || tap test/cookie/*.js",
"test:node-fetch": "node scripts/verifyVersion.js 16 || mocha test/node-fetch",
"test:node-fetch": "node scripts/verifyVersion.js 16 || mocha --exit test/node-fetch",
"test:fetch": "node scripts/verifyVersion.js 16 || (npm run build:node && tap --expose-gc test/fetch/*.js && tap test/webidl/*.js)",
"test:jest": "node scripts/verifyVersion.js 14 || jest",
"test:tap": "tap test/*.js test/diagnostics-channel/*.js",
Expand Down
4 changes: 3 additions & 1 deletion test/agent.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { test } = require('tap')
const { test, teardown } = require('tap')
const http = require('http')
const { PassThrough } = require('stream')
const { kRunning } = require('../lib/core/symbols')
Expand Down Expand Up @@ -705,3 +705,5 @@ test('the dispatcher is truly global', t => {
t.equal(agent, undiciFresh.getGlobalDispatcher())
t.end()
})

teardown(() => process.exit())
6 changes: 3 additions & 3 deletions test/connect-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ const sleep = require('atomic-sleep')
test('priotorise socket errors over timeouts', (t) => {
t.plan(1)
const connectTimeout = 1000
const client = new Pool('http://foobar.bar:1234', { connectTimeout })
const client = new Pool('http://foobar.bar:1234', { connectTimeout: 1 })

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

// block for 2s which is enough for the dns lookup to complete and TO to fire
sleep(connectTimeout * 2)
// block for 1s which is enough for the dns lookup to complete and TO to fire
sleep(connectTimeout)
})

// never connect
Expand Down
4 changes: 3 additions & 1 deletion test/fetch/client-fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

'use strict'

const { test } = require('tap')
const { test, teardown } = require('tap')
const { createServer } = require('http')
const { ReadableStream } = require('stream/web')
const { Blob } = require('buffer')
Expand Down Expand Up @@ -672,3 +672,5 @@ test('Receiving non-Latin1 headers', async (t) => {
t.same(lengths, [30, 34, 94, 104, 90])
t.end()
})

teardown(() => process.exit())
12 changes: 8 additions & 4 deletions test/fetch/jsdom-abortcontroller-1910-1464495619.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ const { JSDOM } = require('jsdom')
test('third party AbortControllers', async (t) => {
const server = createServer((_, res) => res.end()).listen(0)

t.teardown(server.close.bind(server))
await once(server, 'listening')

const { AbortController } = new JSDOM().window
const controller = new AbortController()
let controller = new AbortController()

t.teardown(() => {
controller.abort()
controller = null
return server.close()
})
await once(server, 'listening')

await t.resolves(fetch(`http://localhost:${server.address().port}`, {
signal: controller.signal
Expand Down
11 changes: 6 additions & 5 deletions test/fetch/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

'use strict'

const { test } = require('tap')
const { test, teardown } = require('tap')
const {
Request,
Headers,
fetch
} = require('../../')
const { kState } = require('../../lib/fetch/symbols.js')
const {
Blob: ThirdPartyBlob,
FormData: ThirdPartyFormData
Expand Down Expand Up @@ -199,7 +198,7 @@ test('undefined window', t => {

test('undefined body', t => {
const req = new Request('http://asd', { body: undefined })
t.equal(req[kState].body, null)
t.equal(req.body, null)
t.end()
})

Expand Down Expand Up @@ -298,7 +297,7 @@ test('post aborted signal', t => {
} else {
t.pass()
}
})
}, { once: true })
ac.abort('gwak')
})

Expand Down Expand Up @@ -346,7 +345,7 @@ test('post aborted signal cloned', t => {
} else {
t.pass()
}
})
}, { once: true })
ac.abort('gwak')
})

Expand Down Expand Up @@ -476,3 +475,5 @@ test('set-cookie headers get cleared when passing a Request as first param', (t)
t.same(req2.headers.getSetCookie(), [])
t.end()
})

teardown(() => process.exit())
4 changes: 3 additions & 1 deletion test/proxy-agent.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { test } = require('tap')
const { test, teardown } = require('tap')
const { request, fetch, setGlobalDispatcher, getGlobalDispatcher } = require('..')
const { InvalidArgumentError } = require('../lib/core/errors')
const { nodeMajor } = require('../lib/core/util')
Expand Down Expand Up @@ -692,3 +692,5 @@ function buildSSLProxy () {
server.listen(0, () => resolve(server))
})
}

teardown(() => process.exit())
Loading

0 comments on commit eb4a4fd

Please sign in to comment.