-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
set child process debug port to an available port - fixes #342 #874
Conversation
In addition to unit tests, you should have a few integration tests. We can help figure out why NYC causes a failure. |
7f63137
to
8815163
Compare
Integration test added. Maybe on CI it will be passed, but on my machine I got "Test files must be run with the AVA CLI:" from child stderr if use |
CI failed " not ok AvaError: test/fixture/debug-arg.js exited with a non-zero exit code: 1" Hmm... it works for me — I use fork of ava in my project and can debug tests in IntelliJ IDEA. Something is wrong with nyc, but I don't see how it it is connected. If you will have no clue, I will investigate what's wrong with nyc. |
As I recall, in linux, ports below some number (1024?) are "privileged", and need some special permissions to run. Try bumping your tests to use something higher. |
Port here doesn't matter — for child we use random free port. |
Then what does |
The build runs fine locally on OSX. It's either Linux or Travis specific. Travis could be blocking this somehow. |
I use OS X and it is failed with nyc.
Args of the main process. In the tests we don't start main process, we start child only (if I am not wrong). Purpose of this fix is — replace port in the main process args to another free port. Ok, I will investigate what's wrong with nyc. |
AppVeyor build succeeded only because |
Ahhh. Yes. This is almost certainly a spawnwrap bug then. |
Sorry for delay, I will investigate it soon. Currently I am working to support new v8 inspector in the IntelliJ IDEA. |
@develar - The NYC bug is fixed. Any chance of finalizing this soon? |
Rebased — tests passed. |
test('pass ' + execArgv.join(' ') + ' to fork', function (t) { | ||
t.plan(expectedInspectIndex === -1 ? 3 : 2); | ||
|
||
var api = new Api({testOnlyExecArgv: execArgv}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should stub process.execArgv
rather than needing a test-only option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should stub
Not quite understand, do you mean that we should replace process.execArgv
during test? I think, it is not acceptable to touch global state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you mean that we should replace process.execArgv during test?
Yes.
I think, it is not acceptable to touch global state.
True, but tests are special.
Something I've done in other projects is to have a process
module which exports the global process
, and then stubbing that through Proxyquire. But let's not do that unless we really have to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, but tests are special.
I think, some day AVA tests will be also executed in parallel, so, it is not wise to сhange properties in the global process
object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, some day AVA tests will be also executed in parallel, so, it is not wise to сhange properties in the global process object.
We can deal with it then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even when we do self test with AVA, the parallel processes will have their own process.execArgv
. Test isolation FTW!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the parallel processes will have their own process.execArgv
But not tests in the same file ;)
Ok, up to you, I removed option and replace process.execArgv
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But not tests in the same file ;)
True. Though you can always just do test.serial
for the few that would interfere.
This looks pretty good @develar! I wonder if there's anybody who'd like to install this PR locally to debug their tests? |
Hmm. I kinda think we're going about this the wrong way. Instead of parsing
If a user is debugging their tests, they aren't going to care about attaching a debugger to the parent process. Using the debug flag would imply Then the debug client can connect to a single port, no parsing IMO, If you really want to do it this way (find random open ports and print to stderr for parsing). Then that should be implemented as a separate tool using |
@jamestalmage Why? User just run debug in the IDE. Or run debug using standard node args. That's all. Nothing more. No need to reinvent the wheel and introduce new tool-specific API. User just use standard tools and way to debug. JetBrains IDE — we reimplement multiprocess debug specially for AVA. It just works. No multiple debug tabs anymore, it is like chrome workers (you can select "thread" using combo box if need). You just hit "debug" and it works (in context runner for AVA not yet implemented, but it is another task). Chrome using But, at first, I think, we should support debug using standard tools and way. |
Is that available for us to take a look at? It sounds kinda awesome. Having multiple processes running at a time sounds cool, but I'm not sure how useful it is. Maybe you could debug two test-files that interleave disk operations in some way with clever breakpoints? IDK. Either way, I don't think we want them to use
The second is more convenient. See #929 - It works really well with |
Yes, these changes available since 2016.1 release. You can try 2016.2 EAP — IDEA or WebStorm. Video: https://youtu.be/C75UwuZXI98
I use
IDE uses this break to set breakpoints, find sourcemaps and then continues debug automatically. |
#929 is about how to simplify AVA debug in the CLI using special ava specific CLI. This PR is to make AVA debug working using standard way (i.e. IDE vendor should not explicitly support AVA). Strictly speaking, this PR is a workaround of nodejs/node#5025 |
You can use conditional breakpoints. |
Landed. Finally :) Thanks for doing the hard work here @develar and persevering through this long review. |
@korsmakolnikov Please specify IDE version, do you use ava from sources? |
@develar It does not work for me. I am using this version of webstorm:
And Ava from master, but my debugger just never stops. I was trying with single file debugging (without match): Not sure why the debugger never stops. It also does not terminate. |
@KeKs0r Please use WebStorm 2016.3 EAP |
Is this documented anywhere, please? Does it need to be, or will it simply work with anything that debugs node, like Chrome DevTools? |
How likely is this to ever work in Chrome DevTools? |
@mightyiam It's planned with #929, but that PR stalled. Workaround for now. Put a
Where |
@mightyiam In addition to
Docs from Jest is true and correct for AVA as well. (Irony that currently Jest debug doesn't work due to NodeJS bug nodejs/node#7593, only AVA debug works ;)) So, you can debug in Chrome DevTools also. |
Thanks! |
Just because I couldn't find this anywhere else: when using VS Code as a debugger, you can coerce AVA to behave by using @sindresorhus 's suggestion as part of a {
"version": "0.2.0",
"configurations": [
{
"type": "node2",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceRoot}/tests/index.test.js",
"cwd": "${workspaceRoot}",
"sourceMaps": true,
"runtimeArgs": [
"${workspaceRoot}/node_modules/ava/profile.js"
]
}
]
} |
Worth mentioning that this setup worked for me but the one bit I had missing was that I forgot to install the webstorm debug helper in chrome https://chrome.google.com/webstore/detail/jetbrains-ide-support/hmhgeddbohgjknpmjagkdomcpobmllji?hl=en-GB |
@develar @mightyiam did you guys managed to test AVA tests in Webstorm with the current 2017.2? I use the configuration mentioned in this document: https://github.com/avajs/ava/blob/master/docs/recipes/debugging-with-webstorm.md |
I was also having problem with debugging ava unit tests with Webstorm 2017.2. It didn't stop at the break points. Adding |
@melisoner2006 would you be interested in opening a PR to fix the recipe? |
@novemberborn I'd love to. I'll get on it now. |
@dohomi Did you ever get this working? I'm having a hard time getting the WS debugger to work. It could be related to the fact that our project is using babel. @melisoner2006 Was your project ES6 or something else? |
@Gregoyle Yes, my project was ES6. |
Continue #613
More robust and maintainable approach was found. Just compute required data before main promise for all files. So, it is simple to add new function in to the existing promise chain. Yeah, I spend a lot of time trying to fix last failed test and decided to rework solution.
This syntax is not supported because node supports only
--debug=
, but not--debug <port number>
.Tests added. Initially as heavy-weight tests, but I got weird error
Test files must be run with the AVA CLI
if I run withnyc
(passed withoutnyc
). So, I decided to write unit tests.