11'use strict'
22
3- const t = require ( 'tap' )
4- // Tests skip on win32 platforms due SIGINT signal is not supported across all windows platforms
5- const test = ( process . platform === 'win32' ) ? t . skip : t . test
3+ const { test } = require ( 'node:test' )
64const sinon = require ( 'sinon' )
75const start = require ( '../start' )
86
97let _port = 3001
10-
118function getPort ( ) {
129 return '' + _port ++
1310}
@@ -17,35 +14,36 @@ let fastify = null
1714let signalCounter = null
1815const sandbox = sinon . createSandbox ( )
1916
20- t . beforeEach ( async ( ) => {
17+ test . beforeEach ( async ( ) => {
2118 signalCounter = process . listenerCount ( 'SIGINT' )
2219
2320 const argv = [ '-p' , getPort ( ) , './examples/plugin.js' ]
2421 fastify = await start . start ( argv )
2522 spy = sinon . spy ( fastify , 'close' )
2623} )
2724
28- t . afterEach ( async ( ) => {
25+ test . afterEach ( async ( ) => {
26+ if ( fastify ) {
27+ await fastify . close ( )
28+ }
2929 sandbox . restore ( )
3030} )
3131
32- test ( 'should add and remove SIGINT listener as expected ' , async t => {
32+ test ( 'should add and remove SIGINT listener as expected' , async ( t ) => {
3333 t . plan ( 2 )
3434
35- t . equal ( process . listenerCount ( 'SIGINT' ) , signalCounter + 1 )
35+ t . assert . strictEqual ( process . listenerCount ( 'SIGINT' ) , signalCounter + 1 )
3636
3737 await fastify . close ( )
3838
39- t . equal ( process . listenerCount ( 'SIGINT' ) , signalCounter )
40-
41- t . end ( )
39+ t . assert . strictEqual ( process . listenerCount ( 'SIGINT' ) , signalCounter )
4240} )
4341
4442test ( 'should have called fastify.close() when receives a SIGINT signal' , async t => {
4543 process . once ( 'SIGINT' , ( ) => {
4644 sinon . assert . called ( spy )
4745
48- t . end ( )
46+ t . assert . ok ( 'SIGINT signal handler called' )
4947
5048 process . exit ( )
5149 } )
0 commit comments