Skip to content

How to use vimspector with vim test

Dr. David Kunz edited this page Jan 5, 2021 · 6 revisions

You can use the plugin vim-test to start your vimspector session.

Example using Node.js with Jest

Your debug adapter:

  "configurations: {
    "jest": {
        "adapter": "vscode-node",
        "breakpoints": {
          "exception": {
            "all": "N",
            "uncaught": "N"
          }
        },
        "configuration": {
          "request": "launch",
          "name": "Debug Jest Test",
          "type": "node",
          "runtimeArgs": [
             "--inspect-brk",
            "/usr/local/bin/jest",
             "--no-coverage",
             "-t",
             "'${TestName}'",
             "--",
             "${file}"
          ],
          "console": "integratedTerminal",
          "skipFiles": ["<node_internals>/**/*.js"],
          "internalConsoleOptions": "neverOpen",
          "port": 9229
        }
      }
  }
}

Then you can add a test strategy in your vim configuration:

function! JestStrategy(cmd)
  let testName = matchlist(a:cmd, '\v -t ''(.*)''')[1]
  call vimspector#LaunchWithSettings( #{ configuration: 'jest', TestName: testName } )
endfunction

let g:test#custom_strategies = {'jest': function('JestStrategy')}

Now call :TestNearest -strategy=jest to debug your test.

Clone this wiki locally