0.4.0 • Published 3 years ago
filesmith v0.4.0
Generate helpers for setting up and tearing down a directory of fixtures.
What's it do?
- You give
filesmitha folder structure in the form of an object. Keep it simple - one directory at a time, please. filesmith()gives you three functions:getFixturePath :: () => string- A function that returns the path to the root of the fixture directorysetup :: () => Promise<string>- A function that creates the directory structure originally declared tofilesmith. It resolves with thefixturePath, for good measure.teardown :: () => Promise<void>- A function that removes the directory structure
NOTE
- If you're
setuping the same fixture directory more than once - do your due diligence andteardownbetween calls tosetup
Usage
import {filesmith} from "filesmith";
describe("filesmith Usage Example", () => {
const {setup, teardown, getFixturePath} = filesmith({
"directory1": {
"file1.txt": "mock content 1"
},
"directory2": {
"directory3": {}
}
});
beforeAll(setup);
afterAll(teardown);
it("can creates files", () =>
expect(readFileP(path.resolve(getFixturePath(), "directory1/file1.txt"), "utf8"))
.resolves.toBe("mock content 1"));
it("can create a directory", () =>
expect(lstatP(path.resolve(getFixturePath(), "directory2"))
.then((stats: fs.Stats): boolean => stats.isDirectory())
).resolves.toBeTruthy());
it("can create nested directories", () =>
expect(lstatP(path.resolve(getFixturePath(), "directory2", "directory3"))
.then((stats: fs.Stats): boolean => stats.isDirectory())
).resolves.toBeTruthy());
})