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

Ignoring dist/ direcory

Open lukesarnacki opened this issue 1 year ago • 3 comments

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:

  • there was an option to ignore certain directory;
  • the jest.config.js was taken into consideration as there is testPathIgnorePatterns attribute which already covers this; correct me if I am wrong: I think is_test_file is not based on jest.config.js currently.

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

lukesarnacki avatar Jan 28 '24 15:01 lukesarnacki

something like modulePathIgnorePatterns: ['dist'],

brenoepics avatar Mar 01 '24 12:03 brenoepics

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?

lukesarnacki avatar Mar 06 '24 09:03 lukesarnacki

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.

MisanthropicBit avatar Jul 26 '24 19:07 MisanthropicBit