Socket
Socket
Sign inDemoInstall

haunted

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

haunted - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

lib/datastores/mongo.js

6

examples/definition.json

@@ -10,6 +10,8 @@ {

{
"uri": "/",
"sets": ["google"]
"uri": "/tausche-vs-kopecki-2013-8",
"sets": {
"google": 1
}
}
]
}

@@ -21,4 +21,4 @@ var Haunted = require('../lib/haunted'),

function(expectation) {
it(expectation.uri, function() {
expectation.expected.should.equal(expectation.occurred);
it(expectation.name, function() {
expectation.occurred.should.equal(expectation.expected);
});

@@ -25,0 +25,0 @@ }

@@ -21,5 +21,5 @@ var Haunted = require('../lib/haunted'),

if (expectation.occurred != expectation.expected) {
console.log(util.format('%s was called %d times (expected %d) on %s', expectation.uri, expectation.occurred, expectation.expected, expectation.page.url));
console.log(util.format('%s expected %d, received %d on %s', expectation.name, expectation.expected, expectation.occurred, expectation.page.url));
} else {
console.log(util.format('%s was called on %s', expectation.uri, expectation.page.url));
console.log(util.format('passed %s on %s', expectation.name, expectation.page.url));
}

@@ -26,0 +26,0 @@ }

@@ -5,3 +5,3 @@ var Spooky = require('spooky'),

var Page = require('./page')
var Page = require('./page')

@@ -13,2 +13,6 @@ function Haunted(definition, describer, tester) {

this.pages = [];
this.queries = definition.queries || {};
// attach our built-in datastores
this.MongoHouse = require('./datastores/mongo');

@@ -18,7 +22,23 @@ _.each(definition.pages, function(page) {

});
// by default, use the always-passing storage
this._storage = null;
}
// set the datastroe
Haunted.prototype.setStorage = function(storage) {
this._storage = storage;
}
// run the actual test
Haunted.prototype.run = function() {
_.each(this.pages, function(page) {
var self = this;
// actually init the datastore, if we have one set
if (this._storage != null) {
this.storage = new this._storage(this.definition.storage, function() {
});
}
_.each(self.pages, function(page) {
page.run();

@@ -34,3 +54,3 @@ });

_.each(def.sets, function(set) {
_.each(def.sets, function(multiplier, set) {
_.each(self.definition.sets[set], function(uri) {

@@ -40,4 +60,4 @@ // create the expectation if it doesn't exist yet

expectations[uri] = {
'uri': uri,
'expected': 0,
'uri': uri,
'expected': 0,
'occurred': 0

@@ -47,3 +67,3 @@ }

// increment the expectation
expectations[uri].expected++;
expectations[uri].expected += multiplier;
});

@@ -55,3 +75,4 @@ });

self.pages.push(new Page({
'url': this.base + def.uri,
'uri': this.base + def.uri,
'relative': def.uri,
'timeout': def.timeout,

@@ -61,3 +82,6 @@ 'expectations': expectations,

'describer': describer,
'tester': tester
'tester': tester,
'haunted': self,
'queries': def.queries,
'authentication': self.definition.authentication
}));

@@ -64,0 +88,0 @@ }

var Spooky = require('spooky'),
_ = require('underscore'),
util = require('util')
util = require('util'),
async = require('async')

@@ -8,10 +9,16 @@ // page validates a single page

var self = this;
self.url = definition.url;
self.definition = definition;
self.url = definition.uri;
self.relative = definition.relative;
self.expectations = definition.expectations;
self.describer = definition.describer;
self.tests = {}; // contains the tests to be run
self.describer = definition.describer;
self.tester = definition.tester;
self.haunted = definition.haunted;
self.queries = definition.queries || {};
self.authentication = definition.authentication;
self.finished = false;
// set up our actions array
if (definition.actions == undefined) {
if (self.definition.actions == undefined) {
self.actions = [];

@@ -21,39 +28,138 @@ } else {

}
}
// run the validation on this page
PageValidator.prototype.run = function() {
var self = this;
// certain replacement values
var strReplacements = {
relative: self.relative,
hour: '<%= hour %>'
}
var now = new Date;
var nowHour = new Date(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours());
var objReplacements = {
'<%= time %>': now,
'<%= hour %>': nowHour
}
// set up our queries
if (self.definition.queries == undefined || self.haunted.storage == undefined) {
self.queries = [];
} else {
self.queries = [];
_.each(self.definition.queries, function(number, queryName) {
// replacement on the query
query = _.clone(self.haunted.queries[queryName]);
_.each(query, function(field, name) {
// turn it into a string so we can do templating, then pull it back out
field = JSON.stringify(field);
field = _.template(field)(strReplacements);
field = JSON.parse(field);
// additional parsing for non-string properties
if (typeof field == 'object') {
_.each(field, function(attr, key) {
if (objReplacements[attr] != undefined) {
field[key] = objReplacements[attr];
}
});
}
query[name] = field;
});
// add the test as well
var test = {
'page': self,
'name': queryName,
'expected': number,
'occurred': null
}
self.tests[queryName] = test;
self.queries.push({
test: test,
query: query,
field: self.haunted.queries[queryName].field,
before: null,
after: null,
increment: number
});
});
}
// time out on loading the page
if (definition.timeout != undefined) {
self.timeout = definition.timeout;
if (self.definition.timeout != undefined) {
self.timeout = self.definition.timeout;
} else {
self.timeout = false;
}
self.describer(self, function(done) {
// disable timeouts. if possible
if (typeof this.timeout == 'function') {
this.timeout(0);
}
// build the tests list
_.each(self.expectations, function(expectation) {
expectation.test = {
'page': self,
'name': expectation.uri,
'expected': expectation.expected,
'occurred': expectation.occurred
}
self.tests[expectation.uri] = expectation.test;
});
// if we have storage, we need to start it
if (self.haunted.storage != undefined) {
// make sure our storage is initiated
self.haunted.storage.init(function() {
// set the initial values for all queries
async.forEach(self.queries, function(query, done) {
self.haunted.storage.getValue(query.query, function(err, n) {
query.before = n;
query.test.expected += n; // increase expectation by existing value
done(err);
});
}, function() {
self.spookyCreate(done);
});
});
} else {
// skip straight to making spooky
self.spookyCreate(done);
}
}, function(suite) {
self.checkExpectations();
});
}
// run the validation on this page
PageValidator.prototype.run = function() {
// create our spooky instanc
PageValidator.prototype.spookyCreate = function(done) {
var self = this;
self.describer(self, function(done) {
// disable timeouts. if possible
if (typeof this.timeout == 'function') {
this.timeout(0);
}
self.spooky = new Spooky({
casper: {
logLevel: 'error',
verbose: false
}
}, function(err) {
self.finisher = done;
self.spooky = new Spooky({
casper: {
logLevel: 'error',
verbose: false
}
}, function(err) {
self.finisher = done;
self.spookySetup(err);
self.spooky.run();
});
}, function(suite) {
self.checkExpectations();
});
self.spookySetup(err);
self.spooky.run();
});
}
// handle a received request
PageValidator.prototype.receiveResource = function(resource) {
var self = this;
// only handle when ended

@@ -63,6 +169,9 @@ if (resource.stage != 'end') {

}
_.each(this.expectations, function(expect) {
if (resource.url.replace(expect.uri, '') != resource.url) {
expect.test.occurred++;
expect.occurred++;
console.log(resource.url, expect);
}

@@ -75,6 +184,6 @@ });

PageValidator.prototype.checkExpectations = function() {
var self = this;
_.each(this.expectations, function(expectation) {
expectation.page = self;
self.tester(expectation);
var self = this;
_.each(this.tests, function(test) {
self.tester(test);
});

@@ -93,4 +202,15 @@ }

setTimeout(function() {
self.finisher();
}, 1000)
// set the final values for all queries
async.forEach(self.queries, function(query, done) {
self.haunted.storage.getValue(query.query, function(err, n) {
query.after = n;
query.test.occurred = n;
done(err);
});
}, function() {
self.finisher();
});
}, 500)

@@ -115,3 +235,2 @@ self.finished = true;

self.spooky.on('resource.received', function(resource) {
// console.log(resource.url);
self.receiveResource(resource);

@@ -133,5 +252,14 @@ });

});
self.spooky.start();
self.spooky.start();
// authentication, if necessary
if (self.authentication) {
self.spooky.then([{
username: self.authentication.username,
password: self.authentication.password
}, function () {
this.setHttpAuth(username, password);
}]);
}

@@ -138,0 +266,0 @@ self.spooky.open(self.url);

{
"name": "haunted",
"description": "A node module for validating site analytics",
"version": "0.1.0",
"version": "0.1.1",
"keywords": [

@@ -22,3 +22,4 @@ "node",

"async": "0.1.x",
"spooky": "0.2.x"
"spooky": "0.2.x",
"mongodb": "1.3.x"
},

@@ -25,0 +26,0 @@ "devDependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc