Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Debug Grunt Mocha Task?

I am using WebStorm to run a grunt task. The debugger successfully stops at the breakpoint in the Gruntfile.js file, but not in my task file.

In the Gruntfile.js I register a task like this:

grunt.initConfig({
  ... configuration ...
});    
grunt.registerTask('myTask', ['mocha:myTask']);

When I set a breakpoint in the corresponding js file for the test 'myTask' it doesn't stop. How can I debug also the grunt tests?


--- UPDATE ---------------------------------------

so i tried all of your possible solutions, but it does not solve my problem!

I am able to debug the grunt script itself, this is where the debugger actually stops (either in WebStorm or node-inspector). Also a breakpoint in Gruntfile.js is working.

The problem is, that I am not able to debug the actual Grunt task itself, registered with grunt like this: grunt.registerTask('myTask', ['mocha:myTask']);

I am also able to debug the mocha test itself. But I want to debug a mocha test called from grunt task runner. Any ideas?

like image 875
electronix384128 Avatar asked Sep 23 '14 14:09

electronix384128


3 Answers

To run grunt task in debug, you need to pass the grunt task script to node-inspector:

node-debug $(Path \AppData\Roaming\npm\node_modules\grunt-cli\bin\grunt) task

Put a debugger; line in your task. node-inspector will then open a browser with debugging tools.

This link help you how its work grunt-node-inspector

Example: ChrisWren/grunt-node-inspector

Source: Stackoverflow Question

like image 81
Prateek Avatar answered Nov 03 '22 03:11

Prateek


Finally I am able to debug my mocha tasks! Thanks for all your answers and comments, but unfortunately I have to select my own answer, because that is the only one that worked for me.

Thanks to this video I found out what I was missing: http://vimeo.com/97561531

Basically it was two things:

  1. Add a "debug-brk" option to grunt's mocha configuration:

    grunt.initConfig({
        ...
            "options": {
                "mocha": {
                    ...
                    "debug-brk": (grunt.option('debug-brk')) ? "" : 0
                }
            }
    }
    
  2. Configure WebStorm's Debug Configuration like this:

    WebStorm's Debug Config to Halt on debug-brk

like image 24
electronix384128 Avatar answered Nov 03 '22 01:11

electronix384128


If you happen to use the WebStorm IDE you can set up a task and then either run or debug it.

You can see the configuration for the command grunt jasmine_node_no_coverage in the screenshot. Please note that I installed grunt globally.

Configuration of the task in WebStorm

like image 41
analog-nico Avatar answered Nov 03 '22 02:11

analog-nico