mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-15 23:24: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.
Reference in new issue
Block a user