vim mocha only: A simple Vim plugin for Mocha users
I’ve been using Vim for almost exactly a year now and I’m still a new enough user that I’m constantly annoying people by talking about it. What an amazing tool! I only wish I’d discovered it earlier.
A lot of the power of Vim comes from plugins. There are plugins or even just vimscript snippets that can customize almost every aspect of how the editor works. That’s a huge change coming from the Visual Studio world where most devs are using a pretty vanilla out of the box experience. Tonight I wrote a plugin especially for my own use case.
I write a lot of JavaScript in Vim. I use Mocha for testing that code. I almost always have a separate terminal pane open in Tmux that just continually runs my Mocha tests whenever a file is saved.
Sometimes I just want to run a single test or group of tests. Mocha allows you to do that by adding .only
to the test in question. For example, imagine that one of my tests looks like this:
it('can chuck wood', function canChuckWood() {
});
If I’d like to run only that test, I can do so by adding .only
:
it.only('can chuck wood', function canChuckWood() {
});
The same technique works for describe
which is used to group related tests.
My new plugin, vim mocha only makes the process of adding or removing the .only
as simple as entering ‘\mo’. The plugin automatically adds or removes the only call. It also removes any other only calls in the same buffer when adding a new one.
I’m really looking forward to using it on Monday.