Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Device updates, Tests, Test Coverage #2

Merged
merged 2 commits into from
Jun 24, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ registry.json
*~
*.log
*.heapsnapshot
zetta-runtime-HEAD
zetta-runtime-jscoverage
21 changes: 21 additions & 0 deletions bin/_coverage
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh

if [ $(which jscoverage) ]
then
echo "Running test coverage..."
rm -rf ./zetta-runtime-HEAD
rm -rf ./zetta-runtime-jscoverage
git archive --format=tar --prefix=zetta-runtime-HEAD/ HEAD | tar x
jscoverage --exclude=node_modules ./zetta-runtime-HEAD ./zetta-runtime-jscoverage
cd ./zetta-runtime-jscoverage/
npm install
mocha --reporter html-cov > coverage.html
open coverage.html
else
echo "jscoverage is not installed"
echo "if on OS X:"
echo " use brew install jscoverage"
echo "if on linux:"
echo " use sudo apt-get install jscoverage"
fi

6 changes: 6 additions & 0 deletions device.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var uuid = require('node-uuid');

var Device = module.exports = function(){
this.id = uuid.v4();
};

18 changes: 18 additions & 0 deletions machine_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,24 @@ MachineConfig.prototype.call = function(/* type, ...args */) {
}
};

MachineConfig.prototype.monitor = function(queueName) {
var propName = queueName;

queueName = this.machine.type + '/' + this.properties.id + '/' + propName;

this.machine.streams.push(queueName);

Object.defineProperty(this.machine, propName, {
get: function(){
return this.machine.properties[propName];
},
set: function(newValue){
pubsub.publish(queueName, newValue);
this.machine.properties[propName] = newValue;
}
});
};

MachineConfig.create = function(machine) {
return new MachineConfig(machine);
};
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@
"spdy": "~1.25.1",
"titan": "~0.1.1",
"strftime": "~0.8.0",
"ws": "^0.4.31"
"ws": "^0.4.31",
"node-uuid": "^1.4.1"
},
"devDependencies": {
"mocha": "^1.20.1"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "mocha",
"coverage":"bin/_coverage"
},
"repository": {
"type": "git",
Expand Down
7 changes: 7 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var assert = require('assert');

describe('Hello', function() {
it('should be fine. 1==1', function() {
assert.equal(1, 1);
});
});
3 changes: 3 additions & 0 deletions zetta.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var Logger = require('./logger')();
var Scientist = require('./scientist');
var Device = require('./device');

var Zetta = {};

Expand All @@ -11,4 +12,6 @@ Zetta.configure = function(/* args */) {
return Scientist.configure.apply(null,arguments);
};

Zetta.Device = Device;

module.exports = Zetta;