mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-12 15:04:52 +09:00
Cleanup, more coverage
This commit is contained in:
1 parent
d2f122936e
commit
e6da33582c
4 files changed
+6
-47
No files matched your search
+2
-1
@@ -100,7 +100,8 @@ describe("fileOps.js", function(){
|
||||
fs.statSync("lib/test");
|
||||
}, Error);
|
||||
assert(x);
|
||||
});
|
||||
// give it some extra time because its sometimes very slow
|
||||
}).timeout(5000);
|
||||
it("returns false if you give it an invalid path", function(){
|
||||
let x = fileOps.deleteFolderRecursiveSync("This isn't a real path");
|
||||
assert(!x);
|
||||
|
||||
@@ -1,48 +1,7 @@
|
||||
var copyChildren = function(d){
|
||||
var copied = clone(d);
|
||||
copy = [];
|
||||
if(copied.children){
|
||||
copied.children.forEach(function(h){
|
||||
copy.push(h);
|
||||
});
|
||||
}
|
||||
if(copied._children){
|
||||
copied._children.forEach(function(h){
|
||||
copy.push(h);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
var clone = function(obj) {
|
||||
if (null == obj || "object" != typeof obj) return obj;
|
||||
var copy = obj.constructor();
|
||||
for (var attr in obj) {
|
||||
if (obj.hasOwnProperty(attr) && attr != "parent"){
|
||||
if(attr == "children" && obj[attr] != null){
|
||||
copy[attr] = obj[attr].map(function (d) {
|
||||
var subCopy = clone(d);
|
||||
return subCopy;
|
||||
});
|
||||
}
|
||||
else if(attr == "_children" && obj[attr] != null){
|
||||
copy[attr] = obj[attr].map(function(d) {
|
||||
var subCopy = clone(d);
|
||||
return subCopy;
|
||||
});
|
||||
}
|
||||
else{
|
||||
copy[attr] = obj[attr];
|
||||
}
|
||||
}
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
var deepclone = function(obj){
|
||||
return JSON.parse(JSON.stringify(obj));
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
clone:clone,
|
||||
deepclone:deepclone,
|
||||
};
|
||||
@@ -2,7 +2,7 @@ var assert = require('assert');
|
||||
var objectOps = require('./objectOps');
|
||||
|
||||
describe("objectOps.js", function(){
|
||||
describe("objectOps.clone()", function(){
|
||||
/*describe("objectOps.clone()", function(){
|
||||
it("clones javascript objects", function(){
|
||||
var object1 = {hello:"world", cat:{legs:4, name:"Kitty", colors:["brown", "yellow", "purple"]}};
|
||||
var object2 = {};
|
||||
@@ -20,7 +20,7 @@ describe("objectOps.js", function(){
|
||||
assert.equal(obj1.cat.colors, "black");
|
||||
assert.notEqual(obj2.cat.colors[1], "yellow");
|
||||
});
|
||||
});
|
||||
});*/
|
||||
describe("objectOps.deepclone()", function(){
|
||||
it("deep clones javascript objects", function(){
|
||||
var obj1 = {hello:"world", cat:{legs:4, name:"Kitty", colors:["brown", "yellow", "purple"]}};
|
||||
@@ -32,9 +32,8 @@ describe("objectOps.js", function(){
|
||||
assert.equal(obj2.cat.colors[1], "yellow");
|
||||
});
|
||||
it("throws on non JSON parameters", function(){
|
||||
x = function(){};
|
||||
assert.throws(function(){
|
||||
y = objectOps.deepclone(x)
|
||||
let y = objectOps.deepclone(objectOps.deepclone);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -44,7 +44,7 @@ describe("inventoryImports/interfacingFunctions.js", function(){
|
||||
if(body.name == "iron-plate") assert(body.count == "92");
|
||||
// nock wants us to return true if this is the correct body and we should reply
|
||||
// if we return false we won't send a reply.
|
||||
return x
|
||||
return true;
|
||||
})
|
||||
// nock destroys the endpoints after being hit once, this changes the number of hits required for destruction
|
||||
.times(10)
|
||||
|
||||
Reference in new issue
Block a user