A Neovim plugin to easily run and debug Jest tests.
Requirements: Neovim, nvim-treesitter, for debugging nvim-dap.
Make sure that the JavaScript/TypeScript parser for nvim-treesitter is installed and enabled.
For vim-plug:
Plug 'David-Kunz/jester'
For packer:
use 'David-Kunz/jester'
:lua require"jester".run()
:lua require"jester".run_file()
:lua require"jester".run_last()
:lua require"jester".debug()
:lua require"jester".debug_file()
:lua require"jester".debug_last()
You can specify global options using the setup
function.
Example:
require("jester").setup({
dap = {
console = "externalTerminal"
}
})
These are the defaults:
{
cmd = "jest -t '$result' -- $file", -- run command
identifiers = {"test", "it"}, -- used to identify tests
prepend = {"describe"}, -- prepend describe blocks
expressions = {"call_expression"}, -- tree-sitter object used to scan for tests/describe blocks
path_to_jest_run = 'jest', -- used to run tests
path_to_jest_debug = './node_modules/.bin/jest', -- used for debugging
terminal_cmd = ":vsplit | terminal", -- used to spawn a terminal for running tests, for debugging refer to nvim-dap's config
dap = { -- debug adapter configuration
type = 'node2',
request = 'launch',
cwd = vim.fn.getcwd(),
runtimeArgs = {'--inspect-brk', '$path_to_jest', '--no-coverage', '-t', '$result', '--', '$file'},
args = { '--no-cache' },
sourceMaps = false,
protocol = 'inspector',
skipFiles = {'<node_internals>/**/*.js'},
console = 'integratedTerminal',
port = 9229,
disableOptimisticBPs = true
}
}
You can also overwrite the options for each function call, for example
:lua require"jester".debug({ dap = { console = "externalTerminal" } })
Jest usually transforms the files causing breakpoints to be inserted in the wrong line.
To prevent this, add this .babelrc
file to your project's root:
{
"retainLines": true,
"sourceMap": "inline"
}