Open jrock2004 opened 1 year ago
Although not exactly what you are looking for, but you could use ni to automatically use the correct package manager.
For example running ‘nr test —‘ will run your test regardless of your package manager.
Although not exactly what you are looking for, but you could use ni to automatically use the correct package manager.
For example running ‘nr test —‘ will run your test regardless of your package manager.
Thanks, but was hoping to not have another toolchain. I might go with this but hoping for another solution
Does option with nr work for you? In my case tests are passing, but neotest still show that test failed:
I didn't add any fancy settings and everything works with jestCommand = "npm test --"
:
{
jestCommand = "nr test --",
jestConfigFile = function()
local file = vim.fn.expand("%:p")
if string.find(file, "/packages/") then
return string.match(file, "(.-/[^/]+/)src")
.. "jest.config.ts"
end
return vim.fn.getcwd() .. "/jest.config.ts"
end,
env = { CI = true },
cwd = function(path)
return vim.fn.getcwd()
end,
}
Not sure if this is still relevant but the jestCommand
option can also take a function accepting a single argument (the path of the current test). So you could do:
jestCommand = function(path)
local cwd = vim.fn.getcwd()
if vim.endswith(cwd, 'my-special-project') then
return "yarn test"
end
return "npm test"
end
You might also be able to adapt some of the code for hasJestDependency
or some of the util
functions to locate the package.json
file, or similar, and grab the test command directly.
@MisanthropicBit interesting. Maybe I could check for lock file.
Not an issue per-say but wondering how people configure their jest command when you have projects that use npm, some that use yarn, etc... Do you change your config? Or is there a dynamic way?
Update 1:
I think when I made this ticket, I was bad in not adding a thought on a solution. What if we do something like not pass
jestCommand
and have another property that is something like:With this, what the plugin can do is check in the root dir of project, is there a package-lock, or yarn.lock, or pnpm-lock? Then it could build the
jestCommand
from that