Skip to content

Commit 2a31fae

Browse files
committed
test: migrated graceful-shutdown.test.js from tap to node:test
1 parent 44a2221 commit 2a31fae

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

test/graceful-shutdown.test.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
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')
64
const sinon = require('sinon')
75
const start = require('../start')
86

97
let _port = 3001
10-
118
function getPort () {
129
return '' + _port++
1310
}
@@ -17,35 +14,36 @@ let fastify = null
1714
let signalCounter = null
1815
const 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

4442
test('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

Comments
 (0)