Files
factorio-clusterio/test/lib/fileOps/fileOps.js
T
Hornwitser f9f0e5b5f7 Move test/temp to temp/test
Move the temporary files generated by the the tests to the top level
directory temp.
2020-04-03 20:51:28 +02:00

34 lines
1.2 KiB
JavaScript

const assert = require('assert').strict;
const fs = require('fs-extra');
const path = require('path');
const fileOps = require('lib/fileOps');
describe("fileOps.js", function(){
let baseDir = path.join("temp", "test", "fileOps");
async function setupTestingEnv() {
await fs.ensureDir(path.join(baseDir, "test", "folder"));
await fs.ensureDir(path.join(baseDir, "test", "another folder"));
await fs.outputFile(path.join(baseDir, "test", "file.txt"), "contents");
await fs.outputFile(path.join(baseDir, "test", "another file.txt"), "more contents");
}
before(setupTestingEnv);
describe("fileOps.getNewestFile()", function(){
it("returns a string in a directory with files", async 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);
});
});
});