Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/artemave/vigun
Unclutter your test diet
https://github.com/artemave/vigun
electron-mocha mocha testing vim vim-plugin
Last synced: 20 days ago
JSON representation
Unclutter your test diet
- Host: GitHub
- URL: https://github.com/artemave/vigun
- Owner: artemave
- License: mit
- Created: 2016-12-15T21:54:45.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2024-03-09T14:37:03.000Z (10 months ago)
- Last Synced: 2024-10-30T14:24:56.327Z (2 months ago)
- Topics: electron-mocha, mocha, testing, vim, vim-plugin
- Language: Vim Script
- Size: 108 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# vigun [![CircleCI](https://circleci.com/gh/artemave/vigun.svg?style=svg)](https://circleci.com/gh/artemave/vigun)
Unclutter your test diet.## What is this?
Vim plugin to run tests in a separate tmux window.
Out of the box it works with mocha, rspec and cucumber. Other test frameworks can be supported through some configuration.
## Installation
Use [a plugin manager](https://github.com/junegunn/vim-plug):
```vim script
Plug 'artemave/vigun'
```## Usage
Vigun comes with no mappings, but it does add the following commands:
#### VigunRun
Run test(s). Requires an argument that refers to one of the commands from [g:vigun_mappings](#gvigun_mappings).
For example, with default mappings, for mocha:
`:VigunRun 'all'` runs all tests in a current file.
`:VigunRun 'nearest'` runs test under cursor.
`:VigunRun 'debug-nearest'` starts debug session for test under cursor. By default, for mocha, this will use `--inspect-brk` and copy the debug url into OS clipboard. Open new Chrome window/tab and paste it into the address bar.
If invoked from a non-test file, `VigunRun` (with any argument) will attempt to run the last command.
#### VigunToggleTestWindowToPane
Move tmux test window into a pane of the current vim window. And vice versa.
#### VigunShowSpecIndex
Open quickfix window to quickly navigate between the tests.
#### VigunCurrentTestBefore
Fold everything, except current test and all relevant setup code (e.g. before/beforeEach blocks).
#### VigunToggleOnly
Toggle `.only` for a current test/context/describe.
### Example bindings
```vim script
au FileType {ruby,javascript,typescript,cucumber} nnoremap t :VigunRun 'all'
au FileType {ruby,javascript,typescript,cucumber} nnoremap T :VigunRun 'nearest'
au FileType {ruby,javascript,typescript,cucumber} nnoremap d :VigunRun 'debug-nearest'
au FileType {javascript,typescript} nnoremap vo :VigunToggleOnly
au FileType {ruby,javascript,typescript,go} nnoremap vi :VigunShowSpecIndex
```## Configuration
### g:vigun_mappings
Out of the box, vigun runs mocha, rspec and cucumber. You can add support for new frameworks or modify the default ones:
```vim script
let g:vigun_mappings = [
\ {
\ 'pattern': 'Spec.js$',
\ 'all': './node_modules/.bin/mocha #{file}',
\ 'nearest': './node_modules/.bin/mocha --fgrep #{nearest_test} #{file}',
\ 'debug-all': './node_modules/.bin/mocha --inspect-brk --no-timeouts #{file}',
\ 'debug-nearest': './node_modules/.bin/mocha --inspect-brk --no-timeouts --fgrep #{nearest_test} #{file}',
\ },
\ {
\ 'pattern': '_spec.rb$',
\ 'all': 'rspec #{file}',
\ 'nearest': 'rspec #{file}:#{line}',
\ },
\ {
\ 'pattern': '.feature$',
\ 'all': 'cucumber #{file}',
\ 'nearest': 'cucumber #{file}:#{line}',
\ },
\]
```Each mapping has a `pattern` property that will be tested against the current file name. Note that `pattern` is a regular expression, not a glob. Also note that the match order matters - the block with the first matched `pattern` is selected to run tests.
All other properties represent various ways to run tests. All occurances of `#{file}`, `#{line}` and `#{nearest_test}` in the property value are interpolated based on the current cursor position. You can name the properties whatever you like and then invoke commands via `VigunRun 'your-key'`. For example, let's add watch commands:
```vim script
" Note: requires ripgrep and entr
fun! s:watch(cmd)
return "rg --files | entr -r -d -c sh -c 'echo ".escape('"'.a:cmd.'"', '"')." && ".a:cmd."'"
endflet g:vigun_mappings = [
\ {
\ 'pattern': '_spec.rb$',
\ 'all': 'rspec #{file}',
\ 'nearest': 'rspec #{file}:#{line}',
\ 'watch-all': s:watch('rspec #{file}'),
\ 'watch-nearest': s:watch('rspec #{file}:#{line}'),
\ },
\]au FileType {ruby} nnoremap wt :VigunRun 'watch-all'
au FileType {ruby} nnoremap wT :VigunRun 'watch-nearest'
```#### Magic property names
Mapping property names are arbitrary. However, there is one name based vigun feature that applies to Mocha (or anything else that makes use of `.only`). If vigun detects that there is `.only` test in the current file, it uses `*all` command instead of `*nearest` (e.g., `VigunRun 'debug-nearest'` will run `debug-all` command instead). This is because mocha applies both `.only` and `--fgrep` and the result is likely to be empty.
### g:vigun_test_keywords
A line that starts with one of the following, is considered a start of the test and is used to work out `#{nearest_test}`:
```vim script
let g:vigun_test_keywords = ['[Ii]ts\?', '[Cc]ontext', '[Dd]escribe', 'xit', '[Ff]eature', '[Ss]cenario', 'test']
```Overwrie `g:vigun_test_keywords` to suit your needs.
### g:vigun_tmux_window_name
Name of the tmux window where tests commands are sent. Defaults to `test`.
### g:vigun_tmux_pane_orientation
Be default, `VigunToggleTestWindowToPane` moves test window in a vertical split to the right of the vim pane. Setting `g:vigun_tmux_pane_orientation = 'horizontal'` will change this to horizontal split at the bottom.
## Running Plugin Tests
```
./run_tests
```