exclude files from SDK

pull/128/merge
Fabian Jakobs 2016-01-18 14:18:09 +00:00
rodzic e8dcd182f8
commit 34ce6d9e9a
2 zmienionych plików z 180 dodań i 0 usunięć

Wyświetl plik

@ -0,0 +1,142 @@
#!/usr/bin/env node
/*global describe it before after beforeEach afterEach */
"use strict";
"use server";
require("c9/inline-mocha")(module);
var assert = require("assert-diff");
var async = require("async");
var sinon = require("sinon");
var vfs = require("vfs-local");
var vfsProxy = require("./vfs_proxy");
describe(__filename, function(){
var proxy, home, workspace;
before(function() {
home = vfs({
root: __dirname,
testing: true,
checkSymlinks: true
});
home.root = __dirname;
workspace = vfs({
root: __dirname + "/views",
testing: true,
checkSymlinks: true
});
});
beforeEach(function() {
proxy = vfsProxy(Object.keys(home), home, workspace);
});
it("should use home for files starting with ~ ", function(done) {
home.readfile = sinon.stub().callsArgWith(2, null, "home");
workspace.readfile = sinon.stub().callsArgWith(2, null, "workspace");
proxy.readfile("~/foo.txt", {}, function(err, data) {
assert(!err, err);
assert.equal(data, "home");
done();
});
});
it("should use workspace for files not starting with ~ ", function(done) {
home.readfile = sinon.stub().callsArgWith(2, null, "home");
workspace.readfile = sinon.stub().callsArgWith(2, null, "workspace");
proxy.readfile("foo.txt", {}, function(err, data) {
assert(!err, err);
assert.equal(data, "workspace");
done();
});
});
it("should expand ~ to paths relative to 'home'", function(done) {
home.readfile = function(path, options, callback) {
assert.equal(path, "/foo.txt");
callback(null, "home");
};
proxy.readfile("~/foo.txt", {}, function(err, data) {
assert(!err, err);
assert.equal(data, "home");
done();
});
});
it("should expand ~ in options", function(done) {
home.readfile = function(path, options, callback) {
assert.equal(path, "/foo.txt");
assert.equal(options.target, "/bar");
assert.equal(options.to, "/juhu");
assert.equal(options.from, "/kinners");
assert.equal(options.stuff, "~/stuff");
callback(null, "home");
};
proxy.readfile("~/foo.txt", {
target: "~/bar",
to: "~/juhu",
from: "~/kinners",
stuff: "~/stuff"
}, function(err, data) {
assert(!err, err);
assert.equal(data, "home");
done();
});
});
it("should expand some commands to absolute paths", function(done) {
home.execFile = function(path, options, callback) {
assert.equal(path, __dirname + "/foo.txt");
callback(null, "home");
};
proxy.execFile("~/foo.txt", {}, function(err, data) {
assert(!err, err);
assert.equal(data, "home");
done();
});
});
it("should not wrap some commands", function(done) {
async.eachSeries([
"connect",
"on",
"off",
"emit",
"extend",
"unextend",
"use",
"killtree"
], function(cmd, next) {
workspace[cmd] = function(path, options, callback) {
assert.equal(path, "~/foo.txt");
callback(null, "workspace");
};
proxy[cmd]("~/foo.txt", {}, function(err, data) {
assert(!err, err);
assert.equal(data, "workspace");
next();
});
}, done);
});
it("bad execFile arguments should not break the server", function(done) {
workspace.execFile = sinon.stub().callsArgWith(2, null, "done");
proxy.execFile(['ls', '-a'], {encoding: "utf8"}, function(err, data) {
assert(!err, err);
assert.equal(data, "done");
done();
});
});
});

Wyświetl plik

@ -0,0 +1,38 @@
#!/usr/bin/env node
/*global describe it before after beforeEach afterEach */
"use strict";
"use server";
require("c9/inline-mocha")(module);
var assert = require("assert-diff");
var path = require("path");
var vfs = require("vfs-local");
var vfsWrapper = require("./vfs_wrapper");
describe(__filename, function(){
describe("#extend", function() {
var wrapper;
beforeEach(function() {
var home = vfs({
root: path.normalize(__dirname + "/.."),
testing: true,
});
wrapper = vfsWrapper(home, {
root: __dirname
});
});
it("should return an error if file is not passed", function(done) {
wrapper.extend('foo', { file: {} ,encoding: "utf8"}, function(err, data) {
assert(err);
assert.equal(err.message, "Invalid option 'file'");
done();
});
});
});
});