MisanthropicBit / neotest-busted

Highly experimental neotest adapter for running tests using busted
BSD 3-Clause "New" or "Revised" License
9 stars 2 forks source link

Use local busted installation #22

Closed polirritmico closed 1 month ago

polirritmico commented 1 month ago

Did you check docs and existing issues?

Neovim version (nvim -v)

NVIM v0.10.2 Build type: Release LuaJIT 2.1.1716656478

Operating system/version

Gentoo Linux 2.15, kernel 6.6.52-gentoo (64 bits)

Describe the bug

Hi, I've been following this project from some time but I still can't get things working, most probably I'm setting something wrong. I don't know if this is possible at the current plugin state, but I want to use a local busted installed through a lazy.nvim bootstrap. This is my neotest config:

{
  "nvim-neotest/neotest",
  dependencies = {
    "nvim-neotest/nvim-nio",
    "nvim-lua/plenary.nvim",
    "antoinemadec/FixCursorHold.nvim",
    "nvim-treesitter/nvim-treesitter",
    -- Adapters
    "MisanthropicBit/neotest-busted",
  },
  -- stylua: ignore
  keys = {
    { "<leader>rtf", function() require("neotest").run.run(vim.fn.expand("%")) end, desc = "neotest: Run all test in the current file" },
  },
  opts = {
    status = { virtual_text = true },
    output = { open_on_run = true },
    log_level = vim.log.levels.debug,
  },
  config = function(_, opts)
    opts.adapters = {
      require("neotest-busted")({
        busted_command = ".tests/data/nvim/lazy/busted/busted/runner.lua",
        busted_paths = {
          ".tests/data/nvim/lazy-rocks/busted/share/lua/5.1/pl/?.lua",
        },
        minimal_init = "tests/minit.lua",
        local_luarocks_only = true,
      }),
    }
    require("neotest").setup(opts)
  end,
},

But I'm getting not found modules errors when executing the tests:

E5113: Error while calling lua chunk: .tests/data/nvim/lazy/busted/busted/runner.lua:3: module 'pl.path' not found:
        no field package.preload['pl.path']
cache_loader: module pl.path not found
cache_loader_lib: module pl.path not found
        no file '.tests/data/nvim/lazy-rocks/busted/share/lua/5.1/pl/pl/path.lua'
        no file 'lua/pl/path.lua'
        no file 'lua/pl/path/init.lua'
        no file './pl/path.lua'
        no file '/usr/share/luajit-2.1/pl/path.lua'
        no file '/usr/local/share/lua/5.1/pl/path.lua'
        no file '/usr/local/share/lua/5.1/pl/path/init.lua'
        no file '/usr/share/lua/5.1/pl/path.lua'
        no file '/usr/share/lua/5.1/pl/path/init.lua'
        no file './pl/path.so'
        no file '/usr/local/lib/lua/5.1/pl/path.so'
        no file '/usr/lib64/lua/5.1/pl/path.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
        no file './pl.so'
        no file '/usr/local/lib/lua/5.1/pl.so'
        no file '/usr/lib64/lua/5.1/pl.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
        [C]: in function 'require'
        .tests/data/nvim/lazy/busted/busted/runner.lua:3: in main chunk

Also I got an error message complaining about a missing json test output (check the neotest.log).

Running the tests with: nvim --clean -l tests/minit.lua --busted tests -o utfTerminal work without any problem. I've made this repo to provide the minimal environment. Check the reproduction steps.

Expected Behavior

Found all the busted modules installed inside .tests/data/nvim path and run the tests through neotest without problems.

Output of :checkhealth neotest-busted if relevant

Got this error:

- ERROR config has errors: busted command in configuration is not executable
- OK found `busted` (type: config) at
  /home/<username>/tmp/foo.nvim/.tests/data/nvim/lazy/busted/busted/runner.lua

But fixing that changing the runner.lua execution permissions only fix the checkhealth check:

neotest-busted ~
- WARNING vim.health.report_ok() is deprecated, use vim.health.ok() instead. :help |deprecated|
  Feature will be removed in Nvim 0.11
- OK has neovim 0.9.0+
- OK `neotest` is installed
- OK `nio` is installed
- OK found no errors in config
- OK found `busted` (type: config) at
  /home/<username>/tmp/foo.nvim/.tests/data/nvim/lazy/busted/busted/runner.lua

neotest log output if relevant

