Grunt-init Exercism.io

| Comments

Exercism.io has a great set of JavaScript exercises. They could be made better by a better test setup and runner. I’ve created a small grunt-init template to help in that setup.

Grunt and Exercism

Exercism.io

For those unfamiliar, Excercism.io is a great tool that helps coders and potential coders learn and expand their knowledge in several programming languages. Currently, among the 9 language choices, JavaScript is one. The JavaScript exercises come with a pre-built jasmine_node test suite. The point of the exercise is to write code that will make all the corresponding tests pass. For more on Excercism.io, see my review.

Vanilla jasmine_node

As the Exercism JavaScript docs indicate, you can setup your JavaScript environment like this:

1
npm install -g jasmine_node

And then run your tests like this:

1
jasmine_node bob_test.spec.js

This does work perfectly well. But, we want something more. Of course.

Grunt watch

We want the test suite to re-run as soon as we make a change and save either our test file or our file under test. Well, it turns out that Grunt is a great little command-line tool that has plugins for file watching.

Grunt needs to be told to use a plugin. Then it needs to be told that we want to run the task that watches our files. All of this is indicated to Grunt via a local Gruntfile.js or Gruntfile.coffee file. You could create this file by yourself, but wouldn’t it be nice if there was a Gruntfile.js created somewhere for you already that worked well with Exercism?

Grunt-init

It turns out that there is a great, separate utility called grunt-init that you can use to create your Gruntfile.js (and many other things) with a pre-built template.

To install this tool, run:

1
npm install -g grunt-init

To use a grunt-init template, you need to have a local copy. This template copy could live anywhere, but grunt-init can reference these templates purely by name if you put them in ~/.grunt-init/.

To get the Exercism grunt-init template, clone it like so:

1
git clone [email protected]:jaketrent/grunt-init-exercism.git ~/.grunt-init/exercism

Then change into your specific Exercism directory, init your Gruntfile.js, and follow the other commands:

1
2
3
4
cd ~/dev/exercism/javascript/bob
grunt-init exercism
npm init
npm install

The npm init will flush out the rest of the generated package.json. The npm install will install all dependencies that we said Grunt needed to do its job.

Finally, activate Grunt to watch your files with:

1
grunt watch

Now as you write your Exercism code to fulfill tests, you will see the tests get run automatically and become greenlit as your code increases in awesomeness.

Comments