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

Add support for using 'node --inspect' to debug tests #108

Open
micellius opened this issue Nov 4, 2014 · 5 comments · May be fixed by #109
Open

Add support for using 'node --inspect' to debug tests #108

micellius opened this issue Nov 4, 2014 · 5 comments · May be fixed by #109

Comments

@micellius
Copy link

It would be beneficial to have Node.js debugging capabilities for tests.

Note:
Currently, when starting node-qunit CLI in debug mode using --debug-brk child processes created by testrunner are created with the same debugging port, which causes an error.

Requirements:

  • node-qunit should have a configurable parameter that will trigger child processes to run in debug mode on port provided by this parameter.
  • If node-qunit itself is running in debug mode and no port is provided by parameter, node-qunit should be able to find free port and use it for debugging of child process.
  • Since node-qunit spawns new process for each test file, debugging port should be configurable for each test file.
  • Infinite loop validation should be disabled for child processes running in debug mode

Usage:

  • Using --debug parameter and list of ports in the same order as test files
    $ node node_modules/qunit/bin/cli.js -c code.js -t test1.js test2.js --debug 54890 40893
  • Starting node-qunit in debug mode using --debug-brk
    $ node --debug-brk=56566 node_modules/qunit/bin/cli.js -c code.js -t test1.js test2.js
@kof
Copy link
Contributor

kof commented Nov 4, 2014

Could we fully automate ports selection so that there is no need for defining ports?

@micellius
Copy link
Author

Yes, it's exactly the second case in the usage section, where no ports configuration is provided and they are chosen automatically. Once process is running in debug mode NodeJS prints debug port, so auto generated port will be sufficient to connect to the process using debugger. Port configuration option is mostly enhancement that will allow to have some fixed debugging configuration in IDE (I'm using "Node.js remote debug" option in WebStorm) that should not be updated each time. I'm currently working on PR, but I'm pretty sure that your implementation will be definitely better.

Regarding implementation I think it should be something like the code below (in testrunner.js before forking the process)

function runOne(opts, callback) {
    ...
    var debug = process.execArgv.reduce(function(prevArg, curArg) {
        return prevArg || curArg.indexOf('--debug') === 0;
    }, false);

    if(debug) {
        process.execArgv.push('--debug-brk=' + freePort);
    }
    ...
}

Inspired by this post on StackOverflow.
To find free port freeport or find-free-port may be used.

P.S.
Thanks a lot for your responsiveness and cooperation! I'm really appreciate this.

micellius added a commit to micellius/node-qunit that referenced this issue Nov 4, 2014
When cli.js executed by Node.js running in debug mode, child processes are also running in debug mode with different port.
It is possible to run cli.js in normal mode and debug only child processes using --debug option.
It is possible to specify debug port after --debug option.

Close qunitjs#108.
@micellius micellius linked a pull request Nov 4, 2014 that will close this issue
@micellius
Copy link
Author

After looking on code more deep I realised that cli.js spawns only one child process (spawning multiple child processes is only available via API), thus there is no need in list of ports - only one debugging port is needed. Specifying port is also may be optional since it may be auto generated.

@kof I've submitted PR few minutes ago, please take a look. I'm sure you know how to do it better, but idea remains the same. At least for me it solved the problem with test debugging.

@Krinkle Krinkle changed the title [Feature Request] Add capability to debug tests Add support for using 'node --inspect' to debug tests Mar 10, 2017
@rromanchenko
Copy link

Hi, guys. Just curious, if you are going to complete this enhancement and provide an ability to debug execution of tests by node-qunit?
Thanks.

@Krinkle
Copy link
Member

Krinkle commented Sep 12, 2020

I believe you can use Node.js CLI options such as --inspect via the NODE_OPTIONS environment variable. For example:

NODE_OPTIONS='--inspect' qunit test/index.js

That will not cover sub processes, but at least it solves the issue of being able to use the qunit command without needin the full path to the js file with the node command.

Also consider using the official QUnit CLI, which might suite your needs: https://qunitjs.com/cli/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

4 participants