Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve usage of skip in tests #2761

Merged
merged 2 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 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 @@ -11,30 +11,26 @@ const {
const { getHeadersList } = require('../../lib/cookies/util')

/* global Headers */
const skip = !globalThis.Headers
Uzlopak marked this conversation as resolved.
Show resolved Hide resolved

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', { skip }, () => {
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', { skip }, () => {
const headers = new Headers({
cookie: 'get=cookies; and=attributes'
})

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

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

await t.test('setCookie', () => {
test('setCookie', { skip }, () => {
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
6 changes: 3 additions & 3 deletions test/gc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { test, after } = require('node:test')
const { createServer } = require('node:net')
const { Client, Pool } = require('..')

const SKIP = (
const skip = (
typeof WeakRef === 'undefined' ||
typeof FinalizationRegistry === 'undefined' ||
Uzlopak marked this conversation as resolved.
Show resolved Hide resolved
typeof global.gc === 'undefined'
Expand All @@ -16,7 +16,7 @@ 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 +60,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
8 changes: 4 additions & 4 deletions test/node-test/diagnostics-channel/connect-error.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
'use strict'

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

let diagnosticsChannel
let skip = false

try {
diagnosticsChannel = require('node:diagnostics_channel')
} catch {
skip('missing diagnostics_channel')
process.exit(0)
skip = true
}
Uzlopak marked this conversation as resolved.
Show resolved Hide resolved

const { Client } = require('../../..')

test('Diagnostics channel - connect error', (t) => {
test('Diagnostics channel - connect error', { skip }, (t) => {
const connectError = new Error('custom error')
const assert = tspl(t, { plan: 16 })

Expand Down
8 changes: 4 additions & 4 deletions test/node-test/diagnostics-channel/error.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
'use strict'

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

let diagnosticsChannel
let skip = false

try {
diagnosticsChannel = require('node:diagnostics_channel')
} catch {
skip('missing diagnostics_channel')
process.exit(0)
skip = true
Uzlopak marked this conversation as resolved.
Show resolved Hide resolved
}

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

test('Diagnostics channel - error', (t) => {
test('Diagnostics channel - error', { skip }, (t) => {
const assert = tspl(t, { plan: 3 })
const server = createServer((req, res) => {
res.destroy()
Expand Down
8 changes: 4 additions & 4 deletions test/node-test/diagnostics-channel/get.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
'use strict'

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

let diagnosticsChannel
let skip = false

try {
diagnosticsChannel = require('node:diagnostics_channel')
} catch {
skip('missing diagnostics_channel')
process.exit(0)
skip = true
}
Uzlopak marked this conversation as resolved.
Show resolved Hide resolved

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

test('Diagnostics channel - get', (t) => {
test('Diagnostics channel - get', { skip }, (t) => {
const assert = tspl(t, { plan: 32 })
const server = createServer((req, res) => {
res.setHeader('Content-Type', 'text/plain')
Expand Down
8 changes: 4 additions & 4 deletions test/node-test/diagnostics-channel/post-stream.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
'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
let skip = false

try {
diagnosticsChannel = require('node:diagnostics_channel')
} catch {
skip('missing diagnostics_channel')
process.exit(0)
skip = true
}
Uzlopak marked this conversation as resolved.
Show resolved Hide resolved

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

test('Diagnostics channel - post stream', (t) => {
test('Diagnostics channel - post stream', { skip }, (t) => {
const assert = tspl(t, { plan: 33 })
const server = createServer((req, res) => {
req.resume()
Expand Down
8 changes: 4 additions & 4 deletions test/node-test/diagnostics-channel/post.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
'use strict'

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

let diagnosticsChannel
let skip = false

try {
diagnosticsChannel = require('node:diagnostics_channel')
} catch {
skip('missing diagnostics_channel')
process.exit(0)
skip = true
}
Uzlopak marked this conversation as resolved.
Show resolved Hide resolved

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

test('Diagnostics channel - post', (t) => {
test('Diagnostics channel - post', { skip }, (t) => {
const assert = tspl(t, { plan: 33 })
const server = createServer((req, res) => {
req.resume()
Expand Down
Loading