Closed GitMurf closed 1 week ago
Could be related to this: https://github.com/nvim-neotest/neotest-jest/issues/94
I'm also getting this. I didn't change the default command so that can't be it. I do have odd names in tests, but they're clearly being matched correctly (if I only run a single test, the status updates to running before "failing" again). Neotest logs show nothing weird. Json is being outputted correctly. Very strange.
I'm using LazyVim, so next I'm going to attempt using the plugin without Lazyvim's setup just to check.
Can anyone confirm if this is working correctly for them?
I'm using LazyVim, so next I'm going to attempt using the plugin without Lazyvim's setup just to check.
@AlansCodeLog Don't bother trying that! I failed with lazyvim at first and then tried it from scratch without lazyvim and same results 🥲
I figured out what was happening in my case. I had a dynamic name for the describe blocks and obviously the algorithm to match the names must not have been able to match it exactly. Have you tried with a file with a single simple test? That's how I realized the issue.
I figured out what was happening in my case. I had a dynamic name for the describe blocks and obviously the algorithm to match the names must not have been able to match it exactly. Have you tried with a file with a single simple test? That's how I realized the issue.
Thanks! I will give it a try. Bummer though I don't really want to rename all my tests to satisfy this plugin working. Any hunches at where this could be fixed in the code?
Curious if you have any clue if it is a neotest/vite issue? Or if it is a core neotest issue?
I have the same issue :( Any updates on it?
@GitMurf You also had dynamic names then? I doubt there is a way to make it work because it's not possible to know what the final name (that is outputted to json by the test library then fed to the plugin) will be in cases like this:
it(`how do we know what ${somevar} is`, () => {...
I have the same issue, even though I don't use dynamic names:
Yeah I agree. I tested with simple non dynamic names and still getting errors.
Are you all on windows? I wonder if it's a path / escaping issue like most windows issues are! Haha
I'm on windows 11
Yes, I'm also on Windows (10). Could very well be..
@AlansCodeLog @kirylvarykau do you also happen to be using Windows?
I'm using macos and have the same issue @GitMurf. How are you running the individual tests vs in the summary section?
For me this works:
vim.api.nvim_set_keymap('n', '<leader>twr', "<cmd>lua require('neotest').run.run({ vitestCommand = 'npx vitest run' })<cr>", { desc = 'Run Watch' })
But running from the summary section clicking "r" doesn't
this is the error in the gutter:
Vitest caught 1 unhandled error during the test run.
This might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Error ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
TypeError: Cannot read properties of undefined (reading 'enabled')
❯ setupInspect node_modules/vitest/dist/vendor/inspector.IgLX3ur5.js:8:38
❯ run node_modules/vitest/dist/worker.js:58:28
❯ packages/isomorphic-lib/node_modules/tinypool/dist/esm/entry/worker.js:71:26
I was just able to fix this issue by updating my config to this:
require('neotest').setup {
adapters = {
require 'neotest-vitest' {
vitestCommand = 'npx vitest run',
-- Filter directories when searching for test files. Useful in large projects (see Filter directories notes).
filter_dir = function(name, rel_path, root)
return name ~= 'node_modules'
end,
},
},
}
@GitMurf No, am on linux, and I have not had any issues since I changed all the dynamic names...
I've found another edge case, apparently, template strings alone (no variables) can't be used either. I was working on a parser and I did not want to escape the input strings in the tests which is why they were like this. I did a little bit of digging into the code and added my own treesitter query to quickly this. I'm not sure this should be supported out of the box since the most likely reason to use template strings is variables and I doubt those can be made to work, but @marilari88 are you open to allowing adding an option for custom treesitter queries? I can do a PR.
@AlansCodeLog sure you can! It is an edge case but why not support it? Thanks
I've found another edge case, apparently, template strings alone (no variables) can't be used either. I was working on a parser and I did not want to escape the input strings in the tests which is why they were like this. I did a little bit of digging into the code and added my own treesitter query to quickly this. I'm not sure this should be supported out of the box since the most likely reason to use template strings is variables and I doubt those can be made to work, but @marilari88 are you open to allowing adding an option for custom treesitter queries? I can do a PR.
This finally makes sense! I use template strings everywhere even without variables. So this must be my issue! Thanks so much for all your digging @AlansCodeLog !
No problem, here's my fork with the option to add additional treesitter queries. Then you can do the following for now to get template string support:
{
"alanscodelog/neotest-vitest",
opts = {
additional_treesitter_queries = [[
((call_expression
function: (identifier) @func_name (#any-of? @func_name "it" "test")
arguments: (arguments (template_string (string_fragment) @test.name) (arrow_function))
)) @test.definition
]],
},
},
Hi @marilari88 , I didn't use any template strings and still have this problem.
I thought maybe we should reopen the issue?
@Daydreamer-riri are you on Windows?
@Daydreamer-riri are you on Windows?
Yes.
I just installed and setup for the first time and got things seemingly working except they always show as failed even when the tests are successful. See screenshot. Any thoughts? Thanks!