From 30b827cd44883c2e813d801c6221fe502446f063 Mon Sep 17 00:00:00 2001 From: uzlopak Date: Wed, 14 Feb 2024 18:20:11 +0100 Subject: [PATCH 1/2] chore: improve usage of skip in tests --- test/cookie/global-headers.js | 18 +++++++----------- test/fetch/http2.js | 3 --- test/gc.js | 6 +++--- test/node-test/autoselectfamily.js | 16 ++++++---------- .../diagnostics-channel/connect-error.js | 8 ++++---- test/node-test/diagnostics-channel/error.js | 8 ++++---- test/node-test/diagnostics-channel/get.js | 8 ++++---- .../diagnostics-channel/post-stream.js | 8 ++++---- test/node-test/diagnostics-channel/post.js | 8 ++++---- 9 files changed, 36 insertions(+), 47 deletions(-) diff --git a/test/cookie/global-headers.js b/test/cookie/global-headers.js index e78566905a1..49dd54efc9f 100644 --- a/test/cookie/global-headers.js +++ b/test/cookie/global-headers.js @@ -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, @@ -11,14 +11,10 @@ const { const { getHeadersList } = require('../../lib/cookies/util') /* global Headers */ +const skip = !globalThis.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', { skip }, () => { const headers = new Headers() assert.equal(headers.get('set-cookie'), null) @@ -26,7 +22,7 @@ test('Using global Headers', async (t) => { 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' }) @@ -34,7 +30,7 @@ test('Using global Headers', async (t) => { assert.deepEqual(getCookies(headers), { get: 'cookies', and: 'attributes' }) }) - await t.test('getSetCookies', () => { + test('getSetCookies', { skip }, () => { const headers = new Headers({ 'set-cookie': 'undici=getSetCookies; Secure' }) @@ -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' }) diff --git a/test/fetch/http2.js b/test/fetch/http2.js index 0562730b26b..0793a21556c 100644 --- a/test/fetch/http2.js +++ b/test/fetch/http2.js @@ -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!' @@ -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') diff --git a/test/gc.js b/test/gc.js index 91ea6ab170c..5212415a2ba 100644 --- a/test/gc.js +++ b/test/gc.js @@ -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' || typeof global.gc === 'undefined' @@ -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) => { @@ -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) => { diff --git a/test/node-test/autoselectfamily.js b/test/node-test/autoselectfamily.js index 678a8959042..196f219fc79 100644 --- a/test/node-test/autoselectfamily.js +++ b/test/node-test/autoselectfamily.js @@ -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') @@ -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) => { @@ -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 }) { @@ -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 }) { @@ -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 }) { @@ -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 }) { diff --git a/test/node-test/diagnostics-channel/connect-error.js b/test/node-test/diagnostics-channel/connect-error.js index ecab3856b89..9e77f4752dd 100644 --- a/test/node-test/diagnostics-channel/connect-error.js +++ b/test/node-test/diagnostics-channel/connect-error.js @@ -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 } 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 }) diff --git a/test/node-test/diagnostics-channel/error.js b/test/node-test/diagnostics-channel/error.js index b4861b8f71c..a23599f3f37 100644 --- a/test/node-test/diagnostics-channel/error.js +++ b/test/node-test/diagnostics-channel/error.js @@ -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 } 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() diff --git a/test/node-test/diagnostics-channel/get.js b/test/node-test/diagnostics-channel/get.js index cde68a46f2c..bc698aa677a 100644 --- a/test/node-test/diagnostics-channel/get.js +++ b/test/node-test/diagnostics-channel/get.js @@ -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 } 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') diff --git a/test/node-test/diagnostics-channel/post-stream.js b/test/node-test/diagnostics-channel/post-stream.js index a50d5ea02c0..4eaf447bac4 100644 --- a/test/node-test/diagnostics-channel/post-stream.js +++ b/test/node-test/diagnostics-channel/post-stream.js @@ -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 } 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() diff --git a/test/node-test/diagnostics-channel/post.js b/test/node-test/diagnostics-channel/post.js index 45368e3fdab..2937ec939fd 100644 --- a/test/node-test/diagnostics-channel/post.js +++ b/test/node-test/diagnostics-channel/post.js @@ -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 } 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() From 811db3c925b14825d2ef295a65c57ecb0876cef3 Mon Sep 17 00:00:00 2001 From: uzlopak Date: Wed, 14 Feb 2024 19:40:33 +0100 Subject: [PATCH 2/2] fix remarks --- test/cookie/global-headers.js | 11 ++++------- test/gc.js | 6 +----- test/node-test/diagnostics-channel/connect-error.js | 13 ++----------- test/node-test/diagnostics-channel/error.js | 13 ++----------- test/node-test/diagnostics-channel/get.js | 13 ++----------- test/node-test/diagnostics-channel/post-stream.js | 13 ++----------- test/node-test/diagnostics-channel/post.js | 13 ++----------- 7 files changed, 15 insertions(+), 67 deletions(-) diff --git a/test/cookie/global-headers.js b/test/cookie/global-headers.js index 49dd54efc9f..1dc9d9a5857 100644 --- a/test/cookie/global-headers.js +++ b/test/cookie/global-headers.js @@ -10,11 +10,8 @@ const { } = require('../..') const { getHeadersList } = require('../../lib/cookies/util') -/* global Headers */ -const skip = !globalThis.Headers - describe('Using global Headers', async () => { - test('deleteCookies', { skip }, () => { + test('deleteCookies', () => { const headers = new Headers() assert.equal(headers.get('set-cookie'), null) @@ -22,7 +19,7 @@ describe('Using global Headers', async () => { assert.equal(headers.get('set-cookie'), 'undici=; Expires=Thu, 01 Jan 1970 00:00:00 GMT') }) - test('getCookies', { skip }, () => { + test('getCookies', () => { const headers = new Headers({ cookie: 'get=cookies; and=attributes' }) @@ -30,7 +27,7 @@ describe('Using global Headers', async () => { assert.deepEqual(getCookies(headers), { get: 'cookies', and: 'attributes' }) }) - test('getSetCookies', { skip }, () => { + test('getSetCookies', () => { const headers = new Headers({ 'set-cookie': 'undici=getSetCookies; Secure' }) @@ -50,7 +47,7 @@ describe('Using global Headers', async () => { } }) - test('setCookie', { skip }, () => { + test('setCookie', () => { const headers = new Headers() setCookie(headers, { name: 'undici', value: 'setCookie' }) diff --git a/test/gc.js b/test/gc.js index 5212415a2ba..1a0bf8bcb96 100644 --- a/test/gc.js +++ b/test/gc.js @@ -6,11 +6,7 @@ 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() diff --git a/test/node-test/diagnostics-channel/connect-error.js b/test/node-test/diagnostics-channel/connect-error.js index 9e77f4752dd..38dbd9d717f 100644 --- a/test/node-test/diagnostics-channel/connect-error.js +++ b/test/node-test/diagnostics-channel/connect-error.js @@ -2,19 +2,10 @@ const { test } = require('node:test') const { tspl } = require('@matteo.collina/tspl') - -let diagnosticsChannel -let skip = false - -try { - diagnosticsChannel = require('node:diagnostics_channel') -} catch { - skip = true -} - +const diagnosticsChannel = require('node:diagnostics_channel') const { Client } = require('../../..') -test('Diagnostics channel - connect error', { skip }, (t) => { +test('Diagnostics channel - connect error', (t) => { const connectError = new Error('custom error') const assert = tspl(t, { plan: 16 }) diff --git a/test/node-test/diagnostics-channel/error.js b/test/node-test/diagnostics-channel/error.js index a23599f3f37..ce6e0978146 100644 --- a/test/node-test/diagnostics-channel/error.js +++ b/test/node-test/diagnostics-channel/error.js @@ -2,20 +2,11 @@ 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 = true -} - +const diagnosticsChannel = require('node:diagnostics_channel') const { Client } = require('../../..') const { createServer } = require('node:http') -test('Diagnostics channel - error', { skip }, (t) => { +test('Diagnostics channel - error', (t) => { const assert = tspl(t, { plan: 3 }) const server = createServer((req, res) => { res.destroy() diff --git a/test/node-test/diagnostics-channel/get.js b/test/node-test/diagnostics-channel/get.js index bc698aa677a..3366481910b 100644 --- a/test/node-test/diagnostics-channel/get.js +++ b/test/node-test/diagnostics-channel/get.js @@ -2,20 +2,11 @@ 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 = true -} - +const diagnosticsChannel = require('node:diagnostics_channel') const { Client } = require('../../..') const { createServer } = require('node:http') -test('Diagnostics channel - get', { skip }, (t) => { +test('Diagnostics channel - get', (t) => { const assert = tspl(t, { plan: 32 }) const server = createServer((req, res) => { res.setHeader('Content-Type', 'text/plain') diff --git a/test/node-test/diagnostics-channel/post-stream.js b/test/node-test/diagnostics-channel/post-stream.js index 4eaf447bac4..49fa0be1a04 100644 --- a/test/node-test/diagnostics-channel/post-stream.js +++ b/test/node-test/diagnostics-channel/post-stream.js @@ -3,20 +3,11 @@ 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 = true -} - +const diagnosticsChannel = require('node:diagnostics_channel') const { Client } = require('../../..') const { createServer } = require('node:http') -test('Diagnostics channel - post stream', { skip }, (t) => { +test('Diagnostics channel - post stream', (t) => { const assert = tspl(t, { plan: 33 }) const server = createServer((req, res) => { req.resume() diff --git a/test/node-test/diagnostics-channel/post.js b/test/node-test/diagnostics-channel/post.js index 2937ec939fd..cddb22ace17 100644 --- a/test/node-test/diagnostics-channel/post.js +++ b/test/node-test/diagnostics-channel/post.js @@ -2,20 +2,11 @@ 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 = true -} - +const diagnosticsChannel = require('node:diagnostics_channel') const { Client } = require('../../../') const { createServer } = require('node:http') -test('Diagnostics channel - post', { skip }, (t) => { +test('Diagnostics channel - post', (t) => { const assert = tspl(t, { plan: 33 }) const server = createServer((req, res) => { req.resume()