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

vim-test/neotest-vim-test : test#project_root is not changing Working Directory (monorepo) #359

Open
ls-devs opened this issue Feb 2, 2024 · 1 comment

Comments

@ls-devs
Copy link

ls-devs commented Feb 2, 2024

Hi,
Actually working in a monorepo, I have tests in my_project/frontend/tests.
If I cd into my_project/frontend tests are found and neotest is working perfectly.
But If I only cd into the root directory of my project, test are not found.

I saw this on vim-test documentation :

Working directory

Test.vim relies on you being cd-ed into the project root. However, sometimes you may want to execute tests from a different directory than Vim's current working directory. You might have a bigger project or monorepo with many subprojects, or you might be using autochdir. In any case, you can tell test.vim to use a different working directory for running tests:

let test#project_root = "/path/to/your/project"

Unfortunately, if I set test#project_root to my_project/frontent or my_project/frontend/tests and only cd into the root directory of my project ( my_project/). Tests aren't found.

How can I make vim-test / neotest-vim-test found my tests folder without always cd in the direct parent folder of my tests ? (here my_project/frontend)

EDIT : Found a workaround using

vim.cmd("cd ./frontend")

But shouldn't let test#project_root = "/path/to/your/project" do the job ?

@juansalvatore
Copy link

juansalvatore commented Apr 25, 2024

@ls-devs hey! I was having the same issue and just found a work around that worked for me, hopefully it works for you too.

        ['neotest-vitest'] = {
          vitestCommand = 'npx vitest run',
          vitestConfigFile = function(file)
            if string.find(file, '/packages/') then
              return string.match(file, '(.-/[^/]+/)src') .. 'vitest.config.ts'
            end

            return vim.fn.getcwd() .. '/vitest.config.ts'
          end,
        },

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

2 participants