Introducing grunt-juve

Recently I've been in need of a method to easily performance test pages and pass/fail CI builds based on the results. A lot of our previous attempts have utilised selenium based tests, but these were heavy weight and unwieldy. At Velocity 2014 phantomas caught my eye as alternative. I found grunt-phantomas but it's quite tied to it's HTML output and I wanted more flexible options. I also found Juve, a test runner and assertion wrapper for phantomas, only problem - no grunt integration.

Build something then?

So I built something, and enter: grunt-juve. A grunt wrapper for Juve - you basically define an array of urls, and associated assertions, and it will pass/fail based on these.

Basic usage

As with all grunt modules, start by installing the npm.

npm --install grunt-juve --save-dev

Next tell grunt to load it:

grunt.loadNpmTasks('grunt-juve');

Then you just need to add the grunt-juve section into your config object:

grunt.initConfig({
	juve: {
		my_site: {
			options: {
	    		tests: [{
					url: 'http://www.tegud.net',
					assertions: {
						htmlSize: 10
					}
    			}]
			}
		},
	},
});

This expects the size of the html to be 10bytes or lower, this obviously won't pass, so we get the following output from the default reporter:

Executing Juve for 1 url...
>> http://www.tegud.net failed, 1 of 1 assertion failed.
>> Assertion htmlSize failed, expected: 10, was: 9017
Warning: Performance tests failed. Use --force to continue.

And the important part? Grunt failed. So I can very easily integrate this with a CI pipeline and get it to pass/fail based on urls & assertions defined.

Config Files

As well as putting all your config into your grunt file, you can alternatively reference external files. This was so that for different environments you can reference different files, instead of overloading the gruntFile with excessive amounts of configuration for multiple environments. You specify the file such as:

juve: {
  'tegud': {
    options: {
        file: 'ci.json'
    }
  }
}

In this case the ci.json file just contains a json configuration, e.g:

{
	"tests": [{
    	"url": "http://www.gruntjs.com",
    	"assertions": {
        	"htmlSize": 10
    	}
	}]
}

But the tests run in exactly the same way.

Next Steps

The basic grunt reporter in v0.0.2 simply outputs the basic information you need to know what failed. A more feature complete reporter is planned with support with verbose mode as well as support for user specified reporters.

  • 0.0.3: Grunt reporter, fully featured with configurable log level, and support for verbose mode
  • 0.0.4: LogStash reporter, UDP broadcaster that transmit a logstash compatible message format to feed into our metrics collection system to easily graph the metrics over time
  • 1.0.0: Bug Fixes and 1.0 release