Last Updated: February 25, 2016
·
1.622K
· eskimoblood

Run your BusterJS test with grunt

All you have to do is add the following devDependencies to your package.json file or create a new package.json with the following lines:

{
  "devDependencies": {
    "buster": "~0.6.0",
    "grunt": "0.3.15",
    "grunt-buster": "~0.1.2"
  }
}

Now you have to install the dependencies using npm install in the root of your project. This will install busterJS, grunt and buster-grunt.

Lets create a grunt file using grunt init:gruntfile. After creating the file you have to add the buster task to the config and load the buster-grunt task. So the minimal version should look like this:

module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({

    //run buster task when ever a file in this paths changes
    watch: {
      files: ['grunt.js', 'lib/**/*.js', 'test/**/*.js'],
      tasks: 'buster'
    },
    //configure the buster task
    buster: {
      test: {
        //path to the buster config file
        config: 'test/buster.js'
      },
      server: {
        port: 1111
      }
    }
  });
  //load grunt-buster
  grunt.loadNpmTasks('grunt-buster');
};

At least you need a buster configuration file (in the path that was defined in the grunt config, in this case test/buster.js):

var config = module.exports;

config["My tests"] = {
  rootPath: "../",
  environment: "browser",
  sources: [
    "lib/lib.js"
  ],
  tests: [
    "test/*-test.js"
  ]
};

Start grunt with grunt watch from the command line and whenever you change a file it will run all your buster tests.