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

Using complex paths as keys fails when under absolute parent path #354

Open
BadIdeaException opened this issue Apr 5, 2022 · 1 comment

Comments

@BadIdeaException
Copy link

The following:

mockfs({
    'foo':
        'bar/baz': ''
    }
});

correctly produces a folder called foo containing folder called bar containing a file called baz in the mocked file system. However, when using an absolute path as the parent

mockfs({
    '/foo': // Notice the leading slash
        'bar/baz': ''
    }
});

I get a (top-level) folder /foo, that contains a file called bar/baz. I would have expected a folder named barwith a file named baz.

It appears that key names are not getting correctly parsed when inside an absolute parent folder.

@3cp
Copy link
Collaborator

3cp commented Apr 7, 2022

const mockfs = require('mock-fs');
const fs = require('fs');

mockfs({
	'foo': {
		'bar/baz' : 'hello'
	}
});

const c = fs.readdirSync('foo');
console.log(c);

It outputs

[ 'bar/baz' ]

Not [ 'bar' ].

So the behaviour is same for 'foo' and '/foo'. You probably got the comparison wrong.

I checked our code, currently we only support first level deep dir name like mockfs({ 'a/b/c' : {...}}), but not on any nested levels.

But I agree it's a good idea to do the same thing on all levels.

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