Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] No test found #348

Open
codycjy opened this issue Jan 13, 2024 · 14 comments
Open

[BUG] No test found #348

codycjy opened this issue Jan 13, 2024 · 14 comments
Assignees

Comments

@codycjy
Copy link

codycjy commented Jan 13, 2024

NeoVim Version
Output of nvim --version
NVIM v0.8.2
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by runner@fv-az190-151

Features: +acl +iconv +tui
See ":help feature-compile"

system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "/share/nvim"

Run :checkhealth for more info

Describe the bug
When try to show test us :NeotestSummary error occurs and no test function showed.

To Reproduce
Please provide a minimal init.lua to reproduce which can be run as the following:

nvim --clean -u minimal.lua

You can edit the following example file to include your adapters and other required setup.

-- ignore default config and plugins
vim.opt.runtimepath:remove(vim.fn.expand("~/.config/nvim"))
vim.opt.packpath:remove(vim.fn.expand("~/.local/share/nvim/site"))
vim.opt.termguicolors = true

-- append test directory
local test_dir = "/tmp/nvim-config"
vim.opt.runtimepath:append(vim.fn.expand(test_dir))
vim.opt.packpath:append(vim.fn.expand(test_dir))

-- install packer
local install_path = test_dir .. "/pack/packer/start/packer.nvim"
local install_plugins = false

if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
  vim.cmd("!git clone https://github.com/wbthomason/packer.nvim " .. install_path)
  vim.cmd("packadd packer.nvim")
  install_plugins = true
end
local packer = require("packer")

packer.init({
  package_root = test_dir .. "/pack",
  compile_path = test_dir .. "/plugin/packer_compiled.lua",
})

packer.startup(function(use)
  use("wbthomason/packer.nvim")
  use({
    "nvim-neotest/neotest",
    requires = {
    "nvim-lua/plenary.nvim",
    "nvim-treesitter/nvim-treesitter",
    "antoinemadec/FixCursorHold.nvim",
    "nvim-neotest/neotest-go",
    -- Your other test adapters here
    },
    config = function()
      -- get neotest namespace (api call creates or returns namespace)
      local neotest_ns = vim.api.nvim_create_namespace("neotest")
      vim.diagnostic.config({
        virtual_text = {
          format = function(diagnostic)
            local message =
              diagnostic.message:gsub("\n", " "):gsub("\t", " "):gsub("%s+", " "):gsub("^%s+", "")
            return message
          end,
        },
      }, neotest_ns)
      require("neotest").setup({
        -- your neotest config here
	log_level = vim.log.levels.DEBUG,
        adapters = {
          require("neotest-go"),
        },
      })
    end,
  })
  if install_plugins then
    packer.sync()
  end
end)

vim.cmd([[
command! NeotestSummary lua require("neotest").summary.toggle()
command! NeotestFile lua require("neotest").run.run(vim.fn.expand("%"))
command! Neotest lua require("neotest").run.run(vim.fn.getcwd())
command! NeotestNearest lua require("neotest").run.run()
command! NeotestDebug lua require("neotest").run.run({ strategy = "dap" })
command! NeotestAttach lua require("neotest").run.attach()
command! NeotestOutput lua require("neotest").output.open()
]])

Steps to reproduce the behavior:

  1. Open neovim
  2. :NeotestSummary

Please provide example test files to reproduce.

Expected behavior
Show all test function correctly

Logs

  1. Wipe the neotest.log file in stdpath("log") or stdpath("data").
  2. Set log_level = vim.log.levels.DEBUG in your neotest setup config.
  3. Reproduce the issue.
  4. Provide the new logs.
ERROR | 2024-01-13T22:35:22Z+0800 | ...pack/packer/start/neotest/lua/neotest/lib/subprocess.lua:57 | Child process is waiting for input at startup. Aborting.
ERROR | 2024-01-13T22:35:22Z+0800 | ...ig/pack/packer/start/neotest/lua/neotest/client/init.lua:311 | Couldn't find positions in path /home/saltfish/Coding/Project/GalaxyEmpireWeb/master/services/userservice/user-service_test.go ...packer/start/neotest/lua/neotest/lib/treesitter/init.lua:117: attempt to call field 'get_lang' (a nil value)
stack traceback:
	...packer/start/neotest/lua/neotest/lib/treesitter/init.lua:117: in function 'get_parse_root'
	...packer/start/neotest/lua/neotest/lib/treesitter/init.lua:160: in function 'parse_positions_from_string'
	...packer/start/neotest/lua/neotest/lib/treesitter/init.lua:207: in function 'discover_positions'
	...ig/pack/packer/start/neotest/lua/neotest/client/init.lua:302: in function <...ig/pack/packer/start/neotest/lua/neotest/client/init.lua:266>
	[C]: in function 'xpcall'
	...ig/pack/packer/start/neotest/lua/neotest/client/init.lua:266: in function '_update_positions'
	...ig/pack/packer/start/neotest/lua/neotest/client/init.lua:319: in function <...ig/pack/packer/start/neotest/lua/neotest/client/init.lua:317>
