Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignoring dist/ direcory #98

Open
lukesarnacki opened this issue Jan 28, 2024 · 3 comments
Open

Ignoring dist/ direcory #98

lukesarnacki opened this issue Jan 28, 2024 · 3 comments

Comments

@lukesarnacki
Copy link

lukesarnacki commented Jan 28, 2024

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!

@brenoepics
Copy link

something like modulePathIgnorePatterns: ['dist'],

@lukesarnacki
Copy link
Author

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
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants