nvim-neotest / neotest

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

[BUG] Lags and times out on first 1-2 runs on MacOS #207

Open roginfarrer opened 1 year ago

roginfarrer commented 1 year ago

New issue from this comment: https://github.com/nvim-neotest/neotest/issues/198#issuecomment-1431991497

NeoVim Version NVIM v0.9.0-dev-3545+g6c39edaa7-dirty Build type: Release LuaJIT 2.1.0-beta3

Describe the bug When I run test_file, I get hit with some lag in my editor, and eventually the lag recedes but no test has been run or feedback given. I hit it again, and sometimes I get nothing, sometimes I get "No test found", or sometimes the test runs.

I tried setting discovery.concurrent = 1, but then I get this error:

Error executing vim.schedule lua callback: ...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:18: The coroutine failed with this message: ...local/share/nvim/lazy/neotest/lua/neotest/types/tree.lua:179: attempt to index a nil value
stack traceback:
    [C]: in function 'error'
    ...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:18: in function 'callback_or_next'
    ...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:45: in function <...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:44>

I also sometimes get this error:

Error detected while processing BufEnter Autocommands for "*":
Error executing lua callback: ...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:18: The coroutine failed with this message: ...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:18: The coroutine failed with this message: ...local/share/nvim/lazy/neotest/lua/neotest/types/tree.lua:179: attempt to index a nil value
stack traceback:
    [C]: in function 'error'
    ...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:18: in function 'callback_or_next'
    ...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:45: in function 'step'
    ...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:48: in function 'execute'
    ...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:108: in function 'run'
    ...ocal/share/nvim/lazy/neotest/lua/neotest/client/init.lua:461: in function <...ocal/share/nvim/lazy/neotest/lua/neotest/client/init.lua:459>

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',
      'haydenmeade/neotest-jest',
    },
    config = function()
      require('neotest').setup {
        adapters = {
          require 'neotest-jest' {
            cwd = function(path)
              local cwd = require('neotest-jest.util').find_package_json_ancestor(path)
              return cwd
            end,
          },
        },
      }
    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()
]]

Here's an example test:

import React from 'react';
import {render, screen} from '@testing-library/react';

function Button(props) {
  return <button {...props} />
}

describe('Button', () => {
  it('renders a button', () => {
    render(<Button>hey</Button>);
    expect(screen.getByRole('button')).toBeInTheDocument();
  });
});

Logs

WARN | 2023-02-17T10:12:28Z-0800 | ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:156 | CHILD | Error in remote call ...39eda/share/nvim/runtime/lua/vim/treesitter/language.lua:23: '' is not a valid language name
stack traceback:
    [C]: in function 'error'
    ...39eda/share/nvim/runtime/lua/vim/treesitter/language.lua:23: in function 'require_language'
    ...m/HEAD-6c39eda/share/nvim/runtime/lua/vim/treesitter.lua:124: in function 'get_string_parser'
    ...re/nvim/lazy/neotest/lua/neotest/lib/treesitter/init.lua:118: in function 'get_parse_root'
    ...re/nvim/lazy/neotest/lua/neotest/lib/treesitter/init.lua:159: in function 'parse_positions_from_string'
    ...re/nvim/lazy/neotest/lua/neotest/lib/treesitter/init.lua:206: in function 'func'
    ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:148: in function <...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:147>
    [C]: in function 'xpcall'
    ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:147: in function <...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:146>
WARN | 2023-02-17T10:12:28Z-0800 | ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:156 | CHILD | Error in remote call ...39eda/share/nvim/runtime/lua/vim/treesitter/language.lua:23: '' is not a valid language name
stack traceback:
    [C]: in function 'error'
    ...39eda/share/nvim/runtime/lua/vim/treesitter/language.lua:23: in function 'require_language'
    ...m/HEAD-6c39eda/share/nvim/runtime/lua/vim/treesitter.lua:124: in function 'get_string_parser'
    ...re/nvim/lazy/neotest/lua/neotest/lib/treesitter/init.lua:118: in function 'get_parse_root'
    ...re/nvim/lazy/neotest/lua/neotest/lib/treesitter/init.lua:159: in function 'parse_positions_from_string'
    ...re/nvim/lazy/neotest/lua/neotest/lib/treesitter/init.lua:206: in function 'func'
    ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:148: in function <...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:147>
    [C]: in function 'xpcall'
    ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:147: in function <...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:146>
