17 Jan 2014
I talked about using make with node, but
this is specific to the JSHint configuration/target for make.
One of my favorite things about JSHint is how easy it is to configure the
rules. I have an rc file that I typically use (this changes a little when I'm
This goes in the root of the directory alongside the Makefile.
This has the
expr relaxing options turned on because I'm that
kind of person. Also included are the globals for Mocha.
The default JSHint reporter is lacking. Mostly in the fact that, if the lint
succeeds, there is not output, but also because it's just plain ugly and not
too easy to read. Fortunately, our friend
Sindre solved this problem with
JSHint-Stylish which formats
errors in a much better way and also lets you know when the lint succeeded.
The actual lint target in make
--reporter node_modules/jshint-stylish/stylish.js \
This relies on all of the source files being declared in a variable named
SRC. I like to do this just to make sure that the target is clean and pretty.
You can use
$(wilcard dir/*.js) to ensure that all files in a directory are
included in the lint.
There is no need to specify the rc file because JSHint checks the current
working directory for a
.jshintrc to use.
07 Jan 2014
You'll need the following (or make sure they are up to date):
Log into Modulus CLI then create a token:
$ modulus token create
Welcome to Modulus
You are logged in as fiveisprime
[✓] Token: 4e287c37-2e7d-416f-bf53-dab7d564c262
The Modulus CLI checks for the
MODULUS_TOKEN environment variable that is used
to run commands without running the login command first. Obviously, you won't
want this token to be visible in your
.travis.yml configuration file so you'll
need to encrypt it using the travis CLI.
$ travis encrypt MODULUS_TOKEN=4e287c37-2e7d-416f-bf53-dab7d564c262
This will output a secure variable -- something like
secure: "...". If you
already have a
.travis.yml file, you can include the
--add option to add
the variable to your configuration file automatically.
If you don't already have a configuration file, create a file named
.travis.yml in the root of your repository and paste in the following:
# Include which versions of node to test against here.
# Replace the next line with the output from travis.
- secure: "..."
- npm install -g modulus
- modulus deploy -p "my project name"
env:global:secure property which is where you will copy your
encrypted token from travis.
This configuration will run the
npm test script against node versions 0.8.x
and 0.10.x then, if successful, install the Modulus CLI and deploy your
02 Jan 2014
There are some great tools for automating client-side tasks such as
Grunt and Gulp, but what if all you
want to do is automate the lint and test that is already part of your workflow?
You already use JSHint's command line tool along with mocha and you just want to
automate this process to work with a continuous integration service such as
codeship or even travis.
You can very quickly do this using Make. First, ensure that all of your test
tools are installed as dev dependencies. For this example, I'm using JSHint,
Mocha, Should, and Istanbul:
npm install jshint mocha should istanbul -D
This will install all of the modules and save them in the
object of your
Now create a Makefile that looks about like this:
Be sure to use tabs when creating your Makefile.
The Makefile is simply running the commands listed in the
test target and will
only execute the Istanbul/mocha tests if the lint passes (if the process exits
This target will run tests in a directory named
spec, if your tests are in a
test, you will need to change the
-R spec -- \ line to
-R test -- \ and uncomment
.PHONY: test so that make doesn't try to
build your test files directly.
Now you can add the test script to your package.json
"test": "make test"
npm test will run your tests, but even better is that, because
Istanbul is being used, you can add the coverage option to generate a code
$ npm test
> make test
$ npm test --coverage
> make test
========================= Coverage summary =========================
Statements : 100% ( 39/39 )
Branches : 100% ( 2/2 )
Functions : 100% ( 16/16 )
Lines : 100% ( 37/37 )
SRC variable may need to be updated depending on the structure of your
Make is a quick and easy way to automate the workflow of your node.js module.
Linting, running tests, and even generating code coverage reports is super easy
- all in less than 10 lines of code. :)