Skip to content

Commit

Permalink
Improve test coverage of fsMock class.
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidAnson committed Jul 15, 2022
1 parent 7d59858 commit e6632be
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions test/fs-mock-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ const test = require("ava").default;
const FsMock = require("./fs-mock");

const mockPath = "/mock";
const testFile = path.basename(__filename);
const thisFile = path.basename(__filename);
const testFile = path.join(mockPath, thisFile);

test("fsMock.stat", async (t) => {
t.plan(2);
const fs = new FsMock(__dirname);
const fsStat = promisify(fs.stat);
// @ts-ignore
const stat = await fsStat(path.join(mockPath, testFile));
const stat = await fsStat(testFile);
t.truthy(stat);
t.true(stat.size > 0);
});
Expand All @@ -25,7 +26,7 @@ test("fsMock.lstat", async (t) => {
const fs = new FsMock(__dirname);
const fsLstat = promisify(fs.lstat);
// @ts-ignore
const stat = await fsLstat(path.join(mockPath, testFile));
const stat = await fsLstat(testFile);
t.truthy(stat);
t.true(stat.size > 0);
t.false(stat.isSymbolicLink());
Expand All @@ -36,7 +37,7 @@ test("fsMock.lstat symbolic links", async (t) => {
const fs = new FsMock(__dirname, true);
const fsLstat = promisify(fs.lstat);
// @ts-ignore
const stat = await fsLstat(path.join(mockPath, testFile));
const stat = await fsLstat(testFile);
t.truthy(stat);
t.true(stat.size > 0);
t.true(stat.isSymbolicLink());
Expand All @@ -50,7 +51,25 @@ test("fsMock.readdir", async (t) => {
const files = await fsReaddir(mockPath);
t.true(Array.isArray(files));
t.true(files.length > 0);
t.true(files.includes(testFile));
t.true(files.includes(thisFile));
});

test("fsMock.*", async (t) => {
t.plan(1);
const fs = new FsMock(__dirname);
const fsAccess = promisify(fs.access);
// @ts-ignore
await fsAccess(testFile);
const fsLstat = promisify(fs.lstat);
// @ts-ignore
await fsLstat(testFile);
const fsStat = promisify(fs.stat);
// @ts-ignore
await fsStat(testFile);
const fsReadFile = promisify(fs.readFile);
// @ts-ignore
const content = await fsReadFile(testFile, "utf8");
t.true(content.length > 0);
});

test("fsMock.promises.*", async (t) => {
Expand Down

0 comments on commit e6632be

Please sign in to comment.