Giter Club home page Giter Club logo

vim-test's Introduction

test.vim

A Vim wrapper for running tests on different granularities.

usage overview

Currently the following testing frameworks are supported:

Language Frameworks
Ruby RSpec, Minitest, Cucumber
JavaScript Mocha, Jasmine
Python Nose, PyTest
Elixir ExUnit
Go Go
Clojure Fireplace.vim
Shell Bats
VimScript VSpec, Vader.vim
Lua Busted
PHP PHPUnit, Behat

Idea

Since Gary Bernhardt invented testing from Vim, there have been multiple plugins implementing this functionality (rspec.vim, vroom.vim etc). However, all of these solutions have bad designs, unclear ideas and aren't extendable. So I decided to create test.vim, featuring:

  • zero dependencies
  • zero configuration required (it Does the Right Thing™, see Philosophy)
  • inteface for adding new testing frameworks
  • automatic detection of correct test runner
  • polyfill for nearest tests (by constructing regexes)
  • built-in integration with Dispatch/Vimux/Tslime
  • fully customized CLI options configuration

Internally test.vim consists of a thoughtfully designed core, and testing frameworks are simply plugged in, so that they all work in the same unified way.

Ruby users, you get all of the features of rspec.vim + vroom.vim, but without any of the tedious configuration (test.vim knows how you want to run your test command).

Setup

Plug[in] 'janko-m/vim-test'

Add your preferred mappings to your .vimrc file:

nmap <silent> <leader>t :TestNearest<CR>
nmap <silent> <leader>T :TestFile<CR>
nmap <silent> <leader>a :TestSuite<CR>
nmap <silent> <leader>l :TestLast<CR>
nmap <silent> <leader>g :TestVisit<CR>
Command Description
:TestNearest In a test file runs the test nearest to the cursor, otherwise runs the last nearest test. In test frameworks that don't support line numbers it will polyfill this functionality with regexes.
:TestFile In a test file runs all tests in the current file, otherwise runs the last file tests.
:TestSuite Runs the whole test suite (if the current file is a test file, runs that framework's test suite, otherwise determines the test framework from the last run test).
:TestLast Runs the last test.
:TestVisit Visits the test file from which you last run your tests (useful when you're trying to make a test pass, and you dive deep into application code and close your test buffer to make more space, and once you've made it pass you want to go back to the test file to write more tests).

Strategies

You can instruct test.vim to run your tests with different strategies (with synchronous or asynchronous execution). To use a specific strategy, assign it like this:

" make test commands execute using dispatch.vim
let test#strategy = "dispatch"
Strategy Identifier Description
Basic (default) basic Runs test commands with :!, which switches your Vim to the terminal.
Neovim neovim Runs test commands with :terminal, which spawns a terminal inside your Neovim.
Neoterm neoterm Runs test commands with :T, see neoterm docs for display customization.
Dispatch.vim dispatch Runs test commands with :Dispatch.
Vimux vimux Runs test commands in a small tmux pane at the bottom of your terminal.
Tslime.vim tslime Runs test commands in a tmux pane you specify.
Vim Tmux Runner vtr Runs test commands in a small tmux pane.
Terminal.app terminal Sends test commands to Terminal.app (useful in MacVim GUI).
iTerm.app iterm Sends test commands to iTerm.app (useful in MacVim GUI).

Commands

nearest polyfill

You can execute Test.vim commands directly, and pass them CLI options:

:TestNearest --verbose
:TestFile --format documentation
:TestSuite --fail-fast

If you want some options to stick around, see Configuring.

Runner commands

Aside from the main commands, you get a corresponding Vim command for each test runner (which also accept options):

:RSpec --tag ~slow
:Mocha --grep 'API'
:ExUnit --trace
:Nose --failed

I found these commands to be really useful when using multiple testing frameworks in the same project.

Configuring

CLI options

If you want some CLI options to stick around, you can configure them in your .vimrc:

let test#ruby#minitest#options = '--verbose'

You can also choose a more granular approach:

let test#ruby#rspec#options = {
  \ 'nearest': '--backtrace',
  \ 'file':    '--format documentation',
  \ 'suite':   '--tag ~slow',
\}

Executable

You can instruct test.vim to use a custom executable for a test runner.

let test#ruby#rspec#executable = 'foreman run rspec'

File pattern

Test.vim has file pattern it uses to determine whether a file belongs to certain testing framework. You can override that pattern by overriding the file_pattern variable:

let test#ruby#minitest#file_pattern = '_spec\.rb' " the default is '_test\.rb'

Language-specific

Python

Since there are multiple Python test runners for the same type of tests, test.vim has no way of detecting which one did you intend to use. By default the first available will be chosen, but you can force a specific one:

let test#python#runner = 'pytest'
" or
let test#python#runner = 'nose'

Extending

See CONTRIBUTING.md for information on extending test.vim.

Credits

This plugin was strongly influenced by Gary Bernhardt's Destroy All Software. I also want to thank rspec.vim, from which I borrowed GUI support for OS X, and Windows support. And also thanks to vroom.vim.

License

Copyright © Janko Marohnić. Distributed under the same terms as Vim itself. See :help license.

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.