-
-
Notifications
You must be signed in to change notification settings - Fork 173
test: migrated graceful-shutdown.test.js from tap to node:test #825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Tony133
wants to merge
10
commits into
fastify:main
Choose a base branch
from
Tony133:test/migrated-graceful-shutdown-test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
61c443c
test: migrated graceful-shutdown.test.js from tap to node:test
Tony133 ea9ec29
chore: update test
Tony133 e6a43cf
fix: update test
Tony133 42b7cbf
fix: added plan method
Tony133 5b7f942
test: update test
Tony133 8a2e473
chore: update graceful-shutdown.test.js
Tony133 0e5cef3
test: update test
Tony133 239ccdb
chore: add comment
Tony133 669819e
chore: update graceful-shutdown.test.js
Tony133 b8d7b84
chore: remove conditionalTest
Tony133 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,56 @@ | ||
'use strict' | ||
|
||
const t = require('tap') | ||
// 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 { test, beforeEach, afterEach } = require('node:test') | ||
const sinon = require('sinon') | ||
const start = require('../start') | ||
|
||
let _port = 3001 | ||
|
||
function getPort () { | ||
return '' + _port++ | ||
} | ||
|
||
let spy = null | ||
let fastify = null | ||
let spy = null | ||
let signalCounter = null | ||
const sandbox = sinon.createSandbox() | ||
|
||
t.beforeEach(async () => { | ||
// Skip tests on Windows, Linux and MacOS | ||
const isWindows = process.platform === 'win32' | ||
const isMacOS = process.platform === 'darwin' | ||
const isLinux = process.platform === 'linux' | ||
|
||
beforeEach(async () => { | ||
signalCounter = process.listenerCount('SIGINT') | ||
|
||
const argv = ['-p', getPort(), './examples/plugin.js'] | ||
fastify = await start.start(argv) | ||
spy = sinon.spy(fastify, 'close') | ||
}) | ||
|
||
t.afterEach(async () => { | ||
afterEach(async () => { | ||
sandbox.restore() | ||
}) | ||
|
||
test('should add and remove SIGINT listener as expected ', async t => { | ||
// 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) | ||
|
||
t.equal(process.listenerCount('SIGINT'), signalCounter + 1) | ||
|
||
const initialCount = process.listenerCount('SIGINT') | ||
t.assert.strictEqual(initialCount, 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() | ||
|
||
process.exit() | ||
}) | ||
|
||
test('should call fastify.close() on SIGINT', { skip: isWindows || isMacOS || isLinux }, (t) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if this will not run on windows, macos and linux..it means essentially that will never run |
||
const sigintHandler = async () => { | ||
try { | ||
sinon.assert.called(spy) | ||
t.assert.ok('fastify.close() was called on SIGINT') | ||
} finally { | ||
process.removeListener('SIGINT', sigintHandler) | ||
await fastify.close() | ||
} | ||
} | ||
|
||
process.once('SIGINT', sigintHandler) | ||
process.kill(process.pid, 'SIGINT') | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.