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

Debugger support #342

Closed
hberntsen opened this issue Dec 16, 2015 · 15 comments
Closed

Debugger support #342

hberntsen opened this issue Dec 16, 2015 · 15 comments

Comments

@hberntsen
Copy link

The README.md gives me the impression that debugging of tests is possible with the --serial option. It looks like this option is designed for debugging ava itself though.

I tried debugging tests in the following way:

  1. ava --init

  2. npm install signal-exit

  3. Based on add covenience util for debugging #225, put the following code in node_modules/ava/debug.js

    #!/usr/bin/env node
    'use strict';
    
    var onExit = require('signal-exit');
    var chalk = require('chalk');
    
    process.send = function (data) {
    console.dir(data);
    };
    
    onExit(function () {
    process.emit('ava-cleanup', true);
    });
    
    require('./lib/babel');
  4. Make a simple test with a debugger keyword:

    import test from 'ava';
    
    test(t => {
    debugger;
    t.same([4, 2], [1, 2]);
    });
  5. node debug node_modules/ava/debug.js " {\"file\":\"path/to/test.js\",\"failFast\":false,\"serial\":true,\"require\":[]} "

When running this via the node debugger (or node inspector) the breakpoint is not triggered, possibly due to the code transformations via babel.

Since ava spawns new processes, debugging cli.js directly is not possible. The new node processes try to listen to the same debug port and thus crash with EADDRINUSE :::5858. By hacking fork.js and adding options['execArgv'] = ['--debug-brk=5860']; I could attach node inspector to this port but it still failed to trigger my breakpoint within the test.

Is there any way to use a debugger for my tests?

@sindresorhus sindresorhus added enhancement new functionality question labels Dec 16, 2015
@sindresorhus
Copy link
Member

What Node.js version are you on?

Debugging is broken in Node.js 5.2.

@hberntsen
Copy link
Author

v5.1.1 (from the Debian experimental repository). Simple debugging works:

$ node debug testdebug.js
< Debugger listening on port 5858
debug> . ok
break in testdebug.js:1
> 1 console.log('1');
  2 console.log('2');
  3 debugger;
debug> c
< 1
< 2
break in testdebug.js:3
  1 console.log('1');
  2 console.log('2');
> 3 debugger;
  4 console.log('3');
  5 
debug> 

@sindresorhus
Copy link
Member

We definitely want to support using the debugger, but not really sure from the top of my head what's preventing it. We'll look into it. Thanks for reporting @hberntsen :)

@jamestalmage might have a better idea.

possibly due to the code transformations via babel.

I thought https://github.com/sindresorhus/ava/blob/df48ce69b841c8b5fb1f522aa435d3a676876078/lib/babel.js#L26-L37 did that for us. // @novemberborn

options['execArgv'] = ['--debug-brk=5860'];

Any downside adding this to AVA?

@jamestalmage
Copy link
Contributor

Since ava spawns new processes, debugging cli.js directly is not possible. The new node processes try to listen to the same debug port and thus crash with EADDRINUSE :::5858

That is going to be additionally problematic since AVA will potentially spawn a number of processes at once if you have multiple test files.

I thought that ... did that for us

I think this is separate from remapping coverage/sourcemaps.

Any downside adding this to AVA?

Only the multiple process issue. Can we detect if the debugger is in use and enforce serial execution of the test files?

@sindresorhus
Copy link
Member

I think this is separate from remapping coverage/sourcemaps.

Chrome DevToools use source maps to adjusts breakpoints too, so I just assumed this would do that too.

Can we detect if the debugger is in use and enforce serial execution of the test files?

Maybe, but I think it would be better to be explicit about it. I think it would be worth introducing a --debug flag that activates --serial and other things related to debugging. Thoughts?

@vadimdemedes
Copy link
Contributor

I think it would be worth introducing a --debug flag that activates --serial and other things related to debugging

+1!

