nvim-neotest / neotest

An extensible framework for interacting with tests within NeoVim.
MIT License
2.44k stars 123 forks source link

[BUG] "No tests found" when opening the summary window rigth before running tests the first time #424

Open pepijno opened 5 months ago

pepijno commented 5 months ago

NeoVim Version

NVIM v0.10.0
Build type: Release
LuaJIT 2.1.1693350652

Describe the bug When having a keymap to open the summary window right before running the tests will show the message "No tests found". The second time it does run fine.

To Reproduce A minimal minimal.lua to reproduce which can be run as the following:

nvim --clean -u minimal.lua
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
        vim.fn.system({
                "git",
                "clone",
                "--filter=blob:none",
                "https://github.com/folke/lazy.nvim.git",
                "--branch=stable",
                lazypath,
        })
end
vim.opt.rtp:prepend(lazypath)

vim.g.mapleader = " "
vim.g.maplocalleader = "\\"

require("lazy").setup({
        {
                "nvim-treesitter/nvim-treesitter",
                opts = {
                        ensure_installed = {
                                "lua",
                        },
                        auto_install = true,
                },
        },
        {
                "nvim-neotest/neotest",
                dependencies = {
                        "nvim-neotest/nvim-nio",
                        "nvim-lua/plenary.nvim",
                        "antoinemadec/FixCursorHold.nvim",
                        "nvim-neotest/neotest-plenary",
                },
                config = function()
                        local neotest = require("neotest")

                        vim.keymap.set("n", "<Leader>ta", function()
                                neotest.summary.open()
                                neotest.run.run(vim.fn.expand("%"))
                        end, { desc = "Run all tests" })

                        neotest.setup({
                                log_level = vim.log.levels.TRACE,
                                adapters = {
                                        require("neotest-plenary")
                                },
                        })
                end,
        },
})

Steps to reproduce the behavior:

  1. Go to a plenary test file, for example tests/unit/client/event_spec.lua in the neotest repo.
  2. Run the tests via <leader>ta.
  3. The summary opens and see the error "No tests found".

Expected behavior Expected to have neotest run all the tests in the test file.

Logs neotest.log

Jaimies commented 3 months ago

I have tried changing the order of calls to neotest.summary.open() and neotest.run.run(vim.fn.expand('%')) and the tests did run, even at the first try.

To clarify, I have changed the keymap to the following:

vim.keymap.set("n", "<Leader>ta", function()
    neotest.run.run(vim.fn.expand("%"))
    neotest.summary.open()
end, { desc = "Run all tests" })

My guess as to what is actually causing the issue would be that when the summary opens, neotest starts searching for tests, and if you try to run a test before it's done searching you won't be able to. However, that restriction does not seem necessary as one can call neotest.run.run(...) even with the summary closed and the tests will run.