nvim-neotest/neotest

[BUG] no tests found

Closed this issue ยท 8 comments

bwafi commented

NeoVim Version
NVIM v0.9.4
Build type: Release
LuaJIT 2.1.0-beta3

system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "
/home/linuxbrew/.linuxbrew/Cellar/neovim/0.9.4/share/nvim"

Describe the bug
before I updated the neotest plugin, it ran normally in jest test but after updating the latest neotest plugin no tests found

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.

Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Please provide example test files to reproduce.

Expected behavior
A clear and concise description of what you expected to happen.

Logs

WARN | 2023-10-22T14:14:31Z+0700 | ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:161 | CHILD | Error in remote call ...0.9.4/share/nvim/runtime/lua/vim/treesitter/language.lua:93: no parser for 'javascript' language, see :help treesitter-parsers
stack traceback:
	[C]: in function 'error'
	...0.9.4/share/nvim/runtime/lua/vim/treesitter/language.lua:93: in function 'add'
	...4/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:98: in function 'get_string_parser'
	...re/nvim/lazy/neotest/lua/neotest/lib/treesitter/init.lua:119: in function 'get_parse_root'
	...re/nvim/lazy/neotest/lua/neotest/lib/treesitter/init.lua:160: 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>

Additional context
treesitter parser not found but I have installed javascript and I have reinstalled all the plugins, but still the same no tests found

bwafi commented

apparently you have to use the nvim-treesitter dependency

  {
    "nvim-neotest/neotest",
    event = "LspAttach",
    dependencies = {
      "nvim-treesitter/nvim-treesitter", -- this adding nvim-treesitter
      "haydenmeade/neotest-jest",
      "marilari88/neotest-vitest",
      "nvim-neotest/neotest-go",
    },
    config = function()
      require "custom.configs.neotest"
    end,
    init = function(_)
      require("core.utils").load_mappings "neotest"
    end,
  },

Loading treesitter on VeryLazy can break neotest

In PR #298 the following line was removed from neotest.lib.subprocess:

nio.fn.rpcrequest(child_chan, "nvim_exec_lua", "require('nvim-treesitter')", {})

As a consequence, neotest can break for users of lazy.nvim, when loading nvim-treesitter on VeryLazy(scheduled on UIEnter).
Neotest runs tests in a new Neovim instance, expecting plugins to be ready on VimEnter.
Thus, in that instance, nvim-treesitter is loaded too late.

For LazyVim, @folke fixed the problem in v10.6.0

Note: For python, in Neovim nightly, the tests run fine, because nightly ships with parsers and queries for Markdown, Python, and Bash.
See also: This PR in LazyVim

Repro

--[[
Loads LazyVim using only the plugins needed for neotest-python(9 plugins)
Steps on linux:
1. create dir ~/.config/repro
2. add this file as ~/.config/repro/init.lua
3. run: "NVIM_APPNAME=repro nvim", and restart
4. run: "NVIM_APPNAME=repro nvim", and use neotest
--]]
local function bootstrap(lazypath)
	if not vim.loop.fs_stat(lazypath) then
    -- stylua: ignore
    vim.fn.system({
      "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git",
      "--branch=stable", lazypath
    })
	end
	vim.opt.rtp:prepend(vim.env.LAZY or lazypath)
end
bootstrap(vim.fn.stdpath("data") .. "/lazy/lazy.nvim")

local lazyvim_tag = "v10.5.0"
-- local lazyvim_tag = "v10.6.0" -- fixed treesitter VeryLazy

local opts_flex = { kw = { "tokyo", "trees", "test", "pyth", "plen" }, override_kw = { "context" } }

local plugins = {
	{ "abeldekat/lazyflex.nvim", version = "*", import = "lazyflex.entry.lazyvim", opts = opts_flex },
	"folke/tokyonight.nvim",
	{ "LazyVim/LazyVim", tag = lazyvim_tag, import = "lazyvim.plugins" },
	{ import = "lazyvim.plugins.extras.lang.python" },
	{ import = "lazyvim.plugins.extras.test.core" },
}
require("lazy").setup(plugins, {})
folke commented

fyi: this is not just with lazy.nvim. Any kind of lazy loading of nvim-treesitter that happens after VimEnter will prevent tests working properly on stable.

It might be good to keep something like the below:

nio.fn.rpcrequest(child_chan, "nvim_exec_lua", "pcall(require, 'nvim-treesitter')", {})

Edit: to be fair, this would only help users that use lazy.nvim since lazy automatically loads a plugin when you require one of its modules...

fnune commented

Hint: neotest does not work (returns "No tests found") for me on nvim-treesitter@v0.9.2. It works when downgrading to v0.9.1: #348 (comment)

Sorry for the late reply to this, I've added back the call for nvim-treesitter in the subprocess on startup

Closing, feel free to re-open if it's not fixed

fnune commented

Updating neotest-jest has made things work for me with treesitter on v0.9.2: nvim-neotest/neotest-jest#100

Also Receiving No Test Found error.

neotest v5.2.5
treesitter: updated latest via lazy as of 2024-05-29

treesitter lazy option set to false

config

return {
  'nvim-neotest/neotest',
  lazy = false,
  dependencies = {
    'nvim-lua/plenary.nvim',
    'nvim-neotest/nvim-nio',
    'nvim-treesitter/nvim-treesitter',
    'nvim-neotest/neotest-jest',
  },
  cmds = {
    'Neotest run',
  },
  keys = {
    {'<leader>tr', '<cmd>Neotest run <cr>', desc = 'run nearest test'},
    {'<leader>tl', '<cmd>Neotest run last<cr>', desc = 'run last test'},
    {'<leader>tf', '<cmd>Neotest run file<cr>', desc = 'run test file'}
  },
  config = function()
    require('neotest').setup({
      adapters = {
        require('neotest-jest'){
          jestCommand = "npx nx test ",
          jestConfigFile = "jest.config.ts",
          env = { CI = true },
          cwd = function()
            return vim.fn.getcwd()
          end,
        },
      },
      config = {
        output_panel = { open_on_run = true },
        diagnostic = true
      }
    })
  end
}