neotest-jest
neotest-jest copied to clipboard
Jest Test name from class name breaks "Run Nearest" and "Debug" functionalities
Hi, I have tried the default config from lazyvim distribution. Normally, neotest and jest works fine I can use any functionality. However, whenever I try to change the name from a string literal to "class.name", run nearest skips all tests and debug gives some ENOENT errors from some other packages.Also, I am doing typescript for a couple of months, I used to be a Java dev. So, if this behaviour is kind of related to the language, sorry in advance.
I have the following test (sorry can't share completely since it's an commercial project):
describe(SomeService.name, () => {//if I use 'SomeService' it works but not like the way I use
//variables etc
beforeEach(async () => {
//setup before each
});
afterEach(() => {
//do something after each test
});
describe('.beforeEach()', () => {
it('should be defined', () => {
//check if service is defined
});
});
describe('.getAll()', () => {
it('should return an array of result', async () => {
//checks getAll functionality of our service
});
it('should throw an error on failure', async () => {
//checks error handling of our system
});
});
});
My lazyvim neotest setup (I also enabled test.core and dap.core in lazy.lua file):
return {
"nvim-neotest/neotest",
dependencies = { "nvim-neotest/nvim-nio", "nvim-neotest/neotest-jest" },
opts = {
-- Can be a list of adapters like what neotest expects,
-- or a list of adapter names,
-- or a table of adapter names, mapped to adapter configs.
-- The adapter will then be automatically loaded with the config.
adapters = {
["neotest-jest"] = {
jestCommand = "npm test -- --detectOpenHandles",
env = { CI = true },
JestConfigFile = "jest.config.ts",
},
},
-- Example for loading neotest-golang with a custom config
-- adapters = {
-- ["neotest-golang"] = {
-- go_test_args = { "-v", "-race", "-count=1", "-timeout=60s" },
-- dap_go_enabled = true,
-- },
-- },
},
-- stylua: ignore
keys = {
{"<leader>t", "", desc = "+test"},
{ "<leader>tt", function() require("neotest").run.run(vim.fn.expand("%")) end, desc = "Run File" },
{ "<leader>tT", function() require("neotest").run.run(vim.uv.cwd()) end, desc = "Run All Test Files" },
{ "<leader>tr", function() require("neotest").run.run() end, desc = "Run Nearest" },
{ "<leader>tl", function() require("neotest").run.run_last() end, desc = "Run Last" },
{ "<leader>ts", function() require("neotest").summary.toggle() end, desc = "Toggle Summary" },
{ "<leader>to", function() require("neotest").output.open({ enter = true, auto_close = true }) end, desc = "Show Output" },
{ "<leader>tO", function() require("neotest").output_panel.toggle() end, desc = "Toggle Output Panel" },
{ "<leader>tS", function() require("neotest").run.stop() end, desc = "Stop" },
{ "<leader>tw", function() require("neotest").watch.toggle(vim.fn.expand("%")) end, desc = "Toggle Watch" },
},
}