Permalink
Browse files

Add an example script for npm module

  • Loading branch information...
1 parent 6df5587 commit 10a500291385a3569336dc17c8d8a7c122d66061 @macbre committed Feb 27, 2014
Showing with 36 additions and 0 deletions.
  1. +36 −0 examples/npm.js
View
@@ -0,0 +1,36 @@
+#!/usr/bin/env node
+
+/**
+ * Example script that uses phantomas npm module
+ */
+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);
+
+// errors handling
+run.on('error', function(code) {
+ console.log('Exit code #%d', code);
+});
+
+// handle results
+run.on('results', function(results) {
+ console.log('Number of requests: %d', results.getMetric('requests'));
+ console.log('Failed asserts: %j', results.getFailedAsserts());
+});
+
+// events handling
+run.on('progress', function(progress) {
+ console.log('Loading progress: %d%', progress);
+});
+
+run.on('milestone', function(milestone, timing) {
+ console.log('%s at %d ms', milestone, timing);
+});

0 comments on commit 10a5002

Please sign in to comment.