WARN | 2023-02-17T10:12:30Z-0800 | ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:156 | CHILD | Error in remote call ...-6c39eda/share/nvim/runtime/lua/vim/treesitter/query.lua:261: query: invalid node type at position 66 for language json
stack traceback:
    [C]: in function '_ts_parse_query'
    ...-6c39eda/share/nvim/runtime/lua/vim/treesitter/query.lua:261: in function 'parse_query'
    ...re/nvim/lazy/neotest/lua/neotest/lib/treesitter/init.lua:103: in function 'normalise_query'
    ...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:206: in function 'func'
    ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:148: in function <...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:147>
    [C]: in function 'xpcall'
    ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:147: in function <...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:146>
WARN | 2023-02-17T10:12:31Z-0800 | ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:156 | CHILD | Error in remote call ...-6c39eda/share/nvim/runtime/lua/vim/treesitter/query.lua:261: query: invalid node type at position 66 for language json
stack traceback:
    [C]: in function '_ts_parse_query'
    ...-6c39eda/share/nvim/runtime/lua/vim/treesitter/query.lua:261: in function 'parse_query'
    ...re/nvim/lazy/neotest/lua/neotest/lib/treesitter/init.lua:103: in function 'normalise_query'
    ...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:206: in function 'func'
    ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:148: in function <...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:147>
    [C]: in function 'xpcall'
    ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:147: in function <...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:146>
WARN | 2023-02-17T10:12:32Z-0800 | ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:156 | CHILD | Error in remote call ...-6c39eda/share/nvim/runtime/lua/vim/treesitter/query.lua:261: query: invalid node type at position 66 for language json
stack traceback:
    [C]: in function '_ts_parse_query'
    ...-6c39eda/share/nvim/runtime/lua/vim/treesitter/query.lua:261: in function 'parse_query'
    ...re/nvim/lazy/neotest/lua/neotest/lib/treesitter/init.lua:103: in function 'normalise_query'
    ...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:206: in function 'func'
    ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:148: in function <...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:147>
    [C]: in function 'xpcall'
    ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:147: in function <...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:146>
WARN | 2023-02-17T10:12:33Z-0800 | ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:156 | CHILD | Error in remote call ...-6c39eda/share/nvim/runtime/lua/vim/treesitter/query.lua:261: query: invalid node type at position 66 for language json
stack traceback:
    [C]: in function '_ts_parse_query'
    ...-6c39eda/share/nvim/runtime/lua/vim/treesitter/query.lua:261: in function 'parse_query'
    ...re/nvim/lazy/neotest/lua/neotest/lib/treesitter/init.lua:103: in function 'normalise_query'
    ...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:206: in function 'func'
    ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:148: in function <...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:147>
    [C]: in function 'xpcall'
    ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:147: in function <...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:146>
WARN | 2023-02-17T10:12:34Z-0800 | ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:156 | CHILD | Error in remote call ...-6c39eda/share/nvim/runtime/lua/vim/treesitter/query.lua:261: query: invalid node type at position 66 for language json
stack traceback:
    [C]: in function '_ts_parse_query'
    ...-6c39eda/share/nvim/runtime/lua/vim/treesitter/query.lua:261: in function 'parse_query'
    ...re/nvim/lazy/neotest/lua/neotest/lib/treesitter/init.lua:103: in function 'normalise_query'
    ...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:206: in function 'func'
    ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:148: in function <...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:147>
    [C]: in function 'xpcall'
    ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:147: in function <...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:146>
WARN | 2023-02-17T10:12:35Z-0800 | ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:156 | CHILD | Error in remote call ...-6c39eda/share/nvim/runtime/lua/vim/treesitter/query.lua:261: query: invalid node type at position 66 for language json
stack traceback:
    [C]: in function '_ts_parse_query'
    ...-6c39eda/share/nvim/runtime/lua/vim/treesitter/query.lua:261: in function 'parse_query'
    ...re/nvim/lazy/neotest/lua/neotest/lib/treesitter/init.lua:103: in function 'normalise_query'
    ...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:206: in function 'func'
    ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:148: in function <...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:147>
    [C]: in function 'xpcall'
    ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:147: in function <...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:146>
WARN | 2023-02-17T10:12:36Z-0800 | ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:156 | CHILD | Error in remote call ...-6c39eda/share/nvim/runtime/lua/vim/treesitter/query.lua:261: query: invalid node type at position 66 for language json
stack traceback:
    [C]: in function '_ts_parse_query'
    ...-6c39eda/share/nvim/runtime/lua/vim/treesitter/query.lua:261: in function 'parse_query'
    ...re/nvim/lazy/neotest/lua/neotest/lib/treesitter/init.lua:103: in function 'normalise_query'
    ...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:206: in function 'func'
    ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:148: in function <...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:147>
    [C]: in function 'xpcall'
    ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:147: in function <...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:146>

