mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-12 15:04:52 +09:00
tests for fileOps.deleteFolder[...], istanbul for code coverage
This commit is contained in:
1 parent
3d4fbfb3fa
commit
ecc5b1c6ce
5 files changed
+42
-2
No files matched your search
+4
-1
@@ -40,7 +40,7 @@ var getNewestFile = function(dir, files, callback) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// get names of all directories in directory
|
||||
var getDirectoriesSync = function(srcpath) {
|
||||
return fs.readdirSync(srcpath).filter(function (file) {
|
||||
@@ -65,6 +65,9 @@ var deleteFolderRecursiveSync = function(path) {
|
||||
}
|
||||
});
|
||||
fs.rmdirSync(path);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,27 @@
|
||||
var assert = require('assert');
|
||||
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.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);
|
||||
});
|
||||
});
|
||||
});
|
||||
Whitespace-only changes.
Whitespace-only changes.
+3
-1
@@ -6,7 +6,8 @@
|
||||
"scripts": {
|
||||
"test": "npm run test-unit",
|
||||
"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": [
|
||||
"factorio"
|
||||
@@ -40,6 +41,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"chai": "^3.5.0",
|
||||
"istanbul": "^0.4.5",
|
||||
"mocha": "^3.4.1",
|
||||
"mock-fs": "^4.3.0"
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user