From 61c443c96ec305c580db55479f97193ac59ae585 Mon Sep 17 00:00:00 2001 From: Tony133 Date: Sun, 8 Jun 2025 22:36:27 +0200 Subject: [PATCH 01/10] test: migrated graceful-shutdown.test.js from tap to node:test --- test/graceful-shutdown.test.js | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/test/graceful-shutdown.test.js b/test/graceful-shutdown.test.js index 4b9196e0..8d1b0935 100644 --- a/test/graceful-shutdown.test.js +++ b/test/graceful-shutdown.test.js @@ -1,13 +1,12 @@ 'use strict' -const t = require('tap') +const { test } = require('node:test') // Tests skip on win32 platforms due SIGINT signal is not supported across all windows platforms -const test = (process.platform === 'win32') ? t.skip : t.test +const testWin = (process.platform === 'win32') ? test.skip : test const sinon = require('sinon') const start = require('../start') let _port = 3001 - function getPort () { return '' + _port++ } @@ -17,7 +16,7 @@ let fastify = null let signalCounter = null const sandbox = sinon.createSandbox() -t.beforeEach(async () => { +test.beforeEach(async () => { signalCounter = process.listenerCount('SIGINT') const argv = ['-p', getPort(), './examples/plugin.js'] @@ -25,27 +24,25 @@ t.beforeEach(async () => { spy = sinon.spy(fastify, 'close') }) -t.afterEach(async () => { +test.afterEach(async () => { sandbox.restore() }) -test('should add and remove SIGINT listener as expected ', async t => { +test('should add and remove SIGINT listener as expected', async (t) => { t.plan(2) - t.equal(process.listenerCount('SIGINT'), signalCounter + 1) + t.assert.strictEqual(process.listenerCount('SIGINT'), signalCounter + 1) await fastify.close() - t.equal(process.listenerCount('SIGINT'), signalCounter) - - t.end() + t.assert.strictEqual(process.listenerCount('SIGINT'), signalCounter) }) test('should have called fastify.close() when receives a SIGINT signal', async t => { process.once('SIGINT', () => { sinon.assert.called(spy) - t.end() + t.assert.ok('SIGINT signal handler called') process.exit() }) From ea9ec29711bdb48fe2df26debf9ac3e463ace09b Mon Sep 17 00:00:00 2001 From: Tony133 Date: Sat, 19 Jul 2025 12:54:33 +0200 Subject: [PATCH 02/10] chore: update test --- test/graceful-shutdown.test.js | 43 ++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/test/graceful-shutdown.test.js b/test/graceful-shutdown.test.js index 8d1b0935..345df0cd 100644 --- a/test/graceful-shutdown.test.js +++ b/test/graceful-shutdown.test.js @@ -1,8 +1,7 @@ 'use strict' -const { test } = require('node:test') -// Tests skip on win32 platforms due SIGINT signal is not supported across all windows platforms -const testWin = (process.platform === 'win32') ? test.skip : test +const { test, beforeEach, afterEach } = require('node:test') +const assert = require('assert') const sinon = require('sinon') const start = require('../start') @@ -11,12 +10,16 @@ function getPort () { return '' + _port++ } -let spy = null let fastify = null +let spy = null let signalCounter = null const sandbox = sinon.createSandbox() -test.beforeEach(async () => { +// Skip tests on Windows +const isWindows = process.platform === 'win32' +const conditionalTest = isWindows ? test.skip : test + +beforeEach(async () => { signalCounter = process.listenerCount('SIGINT') const argv = ['-p', getPort(), './examples/plugin.js'] @@ -24,28 +27,28 @@ test.beforeEach(async () => { spy = sinon.spy(fastify, 'close') }) -test.afterEach(async () => { +afterEach(async () => { sandbox.restore() }) -test('should add and remove SIGINT listener as expected', async (t) => { - t.plan(2) - - t.assert.strictEqual(process.listenerCount('SIGINT'), signalCounter + 1) +conditionalTest('should add and remove SIGINT listener as expected', async (t) => { + assert.strictEqual(process.listenerCount('SIGINT'), signalCounter + 1) await fastify.close() - t.assert.strictEqual(process.listenerCount('SIGINT'), signalCounter) + assert.strictEqual(process.listenerCount('SIGINT'), signalCounter) }) -test('should have called fastify.close() when receives a SIGINT signal', async t => { - process.once('SIGINT', () => { - sinon.assert.called(spy) - - t.assert.ok('SIGINT signal handler called') - - process.exit() - }) - +conditionalTest('should call fastify.close() on SIGINT', async (t) => { + const sigintHandler = () => { + try { + sinon.assert.called(spy) + t.pass('fastify.close() was called on SIGINT') + } finally { + process.exit() // Clean exit + } + } + + process.once('SIGINT', sigintHandler) process.kill(process.pid, 'SIGINT') }) From e6a43cf338ce02b55487f87abf2c220990aba575 Mon Sep 17 00:00:00 2001 From: Tony133 Date: Tue, 19 Aug 2025 18:16:30 +0200 Subject: [PATCH 03/10] fix: update test --- test/graceful-shutdown.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/graceful-shutdown.test.js b/test/graceful-shutdown.test.js index 345df0cd..57d7f712 100644 --- a/test/graceful-shutdown.test.js +++ b/test/graceful-shutdown.test.js @@ -43,7 +43,7 @@ conditionalTest('should call fastify.close() on SIGINT', async (t) => { const sigintHandler = () => { try { sinon.assert.called(spy) - t.pass('fastify.close() was called on SIGINT') + t.assert.ok('fastify.close() was called on SIGINT') } finally { process.exit() // Clean exit } From 42b7cbf46abfc3dd4a9b51843ea5b59e08d9fccd Mon Sep 17 00:00:00 2001 From: Tony133 Date: Tue, 19 Aug 2025 20:55:24 +0200 Subject: [PATCH 04/10] fix: added plan method --- test/graceful-shutdown.test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/graceful-shutdown.test.js b/test/graceful-shutdown.test.js index 57d7f712..1b844342 100644 --- a/test/graceful-shutdown.test.js +++ b/test/graceful-shutdown.test.js @@ -32,6 +32,7 @@ afterEach(async () => { }) conditionalTest('should add and remove SIGINT listener as expected', async (t) => { + t.plan(2) assert.strictEqual(process.listenerCount('SIGINT'), signalCounter + 1) await fastify.close() @@ -40,6 +41,7 @@ conditionalTest('should add and remove SIGINT listener as expected', async (t) = }) conditionalTest('should call fastify.close() on SIGINT', async (t) => { + t.plan(1) const sigintHandler = () => { try { sinon.assert.called(spy) From 5b7f942482e306c4be497409aa1232031c2c5ecd Mon Sep 17 00:00:00 2001 From: Tony133 Date: Wed, 20 Aug 2025 09:20:15 +0200 Subject: [PATCH 05/10] test: update test --- test/graceful-shutdown.test.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/test/graceful-shutdown.test.js b/test/graceful-shutdown.test.js index 1b844342..877898e3 100644 --- a/test/graceful-shutdown.test.js +++ b/test/graceful-shutdown.test.js @@ -1,7 +1,6 @@ 'use strict' const { test, beforeEach, afterEach } = require('node:test') -const assert = require('assert') const sinon = require('sinon') const start = require('../start') @@ -33,21 +32,20 @@ afterEach(async () => { conditionalTest('should add and remove SIGINT listener as expected', async (t) => { t.plan(2) - assert.strictEqual(process.listenerCount('SIGINT'), signalCounter + 1) - + const initialCount = process.listenerCount('SIGINT') + t.assert.strictEqual(initialCount, signalCounter + 1) await fastify.close() - - assert.strictEqual(process.listenerCount('SIGINT'), signalCounter) + t.assert.strictEqual(process.listenerCount('SIGINT'), signalCounter) }) -conditionalTest('should call fastify.close() on SIGINT', async (t) => { - t.plan(1) - const sigintHandler = () => { +conditionalTest('should call fastify.close() on SIGINT', (t) => { + const sigintHandler = async () => { try { sinon.assert.called(spy) t.assert.ok('fastify.close() was called on SIGINT') } finally { - process.exit() // Clean exit + process.removeListener('SIGINT', sigintHandler) + await fastify.close() } } From 8a2e473216183df2b66940eb991bcc24ceb5acc4 Mon Sep 17 00:00:00 2001 From: Antonio Tripodi Date: Wed, 20 Aug 2025 09:46:18 +0200 Subject: [PATCH 06/10] chore: update graceful-shutdown.test.js Co-authored-by: Manuel Spigolon Signed-off-by: Antonio Tripodi --- test/graceful-shutdown.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/graceful-shutdown.test.js b/test/graceful-shutdown.test.js index 877898e3..92d2854e 100644 --- a/test/graceful-shutdown.test.js +++ b/test/graceful-shutdown.test.js @@ -30,7 +30,7 @@ afterEach(async () => { sandbox.restore() }) -conditionalTest('should add and remove SIGINT listener as expected', async (t) => { +test('should add and remove SIGINT listener as expected', { skip: isWindows }, async (t) => { t.plan(2) const initialCount = process.listenerCount('SIGINT') t.assert.strictEqual(initialCount, signalCounter + 1) From 0e5cef3e2606e0ce0528a0e2449eb75cc132ccfd Mon Sep 17 00:00:00 2001 From: Tony133 Date: Wed, 20 Aug 2025 09:51:20 +0200 Subject: [PATCH 07/10] test: update test --- test/graceful-shutdown.test.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/graceful-shutdown.test.js b/test/graceful-shutdown.test.js index 92d2854e..866c926d 100644 --- a/test/graceful-shutdown.test.js +++ b/test/graceful-shutdown.test.js @@ -14,9 +14,11 @@ let spy = null let signalCounter = null const sandbox = sinon.createSandbox() -// Skip tests on Windows +// Skip tests on Windows, Linux and MacOS const isWindows = process.platform === 'win32' -const conditionalTest = isWindows ? test.skip : test +const isMacOS = process.platform === 'darwin' +const isLinux = process.platform === 'linux' +const conditionalTest = (isWindows || isMacOS || isLinux) ? test.skip : test beforeEach(async () => { signalCounter = process.listenerCount('SIGINT') From 239ccdb4532635dd70e0238cdfbfc251a430841c Mon Sep 17 00:00:00 2001 From: Antonio Tripodi Date: Wed, 20 Aug 2025 14:45:31 +0200 Subject: [PATCH 08/10] chore: add comment Co-authored-by: Manuel Spigolon Signed-off-by: Antonio Tripodi --- test/graceful-shutdown.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/graceful-shutdown.test.js b/test/graceful-shutdown.test.js index 866c926d..276fbf0b 100644 --- a/test/graceful-shutdown.test.js +++ b/test/graceful-shutdown.test.js @@ -32,6 +32,7 @@ afterEach(async () => { sandbox.restore() }) +// Tests skip on win32 platforms due SIGINT signal is not supported across all windows platforms test('should add and remove SIGINT listener as expected', { skip: isWindows }, async (t) => { t.plan(2) const initialCount = process.listenerCount('SIGINT') From 669819e7eb6d8f40bee43a5b2ef9e20d4296cffa Mon Sep 17 00:00:00 2001 From: Antonio Tripodi Date: Wed, 20 Aug 2025 14:46:20 +0200 Subject: [PATCH 09/10] chore: update graceful-shutdown.test.js Co-authored-by: Manuel Spigolon Signed-off-by: Antonio Tripodi --- test/graceful-shutdown.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/graceful-shutdown.test.js b/test/graceful-shutdown.test.js index 276fbf0b..5905d5f0 100644 --- a/test/graceful-shutdown.test.js +++ b/test/graceful-shutdown.test.js @@ -41,7 +41,7 @@ test('should add and remove SIGINT listener as expected', { skip: isWindows }, a t.assert.strictEqual(process.listenerCount('SIGINT'), signalCounter) }) -conditionalTest('should call fastify.close() on SIGINT', (t) => { +test('should call fastify.close() on SIGINT', { skip: isWindows || isMacOS || isLinux }, (t) => { const sigintHandler = async () => { try { sinon.assert.called(spy) From b8d7b8414f98e48f5a85bcab7cd820aafcb238a6 Mon Sep 17 00:00:00 2001 From: Antonio Tripodi Date: Wed, 20 Aug 2025 14:46:42 +0200 Subject: [PATCH 10/10] chore: remove conditionalTest Co-authored-by: Manuel Spigolon Signed-off-by: Antonio Tripodi --- test/graceful-shutdown.test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/graceful-shutdown.test.js b/test/graceful-shutdown.test.js index 5905d5f0..2eb48351 100644 --- a/test/graceful-shutdown.test.js +++ b/test/graceful-shutdown.test.js @@ -18,7 +18,6 @@ const sandbox = sinon.createSandbox() const isWindows = process.platform === 'win32' const isMacOS = process.platform === 'darwin' const isLinux = process.platform === 'linux' -const conditionalTest = (isWindows || isMacOS || isLinux) ? test.skip : test beforeEach(async () => { signalCounter = process.listenerCount('SIGINT')