Additional context

rcarriga commented 1 year ago

Unfortunately I can't reproduce. I'm not sure if this is a treesitter issue or an issue with the subprocess loading. Can you try reinstall your treesitter parsers? If that doesn't work, can you comment out this line https://github.com/nvim-neotest/neotest/blob/b06b0ccbddc61acfe781689da969d2e0117b3dfe/lua/neotest/client/init.lua#L373 to disable the subprocess starting and see if the behaviour is the same?

roginfarrer commented 1 year ago

That does seem to help! Both "nearest test" and the "file tests" kick-off on the first try.

Reinstalling the parsers didn't have an effect, but commenting out that line did.

rcarriga commented 1 year ago

Is this happening for all jest projects? Can you point to a public repo I can test?

Right now I believe the issues lies with plenary's filetype detection https://github.com/nvim-neotest/neotest/blob/b06b0ccbddc61acfe781689da969d2e0117b3dfe/lua/neotest/lib/treesitter/init.lua#L115 but I'm not sure what would cause the issue. If you can't provide a public repo to reproduce, the only thing I can suggest is manually logging such as after that line adding logger.info(file_path, "detected as", ft) and seeing if the values are valid

lukesarnacki commented 1 year ago

I have a similar issue on fedora. I have the same setup (via dotfiles repo) on my Mac as well. For some reason on Mac it works fine but on linux it works only if I comment the following line you mentioned in the other comment:

lib.subprocess.init() 

Stacktrace from neotest.log:

ERROR | 2023-03-16T18:54:42Z+0100 | ...te/pack/packer/start/neotest/lua/neotest/client/init.lua:310 | Couldn't find positions in path /home/luke/projects/diva/store-bridge/dist/__tests__/server.js.map ...0.8.3/share/nvim/runtime/lua/vim/treesitter/language.lua:23: '' is not a valid language name
stack traceback:
    [C]: in function 'error'
    ...0.8.3/share/nvim/runtime/lua/vim/treesitter/language.lua:23: in function 'require_language'
    ...r/neovim/0.8.3/share/nvim/runtime/lua/vim/treesitter.lua:116: in function 'get_string_parser'
    ...packer/start/neotest/lua/neotest/lib/treesitter/init.lua:118: in function 'get_parse_root'
    ...packer/start/neotest/lua/neotest/lib/treesitter/init.lua:159: in function 'parse_positions_from_string'
    ...packer/start/neotest/lua/neotest/lib/treesitter/init.lua:206: in function 'discover_positions'
    ...te/pack/packer/start/neotest/lua/neotest/client/init.lua:301: in function <...te/pack/packer/start/neotest/lua/neotest/client/init.lua:265>
    [C]: in function 'xpcall'
    ...te/pack/packer/start/neotest/lua/neotest/client/init.lua:265: in function '_update_positions'
    ...te/pack/packer/start/neotest/lua/neotest/client/init.lua:318: in function <...te/pack/packer/start/neotest/lua/neotest/client/init.lua:316>

Are there any other details I could provide?

rcarriga commented 1 year ago

Can you enable debug logging, add the log line as I detailed here https://github.com/nvim-neotest/neotest/issues/207#issuecomment-1447823605 and provide the full log?

bjornsnoen commented 1 year ago

So I'm running on arch linux and for me it just freezes completely, no lag, but commenting out the lib.subprocess.init line works for me as well. I added the log line, but it freezes before it can log anything. Doesn't matter how long I wait, only way out is to kill the neovim process. My config is at https://github.com/bjornsnoen/dotfiles/tree/master/nvim for reproducing.

I've been trying to create a solid set of steps to reproduce, but this is the best I've got.

  1. Install neotest and neotest-vitest
  2. Create a new nextjs app with npx create-next-app all defaults, default app name is my-app
  3. Install vitest with npm i vitest inside the new app
  4. Create the file src/tests/something.test.ts
  5. Write an empty test
    • import { test } from "vitest"; test("something", () => {});
    • If using my dotfiles, add scripts.test: "vitest" to package.json
  6. Run the test. The following error pops up. It seems to always happen right away.