@develar
Copy link
Contributor

develar commented Jan 30, 2016

We, JetBrains, cannot support debug AVA tests without changes on your side. I will send you pull request next week.

General information — https://intellij-support.jetbrains.com/hc/en-us/community/posts/206193339-Debugging-node-child-processes?page=1#community_comment_206895729

My solution — https://github.com/sindresorhus/ava/compare/master...develar:debug?expand=1 (not yet reviewed by my experienced college).

Run configuration —
screen shot 2016-01-30 at 16 53 30

Please note — babel debug in JetBrains IDE is broken in node 5.x, I use my custom build of node 5.x (nodejs/node#4231).

@develar
Copy link
Contributor

develar commented Jan 30, 2016

Another problem on AVA side: CachingPrecompiler produces source map, but... debug doesn't work in any case because generated source file doesn't contain sourceMappingURL AVA CachingPrecompiler must add sourceMappingURL explicitly.

So, IDE cannot map source file to transpired because no sourceMappingURL. And breakpoints don't work correctly.

Yes, it is very strange that babel does so, I found related issue — babel/grunt-babel#13

This change will be also in my pull request. For now, you can set both. Do you have any reasons to produce external source maps instead of inline?

Please note again — babel debug in JetBrains IDE is broken in node 5.x, I use my custom build of node 5.x (nodejs/node#4231). Also, to speed up, enable lazy compilation — nodejs/node#877 (comment)

After set sourceMaps to both, don't forget to detele cache (node_modules/.cache/ava) to apply change.

@jontonsoup
Copy link

I'd love to see an addition to the readme on how to use the debugger for new users. :)

@novemberborn
Copy link
Member

Another problem on AVA side: CachingPrecompiler produces source map, but... debug doesn't work in any case because generated source file doesn't contain sourceMappingURL AVA CachingPrecompiler must add sourceMappingURL explicitly.

@develar this was resolved in #662.

develar added a commit to develar/ava that referenced this issue May 25, 2016
develar added a commit to develar/ava that referenced this issue May 25, 2016
develar added a commit to develar/ava that referenced this issue May 27, 2016
develar added a commit to develar/ava that referenced this issue May 27, 2016
develar added a commit to develar/ava that referenced this issue Jun 18, 2016
develar added a commit to develar/ava that referenced this issue Jun 18, 2016
develar added a commit to develar/ava that referenced this issue Jun 18, 2016
develar added a commit to develar/ava that referenced this issue Jun 20, 2016
develar added a commit to develar/ava that referenced this issue Jun 20, 2016
develar added a commit to develar/ava that referenced this issue Jun 20, 2016
develar added a commit to develar/ava that referenced this issue Jun 20, 2016
…cess.execArgv in tests instead of local option
valorkin added a commit to valorkin/child-process-debug that referenced this issue Jul 21, 2016
Replacing unshift with push allows to users to have expected order of argumets
relates to avajs/ava#342
@azakordonets
Copy link

The issue is still open - does it mean that it's still impossible to debug AVA tests in IDEA or Webstorm ?

@jimbuck
Copy link

jimbuck commented Jul 29, 2016

@azakordonets or VS Code?

@azakordonets
Copy link

@JimmyBoh i prefer products from Intellij :)

@develar
Copy link
Contributor

develar commented Jul 29, 2016

@JimmyBoh Only WebStorm currently provides the best AVA debug. #874 (comment)

@azakordonets Please see #874 I hope it will be accepted soon.

@azakordonets
Copy link

@develar Thanks a lot :) I've subscribed for that issue

develar added a commit to develar/ava that referenced this issue Jul 31, 2016
develar added a commit to develar/ava that referenced this issue Jul 31, 2016
develar added a commit to develar/ava that referenced this issue Aug 9, 2016
develar added a commit to develar/ava that referenced this issue Aug 9, 2016
develar added a commit to develar/ava that referenced this issue Aug 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants