1
1
'use strict'
2
2
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' )
6
4
const sinon = require ( 'sinon' )
7
5
const start = require ( '../start' )
8
6
9
7
let _port = 3001
10
-
11
8
function getPort ( ) {
12
9
return '' + _port ++
13
10
}
@@ -17,35 +14,36 @@ let fastify = null
17
14
let signalCounter = null
18
15
const sandbox = sinon . createSandbox ( )
19
16
20
- t . beforeEach ( async ( ) => {
17
+ test . beforeEach ( async ( ) => {
21
18
signalCounter = process . listenerCount ( 'SIGINT' )
22
19
23
20
const argv = [ '-p' , getPort ( ) , './examples/plugin.js' ]
24
21
fastify = await start . start ( argv )
25
22
spy = sinon . spy ( fastify , 'close' )
26
23
} )
27
24
28
- t . afterEach ( async ( ) => {
25
+ test . afterEach ( async ( ) => {
26
+ if ( fastify ) {
27
+ await fastify . close ( )
28
+ }
29
29
sandbox . restore ( )
30
30
} )
31
31
32
- test ( 'should add and remove SIGINT listener as expected ' , async t => {
32
+ test ( 'should add and remove SIGINT listener as expected' , async ( t ) => {
33
33
t . plan ( 2 )
34
34
35
- t . equal ( process . listenerCount ( 'SIGINT' ) , signalCounter + 1 )
35
+ t . assert . strictEqual ( process . listenerCount ( 'SIGINT' ) , signalCounter + 1 )
36
36
37
37
await fastify . close ( )
38
38
39
- t . equal ( process . listenerCount ( 'SIGINT' ) , signalCounter )
40
-
41
- t . end ( )
39
+ t . assert . strictEqual ( process . listenerCount ( 'SIGINT' ) , signalCounter )
42
40
} )
43
41
44
42
test ( 'should have called fastify.close() when receives a SIGINT signal' , async t => {
45
43
process . once ( 'SIGINT' , ( ) => {
46
44
sinon . assert . called ( spy )
47
45
48
- t . end ( )
46
+ t . assert . ok ( 'SIGINT signal handler called' )
49
47
50
48
process . exit ( )
51
49
} )
0 commit comments