David-Kunz / jester

A Neovim plugin to easily run and debug Jest tests
The Unlicense
202 stars 12 forks source link

Debugger starts always the first debugged test #27

Open MijikHna opened 1 year ago

MijikHna commented 1 year ago

As nvim-dap repo suggests to use vscode-dap I have switched to vscode-dap. Also I have adjusted jester setup a accordingly. Here is my jester setup.

require'jester'.setup{
  cmd = "NODE_OPTIONS=--experimental-vm-modules node ./node_modules/jest/bin/jest.js -t \"$result\" $file", -- run command
  terminal_cmd = ":ToggleTerm",
  dap = {
    type = 'pwa-node',
    request = 'launch',
    name = 'Jest Debug',
    cwd = "${workspaceFolder}",
    rootPath = "${workspaceFolder}",
    runtimeExecutable = "node",
    runtimeArgs = {
      "./node_modules/jest/bin/jest.js",
      "--runInBand",
      "-t",
      "$result",
      "$file",
    },
    -- args = { "--runTestsByPath", "${relativeFile}" },
    args = { "--no-cache" },
    env = { NODE_OPTIONS = '--experimental-vm-modules' },
    sourceMaps = true,
    skipFiles = { "<node_internals>/**" },
    port=9229,
    console = 'integratedTerminal',
    disableOptimisticBPs = true
  },
}

also I have following mappings

nnoremap <silent> <leader>jr :lua require"jester".run()<CR>
nnoremap <silent> <leader>jd :lua require"jester".debug()<CR>

jester.run() works like expected by jester.debug() executes always the first debugged test. I always need to restart nvim to be able to debug second test.

David-Kunz commented 1 year ago

Hi @MijikHna ,

Could you try to log the output of config in

dap.run(config)

in

lua/jester/init.lua:184

?

MijikHna commented 1 year ago

I have added dap.run(config) after line 184 now init.lua looks like this

...
    if string.match(value, "$file") then
      runtimeArgs[key] = runtimeArgs[key]:gsub("$file", file)
      local config = vim.tbl_deep_extend('force', o.dap, { type = type, request = request, cwd = cwd, runtimeArgs = runtimeArgs })
      dap.run(config)
    end
...

On starting debugger I get following error

E5108: Error executing lua /home/kirill/.config/nvim/plugged/nvim-dap/lua/dap.lua:470: attempt to index field 'config' (a nil value)
stack traceback:
        /home/kirill/.config/nvim/plugged/nvim-dap/lua/dap.lua:470: in function 'run'
        ...e/kirill/.config/nvim/plugged/jester/lua/jester/init.lua:193: in function 'cb'
        ...e/kirill/.config/nvim/plugged/jester/lua/jester/init.lua:288: in function 'cb'
        /home/kirill/.config/nvim/plugged/nvim-dap/lua/dap.lua:651: in function 'terminate'
        /home/kirill/.config/nvim/plugged/nvim-dap/lua/dap.lua:694: in function 'terminate'
        ...e/kirill/.config/nvim/plugged/jester/lua/jester/init.lua:287: in function 'terminate'
        ...e/kirill/.config/nvim/plugged/jester/lua/jester/init.lua:303: in function 'debug'
        [string ":lua"]:1: in main chunk

but the debugger starts and still always runs first executed test.