flatten.nvim icon indicating copy to clipboard operation
flatten.nvim copied to clipboard

neotest hangs when running Go tests

Open goropikari opened this issue 1 year ago • 9 comments

Describe the bug Using the latest flatten.nvim (b17a3e65c2e4e2ecd1345a2d08435e80f982c4a6) causes neotest to hang.
When running tests written in Go with neotest, the process hangs.
After performing a git bisect, I identified that the issue occurs from commit ffb29792da8800b01c299e56fb00d8c96d5198a6 onward.
Commits before this do not exhibit the issue.

Expected behavior neotest should not hang.

To Reproduce Steps to reproduce the behavior:

  1. Install the latest flatten.nvim (HEAD).
  2. Use neotest to run the provided Go test file.
  3. Execute lua require('neotest').run.run() on the test file.
  4. Observe that neotest hangs.
package main

import (
	"fmt"
	"testing"
)

func TestHoge(t *testing.T) {
	t.Run("hoge", func(t *testing.T) {
		x := 123
		x++
		fmt.Println(x)
	})
	t.Run("piyo", func(t *testing.T) {
		x := 123
		x++
		fmt.Println(x)
	})
}

Expected behavior neotest should execute the tests without hanging.

Screenshots N/A

Minimal Init

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
  local lazyrepo = "https://github.com/folke/lazy.nvim.git"
  local out = vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "--branch=stable",
    lazyrepo,
    lazypath,
  })
  if vim.v.shell_error ~= 0 then
    vim.api.nvim_echo({
      { "Failed to clone lazy.nvim:\n", "ErrorMsg" },
      { out, "WarningMsg" },
      { "\nPress any key to exit..." },
    }, true, {})
    vim.fn.getchar()
    os.exit(1)
  end
end
vim.opt.rtp:prepend(lazypath)

-- Setup lazy.nvim
require("lazy").setup({
  spec = {
    {
      "nvim-neotest/neotest",
      version = "v5.7.0",
      dependencies = {
        "nvim-neotest/nvim-nio",
        "nvim-lua/plenary.nvim",
        "antoinemadec/FixCursorHold.nvim",
        "nvim-treesitter/nvim-treesitter",
        { "fredrikaverpil/neotest-golang", version = "v1.7.1" }, -- Installation
      },
      config = function()
        require("neotest").setup({
          adapters = {
            require("neotest-golang"), -- Registration
          },
        })
      end,
    },
    {
      "willothy/flatten.nvim",
      opts = {},
      lazy = false,
    },
    {

      "nvim-treesitter/nvim-treesitter",
      version = "*",
      event = "VeryLazy",
      dependencies = {
        "nvim-treesitter/nvim-treesitter-textobjects",
      },
      build = ":TSUpdate",
      config = function()
        vim.defer_fn(function()
          require("nvim-treesitter.configs").setup({
            ensure_installed = { "go" },
            auto_install = true,
            sync_install = false,
            ignore_install = {},
            modules = {},
            highlight = { enable = true },
            indent = { enable = true },
          })
        end, 0)
      end,
    },
  },
  checker = { enabled = true },
})

Desktop (please complete the following information):

  • OS: Ubuntu 24.04 and 24.10
  • Terminal emulator: Alacritty
  • Neovim version: 0.10.3

Additional context

The issue might be related to the recent major refactoring, so this behavior could be intentional. However, I am reporting it in case it is not expected. I have only tested this issue with Go and have not investigated its behavior with other programming languages.

The investigation was conducted in a devcontainer environment. The full configuration of the environment can be found at the following link: https://github.com/goropikari/flatten.nvim/tree/neotest/.devcontainer

goropikari avatar Jan 01 '25 19:01 goropikari

Ahh this is probably due to Neotest running in a nested Neovim session. I'll see if I can get this fixed today :)

willothy avatar Jan 01 '25 19:01 willothy

Thank you for the quick response. For now, as long as I'm using v0.5.1, there's no issue, so there's no need to rush. Wishing you a Happy New Year!

goropikari avatar Jan 01 '25 19:01 goropikari

Sounds good! Happy new year to you as well :)

willothy avatar Jan 02 '25 06:01 willothy

I can't repro this with the default config, but I can with my own. Can you provide your flatten.nvim config?

willothy avatar Feb 05 '25 18:02 willothy

This configuration reproduces the issue in the Neovim config and devcontainer environment. https://github.com/goropikari/flatten.nvim/tree/neotest/.devcontainer

goropikari avatar Feb 06 '25 11:02 goropikari

Hmm, seems will cause hangs with any language (including Go).

tan-wei avatar Feb 25 '25 02:02 tan-wei

Having the same issue with jest..

IvanVelinov94 avatar Mar 20 '25 13:03 IvanVelinov94

Same issue with jest and vitest. As soon as I call any action in neotest (run, summary, etc) the whole neovim process hangs. I just reproduced this yesterday after I integrated flatten in my config a couple of days ago.

carloscalla avatar Jun 16 '25 22:06 carloscalla

The issue likely will occur with any plugin that uses nested nvim sessions / spawns its own "worker" nvim instances. We'll need a system to ignore certain instances of nvim that are meant to be used in that way. I am extremely busy with work right now but will try to prioritize this a bit since this is a pretty serious issue for anyone using neotest. Sorry about this, thanks for using flatten! :)

willothy avatar Jun 17 '25 17:06 willothy