ERROR | 2024-10-08T13:07:26Z-0300 | ...are/nvim/lazy/neotest-busted/lua/neotest-busted/init.lua:26 | Failed to read json test output file /tmp/nvim.<username>/HCE66a/0.json with error: ...al/share/nvim/lazy/neotest/lua/neotest/lib/file/init.lua:25: ENOENT: no such file or directory: /tmp/nvim.<username>/HCE66a/0.json

Steps To Reproduce

-- repro.lua
vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

if not vim.uv.fs_stat("foo.nvim") then
  vim.fn.system({ "git", "clone", "https://github.com/polirritmico/foo.nvim.git" })
end

require("lazy.minit").repro({
  spec = {
    { "folke/tokyonight.nvim", enabled = false },
    {
      "nvim-neotest/neotest",
      dependencies = {
        "nvim-neotest/nvim-nio",
        "nvim-lua/plenary.nvim",
        "antoinemadec/FixCursorHold.nvim",
        "nvim-treesitter/nvim-treesitter",
        -- Adapters
        "MisanthropicBit/neotest-busted",
      },
    -- stylua: ignore
    keys = {
      { "<leader>rtf", function() require("neotest").run.run(vim.fn.expand("%")) end, desc = "neotest: Run all test in the current file" },
      { "<leader>rto", function() require("neotest").output_panel.toggle() end, desc = "neotest: Toggle output panel" },
      { "<leader>rtp", function() require("neotest").summary.toggle() end, desc = "neotest: Toggle summary panel" },
    },
      opts = {
        status = { virtual_text = true },
        output = { open_on_run = true },
      },
      config = function(_, opts)
        opts.adapters = {
          require("neotest-busted")({
            busted_command = ".tests/data/nvim/lazy/busted/busted/runner.lua",
            busted_paths = {
              ".tests/data/nvim/lazy-rocks/busted/share/lua/5.1/pl/?.lua",
            },
            minimal_init = "tests/minit.lua",
            local_luarocks_only = true,
          }),
        }
        require("neotest").setup(opts)
      end,
    },
  },
})

vim.cmd("cd foo.nvim")
vim.cmd("edit tests/neotest_spec.lua")
  1. Add the repro.lua file to an empty directory.
  2. Execute the repro.lua file through nvim: nvim -u repro.lua and exit nvim.
  3. Inside foo.nvim, run the tests through the bootstrap: cd foo.nvim, nvim --clean -l tests/minit.lua --busted tests -o utfTerminal
  4. Should install the environment and run the tests with 1 success and 1 failure
  5. Again, run the repro: cd .., nvim -u repro.lua
  6. And run neotest: :lua require("neotest").run.run(vim.fn.expand("%"))
  7. Error:
Failed to read json test output file /tmp/nvim.<username>/4gO8hc/2.json with error: ...al/share/nvim/lazy/neotest/lua/neotest/lib/file/init.lua:25: ENOENT: no such file or directory: /tmp/nvim.<username>/4gO8hc/2.json
Press ENTER or type command to continue

Don't know if more info is needed.

Thanks!

MisanthropicBit commented 1 month ago

Hi again @polirritmico. Thanks for submitting another issue and providing a detailed description. Really helps with debugging! 🙂

I'm currently on holiday and away from my computer. I'll be home next week where I can try your repro and provide more help.

A few things regarding the errors etc.

Hope that helps for now.

polirritmico commented 1 month ago

Hi. Thanks for the info. Finally I was able to get things running. I had to:

  1. update the minimal_init file:
#!/usr/bin/env -S nvim -l

Remote = false
vim.env.LAZY_STDPATH = ".tests"
local url = "https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"

if Remote then
  load(vim.fn.system("curl -s " .. url))()
else
  local bootstrap = ".tests/bootstrap.lua"
  if not vim.uv.fs_stat(bootstrap) then
    vim.fn.mkdir(vim.fs.dirname(bootstrap), "p")
    vim.fn.system("curl -s " .. url .. " -o " .. bootstrap)
  end
  loadfile(bootstrap)()
end

-- Setup lazy.nvim
require("lazy.minit").busted({
  spec = {},
})
  1. remove the old bootstrap
$ rm -rf .tests
  1. update the neotest-busted config:
require("neotest-busted")({
  busted_command = ".tests/data/nvim/lazy/busted/bin/busted",
  minimal_init = "tests/busted.lua",
  local_luarocks_only = true,
}),
  1. Run the new bootstrap
$ nvim -l tests/minit.lua tests
  1. And finally run neotest!:

imagen

Thanks for the help!