vim-test
vim-test copied to clipboard
Feature Request: Allow ENV vars to be passed correctly
Love vim-test, thanks @janko-m.
In regards to #19 I have a use case that is more general.
Our tests are setup to use headless Chrome. However, I am finding that if I want to run an individual test :TestNearest
that usually means that I want to run it with GUI Chrome.
I can control this with an environment variable.
I have gotten around it at the moment by running a script to switch the HEADLESS
flag before it runs :TestNearest
and switching it back. It would be nice to be able to pass it along through :TestNearest
.
I barely know any Vimscript so I have included my cobbled together script for anyone who needs it in case you decided that this will never be supported.
function! RunNearestTestWithGUIChrome()
let oldHeadless = $HEADLESS
let $HEADLESS = 'false'
TestNearest
let $HEADLESS = oldHeadless
endfunction
nmap <silent> <leader>R :call RunNearestTestWithGUIChrome()<CR>
It's possible that transformations might achieve want you want https://github.com/janko-m/vim-test#transformations
I'm open to having a variable when you can specify the environment variables:
let test#{language}#{runner}#environment = {"HEADLESS": "false"}
" or
let test#{language}#{runner}#environment = {
\ "nearest": {
\ "HEADLESS": "false" " sets HEADLESS=false only when running nearest tests
\ }
\}
And possibly to even allow you to set the environment variables on-the-fly:
:TestNearest -env HEADLESS=false
@codeinabox While transformations could work, I feel like they are a bit of an overkill. The're also not dynamic enough, it seems that @aldhsu would like to include it only for nearest tests, and in transformations it's not easy to determine whether a nearest test was run. What do you think about the above proposal?
@codeinabox I had a look at transformations as @janko-m it isn't possible to tell what context how you are calling vim-test whether through :TestNearest
, :TestFile
, :TestLast
.
Thinking about it some more I think I am happy with my solution. This allows me to switch the environment locally for certain tests and I can bind them separately. For example I could have a keybind for running tests with GUI Chrome or setting timezone ENV.
@janko-m the only solution you have proposed that would satisfy this is:
:TestNearest -env HEADLESS=false
While the other solutions would modify all nearest tests.
I am happy to close this issue if there is no burning desire for it.
I think this feature would be useful, so I would like that we implement it.
This still affects me - would be nice to close this ticket.
I will use @aldhsu 's code in the meantime, thanks!
I would like it as well, I'll see if I find time to add it.
In the end I decided for the TestNearest HEADLESS=false
syntax, without the -env
, as that was simpler to implement. The environment variables are automatically extracted from the arguments based on the <VARIABLE>=<value>
syntax.