Skip to content

Commit

Permalink
chore: improve usage of skip in tests (nodejs#2761)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak authored and crysmags committed Feb 21, 2024
1 parent eb501a3 commit d50897b
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 88 deletions.
19 changes: 6 additions & 13 deletions test/cookie/global-headers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { test, skip } = require('node:test')
const { describe, test } = require('node:test')
const assert = require('node:assert')
const {
deleteCookie,
Expand All @@ -10,31 +10,24 @@ const {
} = require('../..')
const { getHeadersList } = require('../../lib/cookies/util')

/* global Headers */

if (!globalThis.Headers) {
skip('No global Headers to test')
process.exit(0)
}

test('Using global Headers', async (t) => {
await t.test('deleteCookies', () => {
describe('Using global Headers', async () => {
test('deleteCookies', () => {
const headers = new Headers()

assert.equal(headers.get('set-cookie'), null)
deleteCookie(headers, 'undici')
assert.equal(headers.get('set-cookie'), 'undici=; Expires=Thu, 01 Jan 1970 00:00:00 GMT')
})

await t.test('getCookies', () => {
test('getCookies', () => {
const headers = new Headers({
cookie: 'get=cookies; and=attributes'
})

assert.deepEqual(getCookies(headers), { get: 'cookies', and: 'attributes' })
})

await t.test('getSetCookies', () => {
test('getSetCookies', () => {
const headers = new Headers({
'set-cookie': 'undici=getSetCookies; Secure'
})
Expand All @@ -54,7 +47,7 @@ test('Using global Headers', async (t) => {
}
})

await t.test('setCookie', () => {
test('setCookie', () => {
const headers = new Headers()

setCookie(headers, { name: 'undici', value: 'setCookie' })
Expand Down
3 changes: 0 additions & 3 deletions test/fetch/http2.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ const { Client, fetch, Headers } = require('../..')

const { closeClientAndServerAsPromise } = require('../utils/node-http')

const nodeVersion = Number(process.version.split('v')[1].split('.')[0])

test('[Fetch] Issue#2311', async (t) => {
const expectedBody = 'hello from client!'

Expand Down Expand Up @@ -180,7 +178,6 @@ test('[Fetch] Should handle h2 request with body (string or buffer)', async (t)
// Skipping for now, there is something odd in the way the body is handled
test(
'[Fetch] Should handle h2 request with body (stream)',
{ skip: nodeVersion === 16 },
async (t) => {
const server = createSecureServer(pem)
const expectedBody = readFileSync(__filename, 'utf-8')
Expand Down
10 changes: 3 additions & 7 deletions test/gc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@ const { test, after } = require('node:test')
const { createServer } = require('node:net')
const { Client, Pool } = require('..')

const SKIP = (
typeof WeakRef === 'undefined' ||
typeof FinalizationRegistry === 'undefined' ||
typeof global.gc === 'undefined'
)
const skip = typeof global.gc === 'undefined'

setInterval(() => {
global.gc()
}, 100).unref()

test('gc should collect the client if, and only if, there are no active sockets', { skip: SKIP }, async t => {
test('gc should collect the client if, and only if, there are no active sockets', { skip }, async t => {
t = tspl(t, { plan: 4 })

const server = createServer((socket) => {
Expand Down Expand Up @@ -60,7 +56,7 @@ test('gc should collect the client if, and only if, there are no active sockets'
await t.completed
})

test('gc should collect the pool if, and only if, there are no active sockets', { skip: SKIP }, async t => {
test('gc should collect the pool if, and only if, there are no active sockets', { skip }, async t => {
t = tspl(t, { plan: 4 })

const server = createServer((socket) => {
Expand Down
16 changes: 6 additions & 10 deletions test/node-test/autoselectfamily.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { test, skip } = require('node:test')
const { test } = require('node:test')
const dgram = require('node:dgram')
const { Resolver } = require('node:dns')
const dnsPacket = require('dns-packet')
Expand All @@ -16,11 +16,7 @@ const { tspl } = require('@matteo.collina/tspl')
* explicitly passed in tests in this file to avoid compatibility problems across release lines.
*
*/

if (!nodeHasAutoSelectFamily) {
skip('autoSelectFamily is not supportee')
process.exit()
}
const skip = !nodeHasAutoSelectFamily

function _lookup (resolver, hostname, options, cb) {
resolver.resolve(hostname, 'ANY', (err, replies) => {
Expand Down Expand Up @@ -68,7 +64,7 @@ function createDnsServer (ipv6Addr, ipv4Addr, cb) {
})
}

test('with autoSelectFamily enable the request succeeds when using request', async (t) => {
test('with autoSelectFamily enable the request succeeds when using request', { skip }, async (t) => {
const p = tspl(t, { plan: 3 })

createDnsServer('::1', '127.0.0.1', function (_, { dnsServer, lookup }) {
Expand Down Expand Up @@ -108,7 +104,7 @@ test('with autoSelectFamily enable the request succeeds when using request', asy
await p.completed
})

test('with autoSelectFamily enable the request succeeds when using a client', async (t) => {
test('with autoSelectFamily enable the request succeeds when using a client', { skip }, async (t) => {
const p = tspl(t, { plan: 3 })

createDnsServer('::1', '127.0.0.1', function (_, { dnsServer, lookup }) {
Expand Down Expand Up @@ -149,7 +145,7 @@ test('with autoSelectFamily enable the request succeeds when using a client', as
await p.completed
})

test('with autoSelectFamily disabled the request fails when using request', async (t) => {
test('with autoSelectFamily disabled the request fails when using request', { skip }, async (t) => {
const p = tspl(t, { plan: 1 })

createDnsServer('::1', '127.0.0.1', function (_, { dnsServer, lookup }) {
Expand Down Expand Up @@ -177,7 +173,7 @@ test('with autoSelectFamily disabled the request fails when using request', asyn
await p.completed
})

test('with autoSelectFamily disabled the request fails when using a client', async (t) => {
test('with autoSelectFamily disabled the request fails when using a client', { skip }, async (t) => {
const p = tspl(t, { plan: 1 })

createDnsServer('::1', '127.0.0.1', function (_, { dnsServer, lookup }) {
Expand Down
13 changes: 2 additions & 11 deletions test/node-test/diagnostics-channel/connect-error.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
'use strict'

const { test, skip } = require('node:test')
const { test } = require('node:test')
const { tspl } = require('@matteo.collina/tspl')

let diagnosticsChannel

try {
diagnosticsChannel = require('node:diagnostics_channel')
} catch {
skip('missing diagnostics_channel')
process.exit(0)
}

const diagnosticsChannel = require('node:diagnostics_channel')
const { Client } = require('../../..')

test('Diagnostics channel - connect error', (t) => {
Expand Down
13 changes: 2 additions & 11 deletions test/node-test/diagnostics-channel/error.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
'use strict'

const { test, skip, after } = require('node:test')
const { test, after } = require('node:test')
const { tspl } = require('@matteo.collina/tspl')

let diagnosticsChannel

try {
diagnosticsChannel = require('node:diagnostics_channel')
} catch {
skip('missing diagnostics_channel')
process.exit(0)
}

const diagnosticsChannel = require('node:diagnostics_channel')
const { Client } = require('../../..')
const { createServer } = require('node:http')

Expand Down
13 changes: 2 additions & 11 deletions test/node-test/diagnostics-channel/get.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
'use strict'

const { test, skip, after } = require('node:test')
const { test, after } = require('node:test')
const { tspl } = require('@matteo.collina/tspl')

let diagnosticsChannel

try {
diagnosticsChannel = require('node:diagnostics_channel')
} catch {
skip('missing diagnostics_channel')
process.exit(0)
}

const diagnosticsChannel = require('node:diagnostics_channel')
const { Client } = require('../../..')
const { createServer } = require('node:http')

Expand Down
13 changes: 2 additions & 11 deletions test/node-test/diagnostics-channel/post-stream.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
'use strict'

const { test, skip, after } = require('node:test')
const { test, after } = require('node:test')
const { tspl } = require('@matteo.collina/tspl')
const { Readable } = require('node:stream')

let diagnosticsChannel

try {
diagnosticsChannel = require('node:diagnostics_channel')
} catch {
skip('missing diagnostics_channel')
process.exit(0)
}

const diagnosticsChannel = require('node:diagnostics_channel')
const { Client } = require('../../..')
const { createServer } = require('node:http')

Expand Down
13 changes: 2 additions & 11 deletions test/node-test/diagnostics-channel/post.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
'use strict'

const { test, skip, after } = require('node:test')
const { test, after } = require('node:test')
const { tspl } = require('@matteo.collina/tspl')

let diagnosticsChannel

try {
diagnosticsChannel = require('node:diagnostics_channel')
} catch {
skip('missing diagnostics_channel')
process.exit(0)
}

const diagnosticsChannel = require('node:diagnostics_channel')
const { Client } = require('../../../')
const { createServer } = require('node:http')

Expand Down

0 comments on commit d50897b

Please sign in to comment.