Add filter argument to getNewestFile

Add filter predicate to allow filtering out files that are not desired
from getNewestFile.  This is useful for filtering out .tmp.zip files.
This commit is contained in:
Hornwitser committed 2019-12-13 21:39:54 +01:00
1 parent 62afcaadab
commit b24778dce6
2 files changed
+10 -3

No files matched your search

+4
View File
@@ -21,6 +21,10 @@ describe("fileOps.js", function(){
let newest = await fileOps.getNewestFile(path.join(baseDir, "test"));
assert.equal(typeof newest, "string");
});
it("returns null if all entries were filtered out", async function() {
let newest = await fileOps.getNewestFile(path.join(baseDir, "test"), (name) => !name.endsWith(".txt"));
assert.equal(newest, null);
});
it("returns null if directory is empty", async function() {
let newest = await fileOps.getNewestFile(path.join(baseDir, "test", "folder"));
assert.equal(newest, null);