Closed cdaringe closed 3 years ago
Do you need to create the launch configuration? The built-in debug terminal works pretty well for me, and so I haven't used launch configurations in a while…
I wonder if the debug
command is missing from runtimeArgs
. It was removed in https://github.com/avajs/ava/pull/2547. Could you try putting it back in?
Howdy! Same issue.
I have to use launch configuration because I'm using TS so the code has to be first transpiled and then run via the preLaunchTask
param. I have two configurations: 1) "Transpile & Run" and 2) "Run"
{
"version": "0.3.0",
"configurations": [
{
"name": "Transpile & Run",
"preLaunchTask": "transpile",
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/ava",
"runtimeArgs": [
"debug",
"--break",
"--verbose",
"--color",
"--serial",
"--watch=false",
"build/ts-to-es6/test/**/${fileBasenameNoExtension}.js",
],
"request": "launch",
"skipFiles": [
"<node_internals>/**"
],
"type": "node",
"outputCapture": "std",
"port": 9229,
"sourceMaps": true,
"trace": true,
"protocol": "auto",
"console": "integratedTerminal"
},
{
"name": "Run",
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/ava",
"runtimeArgs": [
"debug",
"--break",
"--verbose",
"--color",
"--watch=false",
"--fail-fast=false",
"build/ts-to-es6/test/**/${fileBasenameNoExtension}.js",
],
"request": "launch",
"skipFiles": [
"<node_internals>/**"
],
"type": "node",
"outputCapture": "std",
"port": 9229,
"sourceMaps": true,
"trace": true,
"protocol": "auto",
"console": "integratedTerminal"
},
]
}
For me, everything was working up to VSCode version 1.46.1 and then there was some regression on higher versions. Then I updated my project's Typescript version and it seems that there is a different regression because the VSCode version stayed the same. This issue is related to the latter.
You can reproduce this in the OneSignal WebSDK
Debug breakpoints completely ignored
Update: I tried putting a debugger;
statement to halt execution. This works but opens the transpiled version (JS). Then, if I add breakpoints they work but I have to add them in the transpiled version of the file
@rgomezp have you tried the built-in debug terminal? I run a TypeScript compiler in a separate process, but for be this works great for debugging tests.
@novemberborn ,
Hi Mark.
I'm sorry but I'm not sure what you mean exactly. I have "console": "integratedTerminal"
set in my launch config. Perhaps a gif or video could help clarify?
From the Command Palette (F1 or command + shift + p / control + shift + p), run Debug: Create JavaScript Debug Terminal
@novemberborn , I tried it. Unfortunately not, I see this:
➜ OneSignal-Website-SDK git:(master) npx ava
Debugger listening on ws://127.0.0.1:55969/c73ff059-1228-4a02-89ea-3fc705bf07ce
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
⠙ Debugger listening on ws://127.0.0.1:55983/68406bfa-8140-4449-89e2-0672b8684c1d
For help, see: https://nodejs.org/en/docs/inspector
⠸ Debugger attached.
⠹ Waiting for the debugger to disconnect...
⠴ Debugger listening on ws://127.0.0.1:55991/73b07842-0231-4620-a5b3-1aecb57c7229
⠦ For help, see: https://nodejs.org/en/docs/inspector
⠇ Debugger attached.
⠇ Waiting for the debugger to disconnect...
⠋ Debugger listening on ws://127.0.0.1:55995/05bb11c6-1ef1-4fd0-aab1-e42b22c2a32f
For help, see: https://nodejs.org/en/docs/inspector
⠸ Debugger attached.
⠹ Waiting for the debugger to disconnect...
⠼ Debugger listening on ws://127.0.0.1:55995/05bb11c6-1ef1-4fd0-aab1-e42b22c2a32f
For help, see: https://nodejs.org/en/docs/inspector
⠦ Debugger listening on ws://127.0.0.1:56003/7fb34994-2435-4cb6-8be9-6bac966066b8
For help, see: https://nodejs.org/en/docs/inspector
⠇ Debugger attached.
⠋ Waiting for the debugger to disconnect...
⠹ Debugger listening on ws://127.0.0.1:56011/850140cb-ffee-44ef-90dc-441765b78125
For help, see: https://nodejs.org/en/docs/inspector
⠼ Debugger attached.
✖ No tests found in build/ts-to-es6/test/unit/helpers/ConfigHelper.js
✖ No tests found in build/ts-to-es6/test/unit/helpers/InitHelper.js
✖ No tests found in build/ts-to-es6/test/unit/helpers/MainHelper.js
✖ No tests found in build/ts-to-es6/test/unit/helpers/ServiceWorkerHelper.js
I think that may have more to do with your project setup.
I did clone your project, ran npx tsc --project build/config/tsconfig.tests.json
and then from VSCode ran npx ava
and that ran the tests fine.
There's a lot of moving pieces in your project and I reckon that's where the trouble lies.
Not to say the recipe is perfect, of course, I suspect the debug
command is still missing? https://github.com/avajs/ava/issues/2640#issuecomment-758532588
@novemberborn thanks for your response.
You can see the debug
command in my configuration in this comment.
So I am using that.
I ran the npx tsc --project build/config/tsconfig.tests.json && npx ava
command and it ran the tests fine.
That's not the original issue however. The problem is the breakpoints aren't triggered.
The recipe works as-is with a plain JavaScript project.
Adding TypeScript, and build steps, makes everything more complicated. I don't know if that's solvable within our recipes.
FWIW I use the debug terminal along with @ava/typescript
(which requires you to pre-compile the code). This works great. I'd love for you to try this so we can make more explicit that this works.
greetings all :) the recipe as written actually doesn't work with plain javascript.
to prove it, i've done the following:
test.js
filereference to repro repository. Observe it all in this nice GIF! I debugged on the incorrect file at first--ignore that part 😉 !
As you can see, the debugger
statement is not hit, using plain javascript, using the official recipe. I also decided to edit the Ava source code that launches the subprocess to debug the matter further. You can see the above output that the worker is launched with "execArgv": []
. Because of this, I don't expect the worker to be in debug mode (unless the subprocess kicks itself into debug mode dynamically, which is certainly possible via SIGUSR1).
FWIW, using the debug terminal works fine, as recommended here. ts-node
is certainly compatible with all of this, as suggested in the typescript docs section. Precompiled assets also are not required using the debug terminal.
It's unclear to me what the design intent is supposed to be for the launch-configuration experience (which is my preferred experience). As shown above, the recipe does not kick the worker process into debug mode. Even if it did kick the child into debug mode, it's also unclear to me how one would get VSCode to listen to that child. In the prior state of ava, there was only one PID to hook into. Perhaps something like runInBand is in order to return the easy debug flow to the prior state?
@cdaringe could you confirm your AVA, Node and VS Code versions? I wrote the exact same fixture file yesterday which worked.
Certainly! Node 15.0.1, VSCode: 1.52.1, ava@3.15.0
envinfo
posted below
I didn't notice this before, but you run the debug command from the launch.json
file. What the launch configuration does however is pass the currently active file to AVA, which, if it's a matching test file, will run it.
All this works for me, Node.js 15.8, VSCode 1.53, no AVA configuration.
I'm going to close this, since I don't think there's actually an issue here. Of course if the recipe needs updating I'll happily take a PR. It all works as advertised though… but that could just be my machine 😉
Bummer.
I appreciate your effort and willingness, but I don't see compelling rationale for closure. "Works on my machine (with different config)" I feel is not giving the detailed reports justice. I'm not begging for an immediate solution, but I do kindly think the issue should be closed when it's certainly done-done.
Let me know your thoughts.
As far as I can tell, the configuration, as documented, works. VS Code injects code to enable debugging, so the previous approach is no longer required.
Any combination with ts-node
introduces too many variables. I'd take a PR that documents how to make it work but I highly doubt leaving the issue open for that is going to result in one.
As you can see, the debugger statement is not hit, using plain javascript, using the official recipe.
I don't think my system is uncommon, as shown my envinfo. I even uploaded a reproduction repository for plainjs (ignore -ts in the repro repo url). I admit, I could be missing something. But, as mentioned above, I don't see ts-node as the issue.
Viscose injects
Are you assuming users are using autoattach? Otherwise I don't expect vs code to do this. I only expect it to add args to the root launch cli args to node
I even uploaded a reproduction repository for plainjs
git clone https://github.com/cdaringe/ava-ts-patcherooni
cd ava-ts-patcherooni
npm i
code .
Open test.js
. Run Debug AVA test file
.
This was Node.js 14.15.4 and VS Code 1.53.0.
I don't know why it's not working for you. I'm sorry I can't help further.
I tried on linux today (as opposed to my day-to-day macos laptop), and used the same node & vscode version as above. still doesn't take. ~however, despite that it works for you, i do not expect it to work for you. i'm not sure what about your system makes this work--perhaps an env config, perhaps a vscode extension, ...im not sure.~
~ava runs the test in a child process. nothing is kicking that child process into debug mode. i don't expect a debugger to hit, because the test runner isn't flipping on the node debugger in the child worker.~
~in your screen shot, you can see the parent/child relationship, and that you have broken in the child.~
...
annnnnnd a few interesting tid bits of research have shown up:
"autoAttachChildProcesses": true
. this gets the desired workflow to take, even if not included in the recipe (perhaps because it shouldn't be?)i need to learn more about what conditions would lead to requiring autoAttachChildProcesses
or what conditions would cause VSCode js-debug to not issue its default behavior from the docs
By using "type": "pwa-node"
and dropping autoAttachChildProcesses
, it also works. Do you have "debug.javascript.usePreview": true
set by chance?
Do you have
"debug.javascript.usePreview": true
set by chance?
I do! Not that I recall setting it.
Auto attaching to child processes sounds like it would be necessary. Would be good to know what is stock VS Code and what settings may be inherited from older installations. Or we can just say "use pwa-node
", whatever that is.
Howdy, I'm in the same boat. Can you please reopen the issue?
If we can get to the bottom of it. Does changing the type help?
I'm having the same issue wherein the stock recipe just seems to ignore vscode breakpoints. I'm using AVA v3.15 and vscode 1.65.2... Seems to only happen with WSL2, though. I can confirm the recipe is fine on Windows 11, and MacOS.
Howdy, I'm in the same boat. Can you please reopen the issue?
I think I've figured out the issue. The source map resolution isn't working because VSCode doesn't know what the actual program name is. Try using the following configuration:
{
"name": "Debug AVA",
"type": "node",
"request": "launch",
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/ava",
"program": "${file}",
"outputCapture": "std"
}
the big issue was that we were passing ${file}
to ava
via runtimeArgs
and not through program
...
Please provide details about:
debug tests, in typescript, ts-node only
Test executed successfully, but both breakpoints &
debugger
statements ignoreddebugger
statements to halt executionInterestingly, I can get into a breakpoint if I execute a alternate debugging workflow:
npx ava debug test/class.test.ts
Attach
a debuggerWorks fine :)
Previously,
ava
entered a debug session via more idiomatic node debug conventions--node --inspect <path/to/ava/profile.js> <test name>
. It seems like now ava is doing some fancy footwork, where it wants to start the node debugger, where VSCode also wants to start the debugger, and consequently these two things may be trampling each other a bit.I don't have a minimal repro, but it's a pretty straightforward repro:
git clone https://github.com/cdaringe/factorio-ts
git checkout 7cbc8e9
yarn
Shared above, but here's also
envinfo
output: