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

/undefined path being created when passing '/' #204

Open
feliupe opened this issue Apr 19, 2017 · 0 comments
Open

/undefined path being created when passing '/' #204

feliupe opened this issue Apr 19, 2017 · 0 comments

Comments

@feliupe
Copy link

feliupe commented Apr 19, 2017

If you run mock({'/': {}}) on linux '/undefined' will be created in the mocked filesystem.

I think the problem is here, it returns [] if you input '/':

  • filesystem.js
function getPathParts(filepath) {
    
  var parts = path._makeLong(path.resolve(filepath)).split(path.sep);
  parts.shift();
  if (isWindows) {
    // parts currently looks like ['', '?', 'c:', ...]
    parts.shift();
    var q = parts.shift(); // should be '?'
    var base = '\\\\' + q + '\\' + parts.shift().toLowerCase();
    parts.unshift(base);
  }
  if (parts[parts.length - 1] === '') {
    parts.pop();
  }
  return parts;
}

When it returns to FileSystem.create :

FileSystem.create = function(paths, options) {
  var system = new FileSystem(options);
  console.log(paths, Object.keys(paths).length)
  for (var filepath in paths) {
    var parts = getPathParts(filepath);
    var directory = system._root;
    var i, ii, name, candidate;
    for (i = 0, ii = parts.length - 1; i < ii; ++i) {
      name = parts[i];
      candidate = directory.getItem(name);
      if (!candidate) {
        directory = directory.addItem(name, new Directory());
      } else if (candidate instanceof Directory) {
        directory = candidate;
      } else {
        throw new Error('Failed to create directory: ' + filepath);
      }
    }
    console.log(parts[i], parts)

    populate(directory, parts[i], paths[filepath]);
  }

  return system;
};

It enters the loop and get undefined in parts[i].

So, this is a bug?

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

1 participant