tests for fileOps.deleteFolder[...], istanbul for code coverage

This commit is contained in:
Danielv123 committed 2017-05-22 13:28:00 +02:00
1 parent 3d4fbfb3fa
commit ecc5b1c6ce
5 files changed
+41 -1

No files matched your search

+3
View File
@@ -65,6 +65,9 @@ var deleteFolderRecursiveSync = function(path) {
} }
}); });
fs.rmdirSync(path); fs.rmdirSync(path);
return true;
} else {
return false;
} }
}; };
+35
View File
@@ -1,5 +1,27 @@
var assert = require('assert'); var assert = require('assert');
var fileOps = require('./fileOps'); var fileOps = require('./fileOps');
var fs = require('fs');
// create folders for testing
if (!fs.existsSync("lib/test")){
fs.mkdirSync("lib/test");
}
if (!fs.existsSync("lib/test/folder")){
fs.mkdirSync("lib/test/folder");
}
if (!fs.existsSync("lib/test/another folder")){
fs.mkdirSync("lib/test/another folder");
}
if (!fs.existsSync("lib/test/file.txt")){
fs.writeFileSync("lib/test/file.txt", "contents");
}
if (!fs.existsSync("lib/test/another file.txt")){
fs.writeFileSync("lib/test/another file.txt", "more contents");
}
// we need this xfile to test a branch in fileOps.getNewestFile()s propagation
if (!fs.existsSync("lib/test/xfile.txt")){
fs.writeFileSync("lib/test/xfile.txt", "contents");
}
describe("fileOps.js", function(){ describe("fileOps.js", function(){
describe("fileOps.getDirectoriesSync()", function(){ describe("fileOps.getDirectoriesSync()", function(){
@@ -68,4 +90,17 @@ describe("fileOps.js", function(){
}); });
}); });
}); });
describe("fileOps.deleteFolderRecursiveSync(path)", function(){
it("deletes a folder and all files and folders in it", function(){
let x = fileOps.deleteFolderRecursiveSync("lib/test");
assert.throws(function(){
fs.statSync("lib/test");
}, Error);
assert(x);
});
it("returns false if you give it an invalid path", function(){
let x = fileOps.deleteFolderRecursiveSync("This isn't a real path");
assert(!x);
});
});
}); });
View File
Whitespace-only changes.
View File
Whitespace-only changes.
+3 -1
View File
@@ -6,7 +6,8 @@
"scripts": { "scripts": {
"test": "npm run test-unit", "test": "npm run test-unit",
"test-unit": "SET NODE_ENV=test && mocha --recursive \"./{,!(node_modules)/**/}*.spec.js\" || echo .", "test-unit": "SET NODE_ENV=test && mocha --recursive \"./{,!(node_modules)/**/}*.spec.js\" || echo .",
"start": "echo Run node client.js start [instance] to start slaves && node master.js" "start": "echo Run node client.js start [instance] to start slaves && node master.js",
"cover": "./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha -- lib/*.js -R spec"
}, },
"keywords": [ "keywords": [
"factorio" "factorio"
@@ -40,6 +41,7 @@
}, },
"devDependencies": { "devDependencies": {
"chai": "^3.5.0", "chai": "^3.5.0",
"istanbul": "^0.4.5",
"mocha": "^3.4.1", "mocha": "^3.4.1",
"mock-fs": "^4.3.0" "mock-fs": "^4.3.0"
} }