klen / nvim-test Goto Github PK
View Code? Open in Web Editor NEWA Neovim wrapper for running tests
License: MIT License
A Neovim wrapper for running tests
License: MIT License
this excellent repo
needs some gifs
to be perfect
Thanks, plugin works nice on my setup (using it for Ruby/rspec).
I have a feature request: I assumed the option termOpts < go_back
would let me focus back my previous window immediately. Unfortunately the focus changes only after the test run is finished.
An option go_back_immediately
(overriding go_back
) would be great.
Currently my workaround is this
map <Leader>T :TestFile<CR><c-w><c-p>
(execute TestFile and WindowPrevious).
Some test runners can take configuration via environment variables as well. For example, vusted
can take VUSTED_NVIM
and VUSTED_ARGS
.
We can pass those variables in the cmd
field like so:
{ cmd = "VUSTED_ARGS='--headless --clean' vusted" }
But I think it would be better to provide native support like so:
{
env = {
VUSTED_ARGS = '--headless --clean',
},
cmd = 'vusted',
}
Internally, the env
field will be converted to key=value
string pairs and prefixed to the cmd
field.
This is just a thought, it's ok if rejected :)
I've created some custom configuration to create a coverage file.
local nvimtest = require('nvim-test')
require('nvim-test.runners.go-test'):setup {
args = { "test", "-v", "-cover", "-coverprofile", "coverage.out" },
}
nvimtest.setup()
And I can see that the configuration works:
But no coverage.out
file gets created.
When I run it myself, it works fine.
go test -cover -coverprofile=coverage.out ./...
If I change the args to be nonsensical...
And run the test, well... it still works!
It looks like the args are completely ignored.
I have no idea how to view the command that was actually executed.
I've configured Rspec like this (which should probably be the default):
require('nvim-test.runners.rspec'):setup({
command = "bundle",
args = { "exec", "rspec" },
})
This works perfectly when I open neovim in the directory containing the Gemfile
. However, this doesn't work when I'm working on a project with multiple roots:
project/
a/
Gemfile
spec/a_spec.rb
b/
Gemfile
spec/b_spec.rb
If I'm editing a_spec.rb
, I'd want to execute bundle exec spec/a_spec.rb
with { cwd = "a" }
.
I propose the introduction of runner:find_working_directory(filename)
to dynamically infer the working directory. In the case of RSpec, that implementation might look something like this (adapted from here):
function rspec:find_working_directory(filename)
local gemfile = vim.fn.findfile("Gemfile", vim.fn.fnamemodify(filename, ":p") .. ";")
return vim.fn.fnamemodify(gemfile, ":p:h:t")
end
Firstly, thank you for doing a great plugin for testing based on 100% Lua.
It would be nice if you can add more languages like vim-test does, especially for Dart/Flutter.
Thanks again!
If I'm not mistaken, it's impossible to have both the package: true
option and use an args
list that contains --
I think this is because the package
args are injected after the args
I'm willing to do a proposed implementation as part of #23 if you want
Hi,
the one thing I am really missing at the moment, is to pass arguments to the test command on the fly.
Using pytest
for example, every now and then it is really helpful to get more verbose output via -vvv
or to drop into the debugger if a test fails with --pdb
Ideally one could append these extra flags to the test command, like: TestNearest -vvv --pdb
Is this already doable and I missed how to do it? Otherwise this would be a really helpful feature.
Thanks,
Andreas
The latest version of neovim is throwing the following deprecation warning.
Warn 10:55:20 notify.warn vim.treesitter.query.set_query() is deprecated, use vim.treesitter.query.set() instead. :help deprecated
This feature will be removed in Nvim version 0.10
Example prefix is not a right prefix for Tests see https://pkg.go.dev/cmd/go#hdr-Testing_functions
It is only a Example function to be tested, as described there. We could add "Benchmark" and "Fuzz" prefixes to be complete here
Originally posted by @616b2f in #12 (comment)
hello ๐
according to the jest docs the command to test ECMA scripts is the following
node --experimental-vm-modules node_modules/jest/bin/jest.js
is there a way to model this with the plugin?? I can't implement the jest runner
Hi,
First of all, awesome lib! :)
It would be nice to have the possibility to define the command at runtime that should be used to run the tests. This is useful for local binaries. For example, when using poetry, to run pytest
I either have to run poetry run pytest
or call it directly from the venv's bin (which is not activated). I solved that locally by doing:
local pytest = require("nvim-test.runners.pytest")
function pytest:build_cmd(filename, opts)
local cmd
if vim.env.VIRTUAL_ENV then
cmd = vim.env.VIRTUAL_ENV .. "bin/pytest"
else
cmd = require("utils").find_cmd("pytest", ".venv/bin", filename)
end
return ("%s%s"):format(cmd, pytest:build_args(filename, opts or {}))
end
But it would be nice to have a proper config for it. (obs. that find_cmd is this function: https://github.com/bellini666/dotfiles/blob/master/vim/lua/utils.lua#L186)
Also, I work with monorepos and because of that the config for pytest is inside a subdirectory of where my cwd is. To properly run pytest, I need to "cd" to the subdirectory before running it.
It would be nice to have an option to pass a function similar to the above, that returns a directory that will be used to run the command from.
Both could also be the same function, that could return a table with both options (the ones not set would fallback to the default ones)
As we already discussed here #12 (comment) "TestFile" does not work for csharp and go tests.
Did you have already some ideas how we could refactor to support that feature for those languages?
If not and you don't mind I could create a PR with a suggestion.
What do you think?
Hey,
thanks for this handy plugin!
I noticed if I run a test (e.g. via TestNearest
), change the test and run it again the new test session starts in a new, additional split window/terminal.
I think it would be cool if the existing terminal could be reused. Is this already possible? If not, I think it would be a nice addition.
Thanks,
Andreas
Hello,
I'm having a bit of a problem when trying to use rspec runner.
I've noticed that your default setup is to just execute rspec
.
Although this causes some problems when the project gem versions are not the same, for instance:
Gem::LoadError:
You have already activated rspec-support 3.12.0, but your Gemfile requires rspec-support 3.11.1.
Prepending `bundle exec` to your command may solve this
So I decided to look at replacing the command configuration to command = { "bundle exec rspec"}
But this caused another error when attempting to use :TestFile
E5108: Error executing lua Vim:E475: Invalid value for argument cmd: 'bundle exec rspec' is not executable
stack traceback:
[C]: in function 'exec'
.../packer/start/nvim-test/lua/nvim-test/terms/terminal.lua:54: in function 'run'
[string ":lua"]:1: in main chunk
local status_ok, nvim_test = pcall(require, "nvim-test")
if not status_ok then
return
end
nvim_test.setup({
run = true, -- run tests (using for debug)
commands_create = true, -- create commands (TestFile, TestLast, ...)
filename_modifier = ":.", -- modify filenames before tests run(:h filename-modifiers)
silent = false, -- less notifications
term = "terminal", -- a terminal to run ("terminal"|"toggleterm")
termOpts = {
direction = "vertical", -- terminal's direction ("horizontal"|"vertical"|"float")
width = 96, -- terminal's width (for vertical|float)
height = 24, -- terminal's height (for horizontal|float)
go_back = false, -- return focus to original window after executing
stopinsert = "auto", -- exit from insert mode (true|false|"auto")
keep_one = true, -- keep only one terminal for testing
},
runners = { -- setup tests runners
ruby = "nvim-test.runners.rspec",
}
})
local rspec_runner = require("nvim-test.runners.rspec")
rspec_runner:setup({
command = { "bundle exec rspec" }
})
Would it be possible to have bundle exec rspec
whenever there's a Gemfile
present?
With the default setup, how can i stop running tests (i.e. if my tests a really long-running)?
Is closing the buffer enough? (not obvious).
The buffer does not seem to accept signals.
Calling :terminal
during test run shows and empty terminal.
as the title suggests, I am hoping to have support for php as well. I am sure this would many users want as feature.
I will try to raise PR for this, if @klen says okay to it.
For instance if I'm in file foo.py
, I'd like to run :TestOpenFile<cr>
to open foo_test.py
if it exists.
Or if I run :TestFile
from foo.py
, it should look for the corresponding foo_test.py
file and run the tests.
I'm happy to pick up the work for this if there's interest.
Thank you for a great project!
I've been eager to replace vim-test with a Lua-based alternative, and this one seems to do more or less exactly what I need. However, I am missing support for RSpec and Hspec among others.
What would it take for me (or somebody else) to add support for more languages? Where does one start?
Hey there,
I'm using this plugin and its working great for me so far. There is something I'd like to customize but I haven't found a way to do it yet.
TestSuite runs a full set of tests. However - I want a way to just run a subset of tests. EG:
cargo test --lib --bins
Without running ALL the tests. What is the recommended way to achieve this?
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.