mxsdev / nvim-dap-vscode-js

nvim-dap adapter for vscode-js-debug
287 stars 30 forks source link

AVA Support #24

Closed JbIPS closed 1 year ago

JbIPS commented 1 year ago

Hi, I'm trying to run AVA test with DAP.

I tried the example configuration in the documentation. It works well with VSCode but in NVim it starts the program but do not stop on breakpoints.

I also tried a generic config with npm test:

{
    type = "pwa-node",
    request = "launch",
    name = "Run NPM test",
    cwd = "${workspaceFolder}",
    runtimeExecutable = "npm",
    runtimeArgs = {
      "test"
    },
    trace = true,
    outputCapture = "std",
    console = "integratedTerminal",
    outFiles = {
      "${workspaceFolder}/dist/*.js",
      "!**/node_modules/**"
    }
  }

but I got the same results.

I tried to add a --inspect in the runtimeArgs but I get an error because the inspector is already started. Again, this config works well with VSCode.

Can you point me to a difference between VSCode and DAP that can leads to this?

Thank you

anasrar commented 1 year ago

Work break point and jump break point.

    {
      type = "pwa-node",
      request = "launch",
      name = "Launch Test Current File (pwa-node with ava)",
      cwd = vim.fn.getcwd(),
      program = "${workspaceFolder}/node_modules/ava/entrypoints/cli.mjs",
      args = { "--inspect-brk", "${file}" },
      autoAttachChildProcesses = true,
      smartStep = true,
      console = "integratedTerminal",
      skipFiles = { "<node_internals>/**", "node_modules/**" },
    },

image

JbIPS commented 1 year ago

I've got the same result with this configuration.

I'm sorry I just realized I missed a major point: I'm using TypeScript. The tests are precompiled and a remapping is done with AVA TypeScript.

Maybe there's something with the source maps?

EDIT: I can stop at breakpoints with npx ava debug test.ts and attach the debugger to this process, everything's fine, even sourcemaps.

mxsdev commented 1 year ago

Hi!

I'm not super familiar with AVA unfortunately. To confirm, is npx ava debug test.ts a total solution?

Regardless, if it works in VSCode but not in this plugin, I'm hoping that #15 will resolve any inconsistencies, since technically this plugin uses a different (probably lesser-maintained) endpoint to the debugger than VSCode. That issue is currently blocked on Microsoft/nvim-dap, I believe.

JbIPS commented 1 year ago

I hope this will be resolved with #15 :crossed_fingers:

To be clear, the debugger can attach itself to a npx ava debug test.ts process with the default Attach configuration. I'm not skilled enough to understand what goes under the hood in a Attach vs Launch, so I'll wait for startDebuging and continue with my workaround until then.

Thank you for your help and this plugin 🙂

JbIPS commented 1 year ago

Great news today, after a lot of updates and tweaks I finally made it work!

Here's my config for future reference:

  {
    type = "pwa-node",
    request = "launch",
    name = "Debug AVA Test file",
    program = "node_modules/ava/entrypoints/cli.mjs",
    args = {
      '--serial',
      '${file}'
    },
    cwd = "${workspaceFolder}",
    outFiles = {"${workspaceFolder}/dist/**/*.js"},
    console = "integratedTerminal"
  },

Ava config:

export default {
  typescript: {
    rewritePaths: {
      'src/': 'dist/'
    },
    compile: false
  }
}