ERROR | 2024-01-13T22:35:22Z+0800 | ...ig/pack/packer/start/neotest/lua/neotest/client/init.lua:311 | Couldn't find positions in path /home/saltfish/Coding/Project/GalaxyEmpireWeb/master/services/accountservice/account-service_test.go ...packer/start/neotest/lua/neotest/lib/treesitter/init.lua:117: attempt to call field 'get_lang' (a nil value)
stack traceback:
	...packer/start/neotest/lua/neotest/lib/treesitter/init.lua:117: in function 'get_parse_root'
	...packer/start/neotest/lua/neotest/lib/treesitter/init.lua:160: in function 'parse_positions_from_string'
	...packer/start/neotest/lua/neotest/lib/treesitter/init.lua:207: in function 'discover_positions'
	...ig/pack/packer/start/neotest/lua/neotest/client/init.lua:302: in function <...ig/pack/packer/start/neotest/lua/neotest/client/init.lua:266>
	[C]: in function 'xpcall'
	...ig/pack/packer/start/neotest/lua/neotest/client/init.lua:266: in function '_update_positions'
	...ig/pack/packer/start/neotest/lua/neotest/client/init.lua:319: in function <...ig/pack/packer/start/neotest/lua/neotest/client/init.lua:317>
ERROR | 2024-01-13T22:35:22Z+0800 | ...ig/pack/packer/start/neotest/lua/neotest/client/init.lua:311 | Couldn't find positions in path /home/saltfish/Coding/Project/GalaxyEmpireWeb/master/models/model_test.go ...packer/start/neotest/lua/neotest/lib/treesitter/init.lua:117: attempt to call field 'get_lang' (a nil value)
stack traceback:
	...packer/start/neotest/lua/neotest/lib/treesitter/init.lua:117: in function 'get_parse_root'
	...packer/start/neotest/lua/neotest/lib/treesitter/init.lua:160: in function 'parse_positions_from_string'
	...packer/start/neotest/lua/neotest/lib/treesitter/init.lua:207: in function 'discover_positions'
	...ig/pack/packer/start/neotest/lua/neotest/client/init.lua:302: in function <...ig/pack/packer/start/neotest/lua/neotest/client/init.lua:266>
	[C]: in function 'xpcall'
	...ig/pack/packer/start/neotest/lua/neotest/client/init.lua:266: in function '_update_positions'
	...ig/pack/packer/start/neotest/lua/neotest/client/init.lua:319: in function <...ig/pack/packer/start/neotest/lua/neotest/client/init.lua:317>

Additional context
The code doesn't work on wsl but works fine in my arch linux.

@PierrickF
Copy link

I had a similar issue where I had a supposedly good configuration, and a "no tests found" error.

My mistake was to not have ran :TSInstall <language_to_install> after having installed nvim-treesitter.

@marcoskichel
Copy link

marcoskichel commented Feb 2, 2024

I am having a hard time running Jest tests in a Typescript/Node.js project since two days ago, it was working perfectly until then. Neotest can identify the test files correctly as they show up in the summary view, but when trying to run them it always give me a "No tests found" message. I also have Treesitter installed for Typescript.

My coworker is having the same problem and we do not exchange configurations, we both use slightly modified versions of LazyVim.

I had not much time to dig into this, but I did some debugging and it looks like an issue when the Jest adapter tries to get the nearest test node to run. I am not sure exactly where the problem is so I am just posting this message here for visibility, in case someone else also have this issue.

@lxgreen
Copy link

lxgreen commented Feb 5, 2024

@marcoskichel i have the same issue, started a couple of days ago. tests are detected correctly in :Neotest summary, but they fail to run.

Neotest log contains warning

WARN | 2024-02-05T16:49:24Z+0200 | ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:161 | CHILD | Error in remote call ...im/0.9.5/share/nvim/runtime/lua/vim/treesitter/query.lua:259: query: invalid node type at position 494 for language typescript
stack traceback:
	[C]: in function '_ts_parse_query'
	...im/0.9.5/share/nvim/runtime/lua/vim/treesitter/query.lua:259: in function 'parse_query'
	...re/nvim/lazy/neotest/lua/neotest/lib/treesitter/init.lua:104: in function 'normalise_query'
	...re/nvim/lazy/neotest/lua/neotest/lib/treesitter/init.lua:161: in function 'parse_positions_from_string'
	...re/nvim/lazy/neotest/lua/neotest/lib/treesitter/init.lua:207: in function 'func'
	...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:153: in function <...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:152>
	[C]: in function 'xpcall'
	...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:152: in function <...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:151>

looks like Typescript treesitter has parsing issues

@lxgreen
Copy link

lxgreen commented Feb 8, 2024

