adrigzr / neotest-mocha

Neotest runner for Mocha test framework
9 stars 9 forks source link

Limit neotest-mocha to .js or .ts only? #7

Closed fredrikaverpil closed 1 year ago

fredrikaverpil commented 1 year ago

Hi!

I've got a project with both Python files and Javascript files, and neotest-mocha attempts to run the Python tests. My neotest summary looks like this, although I only have python files in the tests folder:

neotest-mocha
├─  htmlcov
╰─  tests

neotest-python
╰─  tests

Would it be possible to configure neotest-mocha so it only detects tests of a certain filetype or language?

This is my neotest config (dotfiles link here for the most up to date code):

-- lazy.nvim

return {
{
    "nvim-neotest/neotest",
    dependencies = {
      { "nvim-lua/plenary.nvim" },
      { "nvim-treesitter/nvim-treesitter" },
      { "antoinemadec/FixCursorHold.nvim" },

      -- adapters
      { "nvim-neotest/neotest-python" },
      { "rouge8/neotest-rust" },
      { "adrigzr/neotest-mocha" },
    },

    config = function()
      -- Setup neotest adapter for python
      require("neotest").setup({
        adapters = {
          require("neotest-python")({
            runner = "pytest",
            args = { "--log-level", "DEBUG", "--color", "yes" },
          }),

          require("neotest-rust")({
            -- requires nextest, which can be installed via "cargo binstall:
            -- https://github.com/cargo-bins/cargo-binstall
            -- https://nexte.st/book/pre-built-binaries.html
            args = { "--no-capture" },
          }),

          -- https://github.com/adrigzr/neotest-mocha
          require("neotest-mocha")({
            command = "npm test --",
            env = { CI = true },
            cwd = function(path)
              return vim.fn.getcwd()
            end,
          }),
        },
      })
    end,
  },
}

Side-note: I also added a discussion thread on this topic over at neotest: https://github.com/nvim-neotest/neotest/discussions/256

adrigzr commented 1 year ago

Hi @fredrikaverpil, it should only be using the following extensions: "js", "mjs", "cjs", "jsx", "coffee", "ts", "tsx".

fredrikaverpil commented 1 year ago

@adrigzr It looks like the adapter matches any file with test in the name https://github.com/adrigzr/neotest-mocha/blob/c22fc33015c4de4788b4a9394aeed6d7f4f1e949/lua/neotest-mocha/util.lua#L351-L353

I haven't gotten around trying to comment this part of the code out yet - but what's it for?

fredrikaverpil commented 1 year ago

I just commented out that code and I no longer experience the original issue. I'll open up a PR if you don't mind?

fredrikaverpil commented 1 year ago

Credit need to go to @rcarriga who found the issue! 😊