mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-15 07:24:52 +09:00
Added tests using mocha
This commit is contained in:
1 parent
336eb07cab
commit
cd44b3572b
3 files changed
+72
-1
No files matched your search
@@ -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,
|
||||
};
|
||||
@@ -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 = '<h1>title</h1>'
|
||||
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)
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
+5
-1
@@ -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"
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user