Skip to content
This repository has been archived by the owner on Apr 6, 2021. It is now read-only.

Update VFS-local to work on Windows #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion localfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,6 @@ module.exports = function setup(fsOptions) {
} else {
options.env = fsOptions.defaultEnv;
}

childProcess.execFile(executablePath, options.args || [], options, function (err, stdout, stderr) {
if (err) {
err.stderr = stderr;
Expand Down
2 changes: 1 addition & 1 deletion test/node_modules/vfs-local

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 38 additions & 23 deletions test/test-local.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
/*global describe:false, it:false */

var expect = require('chai').expect;
var platform = require('os').platform();
var vfs_local = require("../localfs.js");
var path = require("path");

var STAT_SIZE = platform.match(/^win/) ? 24 : 23;
var EOL = platform.match(/^win/) ? "\r\n" : "\n";

describe('vfs-local', function () {

var root = __dirname + "/mock/";
var base = root.substr(0, root.length - 1);
var root = path.join(__dirname, "mock");
var base = root.substr(0, root.length);

var vfs = require('vfs-lint')(require("vfs-local")({
var vfs = require('vfs-lint')(vfs_local({
root: root,
defaultEnv: { CUSTOM: 43 },
checkSymlinks: true
}));

var vfsLoose = require('vfs-lint')(require("vfs-local")({
var vfsLoose = require('vfs-lint')(vfs_local({
root: root
}));

Expand All @@ -22,10 +28,10 @@ describe('vfs-local', function () {

describe('vfs.resolve()', function () {
it('should prepend root when resolving virtual paths', function (done) {
var vpath = "/dir/stuff.json";
var vpath = path.join("dir", "stuff.json");
vfs.resolve(vpath, {}, function (err, meta) {
if (err) throw err;
expect(meta).property("path").equals(base + vpath);
expect(meta).property("path").equals(path.join(base, vpath));
done();
});
});
Expand All @@ -36,10 +42,10 @@ describe('vfs-local', function () {
});
});
it('should not prepend when already rooted', function (done) {
var path = base + "/file.txt";
vfs.resolve(path, { alreadyRooted: true }, function (err, meta) {
var vpath = path.join(base, "file.txt");
vfs.resolve(vpath, { alreadyRooted: true }, function (err, meta) {
if (err) throw err;
expect(meta).property("path").equal(path);
expect(meta).property("path").equal(vpath);
done();
});
});
Expand All @@ -53,7 +59,7 @@ describe('vfs-local', function () {
var vpath = "/badpath.txt";
vfsLoose.resolve(vpath, {}, function (err, meta) {
if (err) throw err;
expect(meta).property("path").equal(base + vpath);
expect(meta).property("path").equal(path.join(base, vpath));
done();
});
});
Expand All @@ -64,7 +70,7 @@ describe('vfs-local', function () {
vfs.stat("/file.txt", {}, function (err, stat) {
if (err) throw err;
expect(stat).property("name").equal("file.txt");
expect(stat).property("size").equal(23);
expect(stat).property("size").equal(STAT_SIZE);
expect(stat).property("mime").equal("text/plain");
done();
});
Expand All @@ -82,7 +88,7 @@ describe('vfs-local', function () {
vfs.readfile("/file.txt", {}, function (err, meta) {
if (err) throw err;
expect(meta).property("mime").equals("text/plain");
expect(meta).property("size").equals(23);
expect(meta).property("size").equals(STAT_SIZE);
expect(meta).property("etag");
expect(meta).property("stream").property("readable");
var stream = meta.stream;
Expand All @@ -93,9 +99,9 @@ describe('vfs-local', function () {
length += chunk.length;
});
stream.on("end", function () {
expect(length).equal(23);
expect(length).equal(STAT_SIZE);
var body = chunks.join("");
expect(body).equal("This is a simple file!\n");
expect(body).equal("This is a simple file!" + EOL);
done();
});
});
Expand All @@ -116,7 +122,7 @@ describe('vfs-local', function () {
vfs.readfile("/file.txt", {head:true}, function (err, meta) {
if (err) throw err;
expect(meta).property("mime").equal("text/plain");
expect(meta).property("size").equal(23);
expect(meta).property("size").equal(STAT_SIZE);
expect(meta).property("mime").ok;
expect(meta.stream).not.ok;
done();
Expand All @@ -130,7 +136,7 @@ describe('vfs-local', function () {
vfs.readfile("/file.txt", {etag:etag}, function (err, meta) {
if (err) throw err;
expect(meta).property("mime").equal("text/plain");
expect(meta).property("size").equal(23);
expect(meta).property("size").equal(STAT_SIZE);
expect(meta).property("notModified").ok;
expect(meta.stream).not.ok;
done();
Expand All @@ -143,7 +149,7 @@ describe('vfs-local', function () {
expect(meta).property("mime").equal("text/plain");
expect(meta).property("size").equal(3);
expect(meta).property("etag").ok;
expect(meta).property("partialContent").deep.equal({ start: 1, end: 3, size: 23 });
expect(meta).property("partialContent").deep.equal({ start: 1, end: 3, size: STAT_SIZE });
expect(meta).property("stream").ok;
var stream = meta.stream;
var chunks = [];
Expand All @@ -162,7 +168,14 @@ describe('vfs-local', function () {
if (err) throw err;
expect(meta).property("size").equal(10);
expect(meta).property("etag").ok;
expect(meta).property("partialContent").deep.equal({ start: 13, end: 22, size: 23 });

if (platform.match(/^win/)) {
expect(meta).property("partialContent").deep.equal({ start: 14, end: 23, size: STAT_SIZE });
}
else {
expect(meta).property("partialContent").deep.equal({ start: 13, end: 22, size: STAT_SIZE });
}

done();
});
});
Expand Down Expand Up @@ -205,8 +218,10 @@ describe('vfs-local', function () {
done();
});
});
it("should error with ENOTDIR when the path is a file", function (done) {
vfs.readdir("/file.txt", {}, function (err, meta) {
it("should error with ENOTDIR when the path is a file (or ENOENT on Windows)", function (done) {
// see https://github.com/joyent/node/issues/1869
var error_code = platform.match(/^win/) ? "ENOENT" : "ENOTDIR";
vfs.readdir("./file.txt", {}, function (err, meta) {
expect(err).property("code").equal("ENOTDIR");
done();
});
Expand Down Expand Up @@ -274,7 +289,7 @@ describe('vfs-local', function () {
});
});
});
it("should update an existing file using readble in options", function (done) {
it("should update an existing file using readable in options", function (done) {
var vpath = "/changeme.txt";
var stream = fs.createReadStream(__filename);
fs.writeFileSync(base + vpath, "Original Content\n");
Expand Down Expand Up @@ -489,8 +504,8 @@ describe('vfs-local', function () {
describe('vfs.symlink()', function () {
it("should create a symlink", function (done) {
var target = "file.txt";
var vpath = "/newlink.txt";
var text = fs.readFileSync(root + target, "utf8");
var vpath = "newlink.txt";
var text = fs.readFileSync(path.join(root, target), "utf8");
vfs.symlink(vpath, {target: target}, function (err, meta) {
if (err) throw err;
expect(fs.readFileSync(base + vpath, "utf8")).equal(text);
Expand Down