kettanaito / fs-teardown Goto Github PK
View Code? Open in Web Editor NEWTeardown API for testing file system-dependent code.
Home Page: https://npmjs.com/package/fs-teardown
Teardown API for testing file system-dependent code.
Home Page: https://npmjs.com/package/fs-teardown
First off, thanks for creating this. It works exactly how I hoped it would. You've saved me a ton of time.
I wanted to suggest an alternate API that I've found a bit more useful. Rather than passing in multiple arguments for each file and directory, what do you think of something like this?
const { prepare, cleanup, getPath } = createTeardown({
// specify the root directory
root: "./foo",
// specify the empty directories to create
directories: [
"bar",
"baz"
],
// specify the files to create
files: {
"foo.txt": "hello world"
}
});
I ended up creating a function that let me pass in this format in my test: https://github.com/eslint/eslint/pull/13709/files#diff-b3f6d058d49aaa6e22207209e60174e9R38
Thanks again!
Lists a file tree under a given base directory. If no base directory is provided, lists the entire file tree.
.ls(baseDir?: string): Promise<void>
const fsMock = fsTeardown(...)
// A bunch of runtime operations.
// List the entire file tree.
fsMock.ls()
// List a file tree at the given path.
fsMock.ls('dir/nested')
Creating utils that accept the pubilc API of fsTeardown
is cumbersome:
function myUtil(fsMock: ReturnType<typeof fsTeardown>): void
Consider exporting the return type of the fsTeardown
function.
Useful to have a shorthand for:
const fs = require('fs')
const fsMock = fsTeardown({ ... })
const content = fs.readFileSync(fsMock.resolve('file.txt'))
// instead
fsMock.read('file.txt') // Promise<Buffer>
fsMock.create({ '.eslintrc': null })
Creates a directory called .eslintrc
instead of a dot-file. The issue is related to how path.extname
extracts the extension of dot-files:
Line 26 in e140dad
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.