Skip to content
This repository has been archived by the owner on Nov 15, 2021. It is now read-only.

Fix usage with --inspect flag #23

Merged
merged 3 commits into from
Nov 23, 2019
Merged

Fix usage with --inspect flag #23

merged 3 commits into from
Nov 23, 2019

Conversation

nventuro
Copy link
Contributor

@nventuro nventuro commented Nov 22, 2019

Mocha has poor error reporting for crashes that happen before tests start running. For those situations, the recommended debugging method is to use the --inspect flag, which is a Node feature.

Currently, when using --inspect along with test-environment, the following happens:

  • the debugging server is started and correctly reports errors
  • the ganache server fails to load (all calls to it timeout)
  • the following message is logged: Starting inspector on 127.0.0.1:9229 failed: address already in use

What is going on here is a bit tricky. --inspect creates a server in port 9229, so no two processes may run with that flag at the same time. However, as has been noted on the Node repo, this is precisely what happens with .fork is used. This is because fork forwards execArgv by default, passing the child process the same options the parent one received (process.execArgv).

From the Node docs:

process.execArgv
This is the set of node-specific command line options from the executable that started the process. These options do not show up in process.argv, and do not include the node executable, the name of the script, or any options following the script name. These options are useful in order to spawn child processes with the same execution environment as the parent.

To preserve this intended behaviour, this PR simply prevents the --inspect flag from being forwarded.

@frangio
Copy link
Contributor

frangio commented Nov 23, 2019

Perfect fix, thank you. Do you have a link to the way Mocha is used with --inspect? I would like to understand the expectations of someone using the flag, and if disabling the flag for the forked process would result in anything unexpected. In any case there doesn’t seem to be any alternative.

@nventuro
Copy link
Contributor Author

From my understanding, --inspect is quite powerful and is a generally useful debugging tool. In Mocha's case, the use I've found for it is simply to debug issues in the setup of the suite, where Mocha will simply print the error message and not show a stack trace, or even the file or line number that emitted the error.

@nventuro nventuro merged commit 0036da3 into master Nov 23, 2019
@nventuro nventuro deleted the node-inspect-fix branch November 23, 2019 23:48
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants