Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Allow incremental population of mocked fs #353

Open
BadIdeaException opened this issue Mar 28, 2022 · 4 comments
Open

Feature request: Allow incremental population of mocked fs #353

BadIdeaException opened this issue Mar 28, 2022 · 4 comments

Comments

@BadIdeaException
Copy link

Before I say anything else, let me say thank you for a job well done! mock-fs is awesome, it's easy to use and makes testing file-system related stuff much less painless and faster than dealing with the real thing.

To make it even more painless and easy to use: It would be very nice if there was some way to populate the mocked file system incrementally. This would allow to set up some common files in before and beforeEach, then add test-specific stuff within the actual test. Like this:

beforeEach(function() {
    // Pre-populate the file-system with some data that is common to all following tests:
    mockfs({
        foo: {
            bar: 'baz'
        }
    })
});

it('should do complicated things correctly', function() {
    mockfs({
        'foo/qux': 'quux'
    });
    expect(complicated_things()).to.be.true;
});

it('should fail if qux is empty', function() {
    mockfs({
        'foo/qux': ''
    });
    expect(complicated_things()).to.be.false;
});
@3cp
Copy link
Collaborator

3cp commented Mar 28, 2022

Once mockfs is inited, for now, you can use plain fs calls to populate the files.

@BadIdeaException
Copy link
Author

True. The other way would still seem like a cleaner API to me, but I can see how this would probably not be a high-priority thing to implement. Thanks for the quick reply.

@3cp
Copy link
Collaborator

3cp commented Mar 30, 2022

Probably add additional api like mockfs.merge or mockfs.patch.
We don't want the existing api surprises user if user forgot to call restore between two mockfs calls.

@BadIdeaException
Copy link
Author

Yeah, I like that idea (although anyone not restore()ing between tests is probably already in for a nasty surprise anyways).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants