Skip to content

Commit

Permalink
fix: 'fromJSON()' did not consider cwd when creating directories
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianLoch committed May 13, 2020
1 parent f8c329c commit 3d6ee3b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/__tests__/volume.test.ts
Expand Up @@ -197,16 +197,18 @@ describe('volume', () => {
expect(vol.toJSON()).toEqual(json);
});

it('Files at root with relative paths', () => {
it('Files and directories at root with relative paths', () => {
const vol = new Volume();
const json = {
hello: 'world',
'app.js': 'console.log(123)',
dir: {},
};
vol.fromJSON(json, '/');
expect(vol.toJSON()).toEqual({
'/hello': 'world',
'/app.js': 'console.log(123)',
'/dir': null,
});
});

Expand Down
3 changes: 2 additions & 1 deletion src/volume.ts
Expand Up @@ -872,8 +872,9 @@ export class Volume {
for (let filename in json) {
const data = json[filename];

filename = resolve(filename, cwd);

if (typeof data === 'string') {
filename = resolve(filename, cwd);
const steps = filenameToSteps(filename);
if (steps.length > 1) {
const dirname = sep + steps.slice(0, steps.length - 1).join(sep);
Expand Down

0 comments on commit 3d6ee3b

Please sign in to comment.