Error executing vim.schedule lua callback: ...e/bjorn/.local/share/nvim/lazy/neotest/lua/nio/tasks.lua:95: Async task failed without callback: The coroutine failed with this message:          
...e/bjorn/.local/share/nvim/lazy/neotest/lua/nio/tasks.lua:95: Async task failed without callback: The coroutine failed with this message:                                                     
...vim/lazy/neotest/lua/neotest/consumers/state/tracker.lua:47: attempt to index local 'tree' (a nil value)                                                                                     
stack traceback:                                                                                                                                                                                
        ...vim/lazy/neotest/lua/neotest/consumers/state/tracker.lua: in function 'is_test'                                                                                                      
        ...vim/lazy/neotest/lua/neotest/consumers/state/tracker.lua:155: in function 'update_running'                                                                                           
        ...e/nvim/lazy/neotest/lua/neotest/consumers/state/init.lua:49: in function 'listener'                                                                                                  
        ...are/nvim/lazy/neotest/lua/neotest/client/events/init.lua:51: in function <...are/nvim/lazy/neotest/lua/neotest/client/events/init.lua:47>                                            
stack traceback:                                                                                                                                                                                
        [C]: in function 'error'                                                                                                                                                                
        ...e/bjorn/.local/share/nvim/lazy/neotest/lua/nio/tasks.lua:95: in function 'close_task'                                                                                                
        ...e/bjorn/.local/share/nvim/lazy/neotest/lua/nio/tasks.lua:117: in function 'step'                                                                                                     
        ...e/bjorn/.local/share/nvim/lazy/neotest/lua/nio/tasks.lua:143: in function 'run'                                                                                                      
        ...are/nvim/lazy/neotest/lua/neotest/client/events/init.lua:47: in function 'emit'                                                                                                      
        ...hare/nvim/lazy/neotest/lua/neotest/client/state/init.lua:96: in function 'update_running'                                                                                            
        ...ocal/share/nvim/lazy/neotest/lua/neotest/client/init.lua:82: in function 'run_tree'                                                                                                  
        ...al/share/nvim/lazy/neotest/lua/neotest/consumers/run.lua:72: in function 'func'                                                                                                      
        ...e/bjorn/.local/share/nvim/lazy/neotest/lua/nio/tasks.lua:166: in function <...e/bjorn/.local/share/nvim/lazy/neotest/lua/nio/tasks.lua:165>                                          
stack traceback:                                                                                                                                                                                
        [C]: in function 'error'                                                                                                                                                                
        ...e/bjorn/.local/share/nvim/lazy/neotest/lua/nio/tasks.lua:95: in function 'close_task'                                                                                                
        ...e/bjorn/.local/share/nvim/lazy/neotest/lua/nio/tasks.lua:117: in function 'cb'                                                                                                       
        ...e/bjorn/.local/share/nvim/lazy/neotest/lua/nio/tasks.lua:179: in function <...e/bjorn/.local/share/nvim/lazy/neotest/lua/nio/tasks.lua:178> 
  1. Ignore the error, go about your merry day. Running the test again works just fine.
  2. Exit vim
  3. Reopen vim, attempt to run the test
  4. Observe the freeze

Note that this fs path is now tainted somehow. If you rm the whole app directory and start over reusing the same app name, it will skip the error in step 6 and go straight to step 10. Again, commenting out the subrocess.init line does fix this. It also brings back the error in step 6 so it happens every time.

Hope this helps a bit!

zv4w1qol commented 2 weeks ago

Hello,

I've come across a similar issue, I guess (or just hesitate to create a new issue). Anyway, it happens frequently to me, but not every time. Apparently it's a concurrency issue. The error is the same as in the comment https://github.com/nvim-neotest/neotest/issues/207#issuecomment-1534357498, but the stack trace is slightly different, I guess the version of neotest is different, because it's been a year and a half since that time.

I'll post the stack trace if it makes sense

Error executing vim.schedule lua callback: ...ord/.local/share/nvim/plugged/nvim-nio/lua/nio/tasks.lua:100: Async task failed without callback: The coroutine failed with this message:
...ord/.local/share/nvim/plugged/nvim-nio/lua/nio/tasks.lua:100: Async task failed without callback: The coroutine failed with this message:
.../plugged/neotest/lua/neotest/consumers/state/tracker.lua:47: attempt to index local 'tree' (a nil value)
stack traceback:
        .../plugged/neotest/lua/neotest/consumers/state/tracker.lua: in function 'is_test'
        .../plugged/neotest/lua/neotest/consumers/state/tracker.lua:155: in function 'update_running'
        ...vim/plugged/neotest/lua/neotest/consumers/state/init.lua:49: in function 'listener'
        .../nvim/plugged/neotest/lua/neotest/client/events/init.lua:51: in function <.../nvim/plugged/neotest/lua/neotest/client/events/init.lua:47>
