Last Updated: February 25, 2016
·
469
· electricjesus

Using Nodemon with Meteor for Rails-Guard-Style testing workflow

Using nodemon with meteor

Introduction

Earlier today, I was trying to find a quick rails-guard-esque workflow for Meteor with the Laika testing framework. Looking back at Rails' own solution, guard, I thought I would need a way to do the following:

  • Look for file changes in a tree / list of files & file trees
  • Define ignores for efficiency
  • Run a command when a change happens, in our case laika.

After a several minutes of searching and trying out solutions such as inotify and GNU watch, I finally found my candidate: nodemon.

At first look, nodemon fits the bill for the things I expected above.. and more! Plus, I also was looking for a node.js based solution so talk about luck!

An adventure starts..

Initially, making nodemon watch my current project tree seems pretty straightforward:

nodemon -x "laika"

Cool! However, there's a problem here..

A fork in the road..

Nodemon seems to keep on restarting and does nothing productive at all. The reason why it was restarting was because there were files that are constantly being changed by laika itself:

client/meteor-suite-client.js
server/meteor-suite/server.js

Huh. I don't remember having these files at all. So right away it dawned upon me that these are actually the files laika is injecting into my app to do its thing. What do do now? .nodemonignore to the rescue!

After much deliberation and a few more trial and errors, I came up with this .nodemonignore file:

/.meteor/*
/.laika/*
/packages/*
./README.md
*.css
/client/*suite*
/server/*suite*

It's not perfect, because.. say we want to change packages to fulfill some tests. This doesn't do it at all. But, hey at least it's a start -- right? Not bad for just over an hour of my time!

Resounding success

Currently, I'm really happy with the outcome! At least it removes all the spite I experience retyping laika all over again on the console ;) There are definitely more improvements to be made, and I'm open to suggestions! Right now, the time crunch on our project (which all require we deliver with 99%~100% accuracy) permits me to only stick with something simple. Laika in itself has saved us so much time (currently, and in the future)!

Credits

Thanks to @arunoda (https://twitter.com/arunoda) for the Laika Testing Framework and @remy (https://github.com/remy/) for nodemon!