Skip to content
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

Merged
merged 11 commits into from
Aug 30, 2019
Merged

Debug mode for Fastify CLI Start #202

merged 11 commits into from
Aug 30, 2019

Conversation

HighSoftWare96
Copy link
Contributor

@HighSoftWare96 HighSoftWare96 commented Aug 29, 2019

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

  • Programmatically call inspector.open right before running Fastify for the current process when debug mode active. Refs: https://nodejs.org/api/inspector.html
  • Updated readme.md documentation

Contributions

This PR was created referring this issue: #200. Thanks also to @pyxarez and @xtx1130. Feel free to contribute.

Checklist

  • [-] run npm run test and npm run benchmark
  • [-] tests and/or benchmarks are included
  • [-] documentation is changed or added
  • [-] commit message and code follows Code of conduct

Copy link
Member

@mcollina mcollina left a 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')
Copy link
Member

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?

Copy link
Contributor Author

@HighSoftWare96 HighSoftWare96 Aug 29, 2019

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 :)

Copy link
Member

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!

@HighSoftWare96
Copy link
Contributor Author

uld you mind adding a quick example that adds a test using

I'm not confident with this tool. What should I do?

@mcollina
Copy link
Member

I would do something like:

proxyquire('../start', {
  inspector: {
    open () {
      t.pass('open called')
    }
  }
})

lib/watch/index.js Outdated Show resolved Hide resolved
start.js Outdated Show resolved Hide resolved
@HighSoftWare96
Copy link
Contributor Author

@xtx1130 would you mind complete the PR with the tests referred by @mcollina? I have not enough time and so the PR will be completed

Co-Authored-By: 小菜 <xtx1130@gmail.com>
@xtx1130
Copy link
Contributor

xtx1130 commented Aug 30, 2019

@HighSoftWare96 It soon be a weekend in china. I can finish it after 2 days if you don't mind.
@mcollina Would you mind merge this pr into master, and I will add a test-case for this in another pr?

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mcollina mcollina merged commit 22e4c1e into fastify:master Aug 30, 2019
@xtx1130 xtx1130 mentioned this pull request Sep 2, 2019
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants