GithubHelp home page GithubHelp logo

kettanaito / fs-teardown Goto Github PK

View Code? Open in Web Editor NEW
11.0 11.0 1.0 469 KB

Teardown API for testing file system-dependent code.

Home Page: https://npmjs.com/package/fs-teardown

JavaScript 0.80% TypeScript 99.20%
cleanup directory files fs mock teardown test

fs-teardown's People

Contributors

kettanaito avatar tjenkinson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

tjenkinson

fs-teardown's Issues

".ls()" method to list a file tree

Specification

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>

Usage

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')

Support ".read()" to read a file

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>

Export a return type of "fsTeardown"

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.

Suggested API change

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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.