-
Notifications
You must be signed in to change notification settings - Fork 386
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
Package.json detection fails if the package.json is not in the root #272
Comments
I guess it could be possible to have an option to manually override the path it checks for package.json but in this case are you staying there are multiple ones, and I am guessing each of them might have a different test runner? I need to check with @janko-m but I believe the scope of this plugin is just for it running in the root directory of a single project |
I'm not sure I understand yet what exactly vim-test needs to do here, but if any feature request that would otherwise require overriding the If this use case is too specific, it might also be worthwhile to add some Vim auto-commands to allow people to change some things dynamically. |
@codeinabox The way |
Yes but there will be package.json in people's vendor directories |
@codeinabox But that is not in the path to the file, is it? It's normally in a |
Now I am working on a project with mono repo I can see the problem but I don't see this a problem specifically with vim-test but any plugin that assumes the current working directory is the project directory. Keen to find a solution but ideally one that works across multiple plugins and not just vim-test. |
@codeinabox Given this project already uses projectionist, maybe it should use the result of the function call |
Interesting, so projectionist let's you define multiple projects and |
Yes, exactly! |
@janko do think using |
So, this will only work if the user is using projectionist.vim and has it configured? I'm ok with that. If the user doesn't use projectionist.vim, we can just fall back to the current behaviour. |
@entropitor what does your |
I just have one in every "subrepo" of the monorepo, it's a standard one, nothing special. And I do believe it makes a lot of sense to use that path over the current dir if the user is using projectionist and there is a file for the current project |
I do like this idea and I'm keen to help out implementing projectionist support though I won't have the chance to do so till mid August. Feel free to raise a PR in the interim |
Do you have any pointers on how to start on this? |
I commented on #372 but I think it makes more sense to discuss the problem here (maybe even close the other issue?) Here's my idea not requiring projectionist but just recursively searching for the
|
I'm working on this a little bit in https://github.com/JoosepAlviste/vim-test/tree/non-root-package-json but there's a small problem with the solution. Detecting the correct For my example above:
I have two ideas on how to solve this (neither seems "good enough" though):
What do you think is a reasonable solution here? This is probably also relevant for the other Javascript test runners so it would be nice to have a generic solution. I guess the most reasonable option is to always
|
@JoosepAlviste are you using projectionist too? I found for me working with mono repos the simplest solution is have each sub project in a tab and in Neovim using |
Just wanted to note that regardless of projectionist, we should still have an implementation that doesn’t rely on it. |
I recently started using projectionist but I've only used the alternative files feature and haven't done much with I've also tried to just manually let g:root_markers = ['package.json', '.git/']
function! s:RunVimTest(cmd)
" I guess this part could be replaced by projectionist#project_root
for marker in g:root_markers
let marker_file = findfile(marker, expand('%:p:h') . ';')
if strlen(marker_file) > 0
let g:test#project_root = fnamemodify(marker_file, ":p:h")
break
endif
let marker_dir = finddir(marker, expand('%:p:h') . ';')
if strlen(marker_dir) > 0
let g:test#project_root = fnamemodify(marker_dir, ":p:h")
break
endif
endfor
execute a:cmd
endfunction
nnoremap <leader>tf :call <SID>RunVimTest('TestFile')<cr>
nnoremap <leader>tn :call <SID>RunVimTest('TestNearest')<cr>
nnoremap <leader>tf :call <SID>RunVimTest('TestSuite')<cr>
nnoremap <leader>ts :call <SID>RunVimTest('TestFile')<cr>
nnoremap <leader>tl :call <SID>RunVimTest('TestLast')<cr>
nnoremap <leader>tv :call <SID>RunVimTest('TestVisit')<cr> |
Keen to revisit and solve this issue, it would be quite easy add some unit tests around it because we just need a scenario when you are one directory below. A couple of questions though:
|
I've been thinking about this and now feel that handling mono repositories is perhaps beyond the scope of this plug-in and actually warrants its own plug-in for the following reasons:
What are your thoughts @janko and @willfish? I stumbled upon vim-rooter which could perhaps be configured to automatically changed working directories when working on a mono repo |
I've very naively added the snippet above shared by @JoosepAlviste to the https://github.com/fnune/vim-test/blob/master/autoload/test.vim#L161-L177 |
Thanks @fnune + @JoosepAlviste. That solution worked for me as well 👍 |
Finally got around to updating @JoosepAlviste's solution for my nvim config. Here's my updated lua config using -- Find project root using root markers
local root_markers = {'Gemfile', 'package.json', '.git/'}
function _G.RunVimTest(cmd_name)
return function()
for _, marker in ipairs(root_markers) do
local marker_file = vim.fn.findfile(marker, vim.fn.expand('%:p:h') .. ';')
if #marker_file > 0 then
vim.g['test#project_root'] = vim.fn.fnamemodify(marker_file, ":p:h")
break
end
local marker_dir = vim.fn.finddir(marker, vim.fn.expand('%:p:h') .. ';')
if #marker_dir > 0 then
vim.g['test#project_root'] = vim.fn.fnamemodify(marker_dir, ":p:h")
break
end
end
vim.cmd(':' .. cmd_name)
end
end
return {
'vim-test/vim-test',
dependencies = { { 'kassio/neoterm' } },
config = function()
vim.g['test#strategy'] = 'neoterm'
vim.g['test#neoterm#term_position'] = 'vert'
vim.g['test#preserve_screen'] = 1
vim.g['test#javascript#runner'] = 'vitest'
vim.g.neoterm_shell = 'zsh'
vim.g.neoterm_automap_keys = ''
vim.g.neoterm_default_mod = 'vertical'
end,
keys = {
{ '<leader>rn', RunVimTest('TestNearest'), desc = "Run nearest test" },
{ '<leader>rt', RunVimTest('TestSuite'), desc = "Run the nearest test suite" },
{ '<leader>rf', RunVimTest('TestFile'), desc = "Run all tests in the current file" },
{ '<leader>rr', RunVimTest('TestLast'), desc = "Run last test again" }
}
} |
E.g. I'm working in a mono-repo with multiple package.json's in my repository, vim-test cannot find the other ones.
vim-lsp
for examples can cope with this using some helper functions\ 'root_uri':{server_info->lsp#utils#path_to_uri(lsp#utils#find_nearest_parent_file_directory(lsp#utils#get_buffer_path(), '.flowconfig'))},
It would be nice if we could also configure this for vim-test
The text was updated successfully, but these errors were encountered: