neotest-elixir icon indicating copy to clipboard operation
neotest-elixir copied to clipboard

Running tests in docker container

Open guess opened this issue 1 year ago • 1 comments

Hi! I am trying to run my tests in a docker container, however I am getting these errors because it can't find the formatter.ex and json_encoder.ex in my container:

-r : No files matched pattern /Users/steve/.local/share/nvim/lazy/neotest-elixir/neotest_elixir/json_encoder.ex
-r : No files matched pattern /Users/steve/.local/share/nvim/lazy/neotest-elixir/neotest_elixir/formatter.ex

Is there a way to override these paths somehow so I can mount the files and point to the new location in the container?

Here is how I am setting it up:

require("neotest").setup({
  log_level = vim.log.levels.DEBUG,
  adapters = {
    require("neotest-elixir")({
      post_process_command = function(cmd)
        return vim.tbl_flatten({
          { "docker", "compose",     "exec", "-i" },
          { "-w",     "/app" },
          { "-e",     "MIX_ENV=test" },
          { "app" },
          cmd })
      end,
    }),
  },
})

Or do you have a better recommendation for how to run these in docker instead?

guess avatar Jun 17 '24 14:06 guess

Running inside Docker is tricky. See https://github.com/nvim-neotest/neotest/issues/89. Most of the issues mentioned there apply to the Elixir adapter as well.

You could overwrite the paths in post_process_command. If everything works, we can add an option to specify the base path when configuring the adapter. Besides that, the formatter receives an env var with the path where it's going to write the output files. When running inside a container, those files would be in the container, so they would need to be mounted as well so that the Neovim side can read them.

jfpedroza avatar Jun 17 '24 20:06 jfpedroza