The setup involves creating a plugin configuration file that leverages the neotest-jest adapter. Save the following to .config/nvim/lua/plugins/neotest-jest.lua:
return {
{
"haydenmeade/neotest-jest",
},
{
"nvim-neotest/neotest",
dependencies = { "haydenmeade/neotest-jest" },
opts = function(_, opts)
table.insert(
opts.adapters,
require("neotest-jest")({
jestCommand = "npm test --",
jestConfigFile = "jest.config.js",
cwd = function()
return vim.fn.getcwd()
end,
})
)
end,
},
}
Key Components
- Plugin Dependencies: The configuration specifies neotest-jest as a dependency for the main neotest plugin
- Jest Command: Configured to use
"npm test --"as the execution command - Config File Reference: Points to
jest.config.jsfor test configuration - Working Directory: Dynamically retrieves the current vim working directory