-
Notifications
You must be signed in to change notification settings - Fork 164
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
Debug mode for Fastify CLI Start #202
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work! Would you mind adding a quick example that adds a test using https://www.npmjs.com/package/proxyquire?
start.js
Outdated
@@ -13,6 +13,7 @@ const listenAddressDocker = '0.0.0.0' | |||
const watch = require('./lib/watch') | |||
const parseArgs = require('./args') | |||
const { exit, requireFastifyForModule, requireServerPluginFromPath, showHelpForCommand } = require('./util') | |||
const inspector = require('inspector') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are still supporting node 6, and this is not available there. Would you mind loading this module only in that case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I understand it is a experimental feature of nodejs but it was the simplest way to do that :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's brilliant, definitely +1!
I'm not confident with this tool. What should I do? |
I would do something like: proxyquire('../start', {
inspector: {
open () {
t.pass('open called')
}
}
}) |
Co-Authored-By: 小菜 <xtx1130@gmail.com>
@HighSoftWare96 It soon be a weekend in china. I can finish it after 2 days if you don't mind. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Feature
With this PR you should be able to run a FastifyCLI-generated app with NodeJS inspector on a chosen port. The added flags are:
-d
(--debug
) for enabling the debug mode and-I
(--debug-port
) for choosing a debug port. Works even in--watch
mode.What was done
inspector.open
right before running Fastify for the current process when debug mode active. Refs: https://nodejs.org/api/inspector.htmlContributions
This PR was created referring this issue: #200. Thanks also to @pyxarez and @xtx1130. Feel free to contribute.
Checklist
npm run test
andnpm run benchmark