nvim-neotest / neotest

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

[BUG] enabling quickfix causes weirdness on test fail #219

Closed benlubas closed 1 year ago

benlubas commented 1 year ago

NeoVim Version

output of `nvim --version` NVIM v0.8.3 Build type: Release LuaJIT 2.1.0-beta3 Compiled by linuxbrew@1eb16d0118e5 Features: +acl +iconv +tui See ":help feature-compile" system vimrc file: "$VIM/sysinit.vim" fall-back for $VIM: " /home/linuxbrew/.linuxbrew/Cellar/neovim/0.8.3/share/nvim" Run :checkhealth for more info

Describe the bug Sometimes when running a test the test file is closed and the cmdheight seems to get set to a large number. I've had this problem across MacOS and Linux, and it's happened with ruby/rspec and javascript/jest tests.

Here is a recording of what it looks like:

https://user-images.githubusercontent.com/56943754/224509195-98a9b46b-8b76-4573-ac23-e32f027b9514.mp4

I've seen the same thing happen with jest tests too. I haven't figured out a reliable way to quickly reproduce that one yet. In the jest case, there is nothing like binding.pry, and no need to attach to the running test. Sometimes the test will just fail, and the bug happens.

To Reproduce

minimal.lua ```lua -- 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 = { "vim-test/vim-test", "nvim-lua/plenary.nvim", "nvim-treesitter/nvim-treesitter", "antoinemadec/FixCursorHold.nvim", "olimorris/neotest-rspec", }, config = function() require("neotest").setup({ adapters = {require("neotest-rspec")}, }) 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() ]]) ```

Steps to reproduce the behavior:

  1. Install ruby and bundler: nix-env -iA nixpkgs.ruby or brew install ruby
  2. mkdir neotest-bug && cd neotest-bug
  3. echo "gem 'rspec'" >> Gemfile && echo "gem 'pry'" >> Gemfile
  4. mkdir spec && touch spec/sample_spec.rb
  5. copy into sample_spec.rb:
    
    require 'pry'

describe 'a test' do it 'does a weird thing' do expect(true).to be true # correct test binding.pry expect(true).to be false # failing test end end


6. `bundle install`
7. `nvim --clean -u minimal.lua spec/sample_spec.rb`
8. go to the `it` line and type: `:NeotestNearest` to run the test
9. type: `:NeotestAttach` to attach to the running process, it should be stopped by the `binding.pry`
10. shift + a to start typing, `exit` enter to exit the pry

**Expected behavior**

I expect the test to fail as normal. I do not expect the test file to disappear. 

I also don't expect the command height to change

**Logs**

[neotest.log](https://github.com/nvim-neotest/neotest/files/10949384/neotest.log)
benlubas commented 1 year ago

Played around with this some more. It's related to the quickfix list. Here are some things that I discovered:

rcarriga commented 1 year ago

I believe this is a neovim internals issue but I've made a small change in the output consumer and it seems to have fixed it for me, but it also doesn't reproduce reliably. Can you verify?

benlubas commented 1 year ago

I tested with the new changes and the ruby issue still happens 10/10 times.

The method of reproducing with jest now doesn't reproduce on the first test run. But subsequent runs of the test do cause the bug seemingly 100% of the time.

austinphilp commented 1 year ago

Just wanted to drop in to say I'm experiencing this same issue with a python/django project, disabling quickfix worked for me as well

patricio-ferraggi-deel commented 1 year ago

This is also happening to me on jest. If you have the summary open and your cursor there, the qf will take over the summary too. Very strange. I disabled qf for now

rcarriga commented 1 year ago

As this is a race condition within Neovim core there's not too much that neotest can do. I've disabled quickfix opening by default since it doesn't make much sense having both output and quickfix open at the same time anyway so at least users won't see it by default