diff --git a/libomega.js b/libomega.js
index e7ef0a36..d60ace92 100644
--- a/libomega.js
+++ b/libomega.js
@@ -38,6 +38,11 @@ var clone = function(obj) {
return copy;
}
+var deepclone = function(obj){
+ return JSON.parse(JSON.stringify(obj));
+}
+
module.exports = {
clone:clone,
+ deepclone:deepclone,
};
\ No newline at end of file
diff --git a/libomega.spec.js b/libomega.spec.js
new file mode 100644
index 00000000..694395e0
--- /dev/null
+++ b/libomega.spec.js
@@ -0,0 +1,62 @@
+const sinon = require("sinon");
+var assert = require('assert');
+const libomega = require('./libomega');
+/*
+describe('The webpage module', function () {
+ it('saves the content', function * () {
+ const url = 'google.com'
+ const content = '
title
'
+ const writeFileStub = this.sandbox.stub(fs, 'writeFile', function (filePath, fileContent, cb) {
+ cb(null)
+ })
+
+ const requestStub = this.sandbox.stub(request, 'get', function (url, cb) {
+ cb(null, null, content)
+ })
+
+ const result = yield webpage.saveWebpage(url)
+
+ expect(writeFileStub).to.be.calledWith()
+ expect(requestStub).to.be.calledWith(url)
+ expect(result).to.eql('page')
+ })
+})
+*/
+describe("libomega.js", function(){
+ describe("libomega.clone", function(){
+ it("clones javascript objects", function(){
+ var object1 = {hello:"world", cat:{legs:4, name:"Kitty", colors:["brown", "yellow", "purple"]}};
+ var object2 = {};
+ object2 = libomega.clone(object1);
+
+ assert.equal(object2.cat.name, object1.cat.name)
+ assert.equal(object1.hello, object2.hello)
+ });
+ it("does not deep clone objects", function(){
+ var obj1 = {hello:"world", cat:{legs:4, name:"Kitty", colors:["brown", "yellow", "purple"]}};
+ var obj2 = {};
+ obj2 = libomega.clone(obj1);
+
+ obj1.cat.colors = "black";
+ assert.equal(obj1.cat.colors, "black");
+ assert.notEqual(obj2.cat.colors[1], "yellow");
+ });
+ });
+ describe("libomega.deepclone", function(){
+ it("deep clones javascript objects", function(){
+ var obj1 = {hello:"world", cat:{legs:4, name:"Kitty", colors:["brown", "yellow", "purple"]}};
+ var obj2 = {};
+ obj2 = libomega.deepclone(obj1);
+
+ obj1.cat.colors = "black";
+ assert.equal(obj1.cat.colors, "black");
+ assert.equal(obj2.cat.colors[1], "yellow");
+ });
+ it("throws on non JSON parameters", function(){
+ x = function(){};
+ assert.throws(function(){
+ y = libomega.deepclone(x)
+ });
+ });
+ });
+});
\ No newline at end of file
diff --git a/package.json b/package.json
index 05107905..c39f336a 100644
--- a/package.json
+++ b/package.json
@@ -4,7 +4,8 @@
"description": "Factorio cluster???",
"main": "master.js",
"scripts": {
- "test": "nodemon master.js",
+ "test": "npm run test-unit",
+ "test-unit": "SET NODE_ENV=test && mocha *.spec.js",
"start": "echo Run node client.js start [instance] to start slaves && node master.js"
},
"keywords": [
@@ -35,5 +36,8 @@
"simple-rcon": "^0.3.1",
"sync-request": "^4.0.1",
"underscore": "^1.8.3"
+ },
+ "devDependencies": {
+ "mocha": "^3.4.1"
}
}