stack traceback:
        [C]: in function 'error'
        ...ord/.local/share/nvim/plugged/nvim-nio/lua/nio/tasks.lua:100: in function 'close_task'
        ...ord/.local/share/nvim/plugged/nvim-nio/lua/nio/tasks.lua:122: in function 'step'
        ...ord/.local/share/nvim/plugged/nvim-nio/lua/nio/tasks.lua:150: in function 'run'
        .../nvim/plugged/neotest/lua/neotest/client/events/init.lua:47: in function 'emit'
        ...e/nvim/plugged/neotest/lua/neotest/client/state/init.lua:95: in function 'update_running'
        ...l/share/nvim/plugged/neotest/lua/neotest/client/init.lua:82: in function 'run_tree'
        ...share/nvim/plugged/neotest/lua/neotest/consumers/run.lua:85: in function 'func'
        ...ord/.local/share/nvim/plugged/nvim-nio/lua/nio/tasks.lua:173: in function <...ord/.local/share/nvim/plugged/nvim-nio/lua/nio/tasks.lua:172>
stack traceback:
        [C]: in function 'error'
        ...ord/.local/share/nvim/plugged/nvim-nio/lua/nio/tasks.lua:100: in function 'close_task'
        ...ord/.local/share/nvim/plugged/nvim-nio/lua/nio/tasks.lua:122: in function 'cb'
        ...ord/.local/share/nvim/plugged/nvim-nio/lua/nio/tasks.lua:188: in function 'waiter'
        ...d/.local/share/nvim/plugged/nvim-nio/lua/nio/control.lua:57: in function 'set'
        ...lord/.local/share/nvim/plugged/nvim-nio/lua/nio/init.lua:109: in function 'cb'
        ...ord/.local/share/nvim/plugged/nvim-nio/lua/nio/tasks.lua:105: in function 'close_task'
        ...ord/.local/share/nvim/plugged/nvim-nio/lua/nio/tasks.lua:127: in function 'cb'
        ...ord/.local/share/nvim/plugged/nvim-nio/lua/nio/tasks.lua:188: in function 'waiter'
        ...d/.local/share/nvim/plugged/nvim-nio/lua/nio/control.lua:57: in function 'set'
        ...lord/.local/share/nvim/plugged/nvim-nio/lua/nio/init.lua:151: in function 'cb'
        ...ord/.local/share/nvim/plugged/nvim-nio/lua/nio/tasks.lua:105: in function 'close_task'
        ...ord/.local/share/nvim/plugged/nvim-nio/lua/nio/tasks.lua:127: in function 'cb'
        ...ord/.local/share/nvim/plugged/nvim-nio/lua/nio/tasks.lua:188: in function 'handler'
        ...home/wantlord/Apps/neovim/runtime/lua/vim/lsp/client.lua:687: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

Given that, I popped out the debugger for Neovim plugins and found that StateTracker:update_running runs sometimes before StateTracker:update_positions. Therefore the field positions is nil. So, I did this:

diff --git a/lua/neotest/consumers/state/init.lua b/lua/neotest/consumers/state/init.lua
index c9e48ee..eeb90e9 100644
--- a/lua/neotest/consumers/state/init.lua
+++ b/lua/neotest/consumers/state/init.lua
@@ -33,10 +33,12 @@ local function init(client)
   for _, buf in ipairs(nio.api.nvim_list_bufs()) do
     tracker:register_buffer(buf)
   end
+  local event = nio.control.event()
   nio.run(function()
     xpcall(update_positions, function(msg)
       logger.error("Error in state consumer", debug.traceback(msg, 2))
     end)
+    event.set()
   end)
   client.listeners.discover_positions = function(adapter_id)
     if not tracker:adapter_state(adapter_id) then
@@ -46,7 +48,7 @@ local function init(client)
   end

   client.listeners.run = function(adapter_id, _, position_ids)
-    tracker:update_running(adapter_id, position_ids)
+    tracker:update_running(adapter_id, position_ids, event)
   end

   client.listeners.results = function(adapter_id, results)
diff --git a/lua/neotest/consumers/state/tracker.lua b/lua/neotest/consumers/state/tracker.lua
index 06a8a3f..4d7989c 100644
--- a/lua/neotest/consumers/state/tracker.lua
+++ b/lua/neotest/consumers/state/tracker.lua
@@ -147,7 +147,8 @@ function StateTracker:register_buffer(buffer)
   self.path_buffers[path] = buffer
 end

-function StateTracker:update_running(adapter_id, position_ids)
+function StateTracker:update_running(adapter_id, position_ids, event)
+  event.wait()
   local state = self:adapter_state(adapter_id)
   local running = state.running
   local tree = state.positions

I doubt that it can be a proper fix, because it might break the design view of the author. However, it does the work just fine.

If you give me an insight, I'm happy to make a proper fix.