there's specific Typescript issue in neotest-jest, is this one still relevant?

@fnune
Copy link

fnune commented Feb 14, 2024

Here to confirm that on version v0.9.2 of nvim-treesitter:

  • neotest cannot find tests regardless of adapter (tried neotest-python, neotest-jest)
  • There's big input lag for ~5s when running lua require("neotest").run.run() (the bigger the project, the longer the lag)
    • After this, Neotest does not produce output
    • If you run lua require("neotest").run.run() again, it runs immediately but returns "No tests found"

This is all fixed by reverting to v0.9.1 of nvim-treesitter, indicating that there's a compatibility bug between that library and neotest.

@codycjy
Copy link
Author

codycjy commented Feb 14, 2024

After upgrading neovim to 0.9.5(latest stable), test cases back to normal.
Thank you @fnune

@codycjy codycjy closed this as completed Feb 14, 2024
@fnune
Copy link

fnune commented Feb 14, 2024

@codycjy I upgraded to Neovim 0.9.5 but Neotest still can't find tests if nvim-treesitter is at v0.9.2. Downgrading to v0.9.1 still works. IMO reopen, or I can open a different bug for the version incompatibility.

@codycjy codycjy reopened this Feb 14, 2024
@rcarriga
Copy link
Collaborator

@fnune Am I correct in saying that's only for typescript? Everything is working well for me with python and lua

@fnune
Copy link

fnune commented Feb 15, 2024

It's for all adapters (at least for me). There may be more things involved, but downgrading to v0.9.1 definitely helps.

@rcarriga
Copy link
Collaborator

Ah OK, could you paste the output of the logs at debug level?

@fnune
Copy link

fnune commented Feb 17, 2024

Update: you were right @rcarriga it's only TypeScript. It turns out my Python test discovery was failing because my project also contains TypeScript. When I removed the neotest-jest adapter from my project config, Python test discovery started working again.

Suggestion: cover against failures in test discovery from one adapter so that the other adapter still works? Also, the discovery failure was invisible to me as a user. The :Neotest summary window showed that the nodetest-jest adapter had found the directory structure of my project and correctly identified the test files but no tests within each test file. Maybe show an error message there?


Here are some logs from my TypeScript problem:

Neovim version: 0.9.5

$ nvim --version
NVIM v0.9.5

Neotest version: https://github.com/nvim-neotest/neotest/commits/f6048f32be831907fb15018af2688ff6633704fc

Treesitter version: https://github.com/nvim-treesitter/nvim-treesitter/commits/17d68ac13c902f55253b7facb47df4c0ae532575
(newer than 0.9.2)

Behavior when trying to run a test (2nd try; 1st try does not return any output):
image

Logs on the 1st try (TSX):

WARN | 2024-02-17T13:50:28Z+0100 | ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:164 | CHILD | Error in remote call ...ed-0.9.5/share/nvim/runtime/lua/vim/treesitter/query.lua:259: query: invalid node type at position 494 for language tsx
stack traceback:
        [C]: in function '_ts_parse_query'
        ...ed-0.9.5/share/nvim/runtime/lua/vim/treesitter/query.lua:259: in function 'parse_query'
        ...re/nvim/lazy/neotest/lua/neotest/lib/treesitter/init.lua:104: in function 'normalise_query'
        ...re/nvim/lazy/neotest/lua/neotest/lib/treesitter/init.lua:161: in function 'parse_positions_from_string'
        ...re/nvim/lazy/neotest/lua/neotest/lib/treesitter/init.lua:207: in function 'func'
        ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:156: in function <...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:155>
        [C]: in function 'xpcall'
        ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:155: in function <...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:154>

Logs on the 2nd try (TSX): no additional logs, directly posts "No tests found".

@JordanFaust
Copy link

I dug into the specific problem for neotest-jest and found it to be what looks like a breaking change in the javascript treesitter parser: nvim-neotest/neotest-jest#100. I know there were some breaking highlighting changes in treesitter lately. Not sure if there were other breaking changes introduced as well.

This problem was not impacting my other projects that did not have any typescript/javascript within them but my neotest-jest adapter was also the very last one in the list. Not sure if adapter ordering could be the cause of @fnune's problem?

@fnune
Copy link

fnune commented Feb 17, 2024

Placing neotest-python first did allow the Python test discovery to succeed & let me run tests. But (1) the TypeScript discovery still failed, and (2) my Python tests didn't run until the TypeScript discovery part failed (which took a good 15 seconds).

Repeating the workaround in case it's helpful to others: pinning nvim-treesitter to v0.9.1 fixes all these problems, but it would be nice to be able to update.

@fnune
Copy link

fnune commented Feb 19, 2024

Looks like it a bug in neotest-jest, which broke discovery for all other adaptors: updating neotest-jest has made things work for me with treesitter on v0.9.2: nvim-neotest/neotest-jest#100

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants