Giter VIP home page Giter VIP logo

vigun's Introduction

vigun CircleCI

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:

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.

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

au FileType {ruby,javascript,typescript,cucumber} nnoremap <leader>t :VigunRun 'all'<cr>
au FileType {ruby,javascript,typescript,cucumber} nnoremap <leader>T :VigunRun 'nearest'<cr>
au FileType {ruby,javascript,typescript,cucumber} nnoremap <leader>d :VigunRun 'debug-nearest'<cr>
au FileType {javascript,typescript} nnoremap <Leader>vo :VigunToggleOnly<cr>
au FileType {ruby,javascript,typescript,go} nnoremap <leader>vi :VigunShowSpecIndex<cr>

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:

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:

" Note: requires ripgrep and entr
fun! s:watch(cmd)
  return "rg --files | entr -r -d -c sh -c 'echo ".escape('"'.a:cmd.'"', '"')." && ".a:cmd."'"
endf

let 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 <leader>wt :VigunRun 'watch-all'<cr>
au FileType {ruby} nnoremap <leader>wT :VigunRun 'watch-nearest'<cr>

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}:

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

vigun's People

Contributors

artemave avatar

Stargazers

 avatar

Watchers

 avatar  avatar

vigun's Issues

Regexp like test title breaks things

Invalid regular expression: /inserts a "**strong text**"/: Nothing to repeat
SyntaxError: Invalid regular expression: /inserts a "**strong text**"/: Nothing to repeat
    at RegExp (<anonymous>)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.