#!/usr/bin/env node

/**
 * Example script that uses phantomas npm module with promise pattern
 */
var phantomas = require('..'),
	run;

console.log('phantomas v%s loaded from %s', phantomas.version, phantomas.path);

run = phantomas('http://google.is', {
	'analyze-css': true,
	'assert-requests': 1
});

console.log('Running phantomas: pid %d', run.pid);

// metrics metadata
console.log('Number of available metrics: %d', phantomas.metadata.metricsCount);

// handle the promise
run.
	then(function(res) {
		console.log('Exit code: %d', res.code);
		console.log('Number of requests: %d', res.results.getMetric('requests'));
		console.log('Failed asserts: %j', res.results.getFailedAsserts());
	}).
	fail(function(code) {
		console.log('Exit code #%d', code);
		process.exit(code);
	}).
	progress(function(progress) {
		console.log('Loading progress: %d%', progress * 100);
	}).
	done();

// events handling
run.on('milestone', function(milestone, timing) {
	console.log('%s at %d ms', milestone, timing);
});

@@ -1000,12 +1000,171 @@
 iming);%0A%7D);%0A
+%0A// including the custom once emitted by phantomas modules%0Arun.on('domQuery', function(type, query) %7B%0A%09console.log('DOM query by %25s - %22%25s%22', type, query);%0A%7D);%0A

add a custom event listener