nvim-neotest / neotest-jest

MIT License
124 stars 80 forks source link

Ignoring dist/ direcory #98

Open lukesarnacki opened 10 months ago

lukesarnacki commented 10 months ago

Thanks for creating this plugin, it is awesome!

I have an issue with a typescript project with the dist directory. While it is ignored in the jest.config.js, neotest considers it when detecting tests. This results in the error below. This doesn't happen when I delete the dist/ directory.

...Error in remote call ...0.9.5/share/nvim/runtime/lua/vim/treesitter/language.lua:87: '' is not a valid language name
stack traceback:
    [C]: in function 'error'

...0.9.5/share/nvim/runtime/lua/vim/treesitter/language.lua:87: in function 'add'
    ...5/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:98: in function 'get_string_parser'
    ...re/nvim/lazy/neotest/lua/neotest/lib/treesitter/init.lua:119: in function 'get_parse_root'
    ...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:207: in function 'func'
    ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:153: in function <...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:152>
...

This results in a weird behaviour. There is "no tests found" message but neotest sees tests as long as you open a file through a test summary window.

It would be great if either:

Let me know which approach would be better, I am happy to open a PR, thanks!

brenoepics commented 8 months ago

something like modulePathIgnorePatterns: ['dist'],

lukesarnacki commented 8 months ago

I don't have a ton of experience with jest so maybe I am missing something but I think that there is an even easier way of doing this. The jest command has the --listTests option which should be enough to determine available tests without any custom code. The big advantage is that it uses jest config out of the box so the result will always match the tests that are actually run for the whole project. Was there a specific reason why it hasn't been used?

MisanthropicBit commented 4 months ago

I can't explain why you get treesitter errors for a dist directory. That looks more like the errors you would get for outdated treesitter parsers.

Have you tried neotest's filter_dir option (:h neotest.Config.discovery)? I use it for this exact purpose which also speeds up test discovery quite a bit for larger repos.

neotest.setup({
    discovery = {
        filter_dir = function(name, rel_path, root)
            return name ~= "dist"
        end,
    },
})

I think is_test_file is not based on jest.config.js currently.

It isn't no but it shouldn't match any files in dist unless you are bundling tests.