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 tests found" when opening the summary window rigth before running tests the first time #424

Open
pepijno opened this issue Jun 21, 2024 · 1 comment
Assignees

Comments

@pepijno
Copy link

pepijno commented Jun 21, 2024

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
Copy link

Jaimies commented Aug 18, 2024

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.

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

3 participants