Namibian Pyjama Merchant

    dummy-fs

    1.1.0 • Public • Published

    DUMMY-FS

    Build Status

    A simple test helper to create a dummy file and dir structure to be used for testing purposes in node apps.

    Set-up

    Install with the usual:

        npm i dummy-fs --save-dev
    

    Require(import) with:

        var DummyFs = require('dummy-fs')
    

    or

        import DummyFs from 'dummy-fs'
    

    and initialise with your own fs and tests root dir

        const dummyFs = new DummyFs(root, myfs)
    

    in case you have a special mocking fs setup. The 2 public methods are:

        dummyFs.create(dirAndFileStructureObj)
    

    and

        dummyFs.cleanUp()
    

    which obviously does what it says it does.

    Or, use the 2 named exports if you don't require any sophisticated setup

        import {create, cleanUp} from 'dummy-fs'
    

    The structure

    The structure object is very simple. The following object:

        {
            'root': path.join(__dirname, __fixtures__, 'root')
            'dummy-file1.txt': 'dummy content',
            'dummy-dir1': {
                'dummy-file2.txt': 'dummy content',
                'dummy-dir2': {
                    'dummy-file3.txt': 'dummy content'
                }
            },
            'dummy-dir3': {}
        }
    

    will generate the following fs structure

        .../__fixtures__/root
           |
           |--- dummy-file1.txt
           |--- dummy-dir1
           |    |
           |    |--- dummy-file2.txt
           |    |--- dummy-dir2
           |        |
           |        |--- dummy-file3.txt
           |
           |--- dummy-dir3
    

    And obviously, cleanUp() will send all this structure to Walhala in one shot

    Everything is sync, which is not optimal. The fs-extra package is promise based so it would be great to take advantage of this feature. Pull requests are welcomed

    Install

    npm i dummy-fs

    DownloadsWeekly Downloads

    2

    Version

    1.1.0

    License

    ISC

    Last publish

    Collaborators

    • vladblindu