2016-03-14 02:50:14 +00:00
|
|
|
/// <reference path="../ts/typings/main.d.ts" />
|
2016-03-19 21:07:59 +00:00
|
|
|
let smartfile = require("../dist/index.js");
|
|
|
|
let beautylog = require("beautylog");
|
2016-04-04 13:44:00 +00:00
|
|
|
let gulp = require("gulp");
|
2016-03-19 21:07:59 +00:00
|
|
|
let gFunction = require("gulp-function");
|
2016-04-04 13:44:00 +00:00
|
|
|
import should = require("should");
|
|
|
|
let vinyl = require("vinyl");
|
2016-03-14 02:50:14 +00:00
|
|
|
|
2016-03-18 16:34:31 +00:00
|
|
|
describe("smartfile".yellow,function(){
|
2016-02-04 13:21:48 +00:00
|
|
|
describe(".checks".yellow,function(){
|
|
|
|
describe(".fileExistsSync".yellow,function(){
|
|
|
|
it("should return an accurate boolean",function(){
|
|
|
|
(smartfile.checks.fileExistsSync("./test/mytest.json")).should.be.true();
|
|
|
|
(smartfile.checks.fileExistsSync("./test/notthere.json")).should.be.false();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe(".fileExists".yellow,function(){
|
|
|
|
it("should return a working promise",function(){
|
|
|
|
(smartfile.checks.fileExists("./test/mytest.json")).should.be.Promise();
|
|
|
|
(smartfile.checks.fileExists("./test/mytest.json")).should.be.fulfilled();
|
|
|
|
(smartfile.checks.fileExists("./test/notthere.json")).should.not.be.fulfilled();
|
|
|
|
});
|
|
|
|
})
|
|
|
|
});
|
2016-04-04 13:44:00 +00:00
|
|
|
|
|
|
|
|
2016-03-18 16:34:31 +00:00
|
|
|
describe(".fsaction".yellow,function(){
|
|
|
|
describe(".copy()".yellow,function(){
|
|
|
|
it("should copy a directory",function(){
|
2016-03-19 21:07:59 +00:00
|
|
|
smartfile.fsaction.copy("./test/testfolder/","./test/temp/")
|
2016-03-18 16:34:31 +00:00
|
|
|
});
|
|
|
|
it("should copy a file",function(){
|
2016-03-19 21:07:59 +00:00
|
|
|
smartfile.fsaction.copy("./test/mytest.yaml","./test/temp/")
|
2016-03-18 16:34:31 +00:00
|
|
|
});
|
|
|
|
it("should copy a file and rename it",function(){
|
2016-03-19 21:07:59 +00:00
|
|
|
smartfile.fsaction.copy("./test/mytest.yaml","./test/temp/mytestRenamed.yaml")
|
2016-03-18 16:34:31 +00:00
|
|
|
});
|
2016-03-14 02:50:14 +00:00
|
|
|
});
|
2016-03-20 23:28:29 +00:00
|
|
|
describe(".remove()",function(){
|
|
|
|
it("should remove an entire directory",function(){
|
|
|
|
|
|
|
|
});
|
2016-04-02 21:03:18 +00:00
|
|
|
it("should remove single files",function(){
|
2016-04-04 13:44:00 +00:00
|
|
|
|
2016-04-02 21:03:18 +00:00
|
|
|
});
|
2016-03-20 23:28:29 +00:00
|
|
|
});
|
2016-03-18 16:34:31 +00:00
|
|
|
});
|
2016-04-04 13:44:00 +00:00
|
|
|
|
|
|
|
|
2016-03-18 16:34:31 +00:00
|
|
|
describe(".local".yellow,function(){
|
2016-03-19 21:07:59 +00:00
|
|
|
describe("toGulpStreamSync() and toGulpDestSync",function(){
|
|
|
|
it("should produce a gulp stream",function(done){
|
|
|
|
smartfile.local.toGulpStreamSync("./test/my*")
|
|
|
|
.pipe(smartfile.local.toGulpDestSync("./test/temp/"))
|
|
|
|
.pipe(gFunction(done,"atEnd"));
|
2016-03-18 16:34:31 +00:00
|
|
|
});
|
2016-03-14 02:50:14 +00:00
|
|
|
});
|
2016-03-18 16:34:31 +00:00
|
|
|
describe(".toObjectSync()".yellow,function(){
|
|
|
|
it("should read an " + ".yaml".blue + " file to an object",function(){
|
2016-03-19 21:07:59 +00:00
|
|
|
let testData = smartfile.local.toObjectSync("./test/mytest.yaml");
|
2016-03-18 16:34:31 +00:00
|
|
|
testData.should.have.property("key1","this works");
|
|
|
|
testData.should.have.property("key2","this works too");
|
|
|
|
|
|
|
|
});
|
|
|
|
it("should state unknown file type for unknown file types",function(){
|
2016-03-19 21:07:59 +00:00
|
|
|
let testData = smartfile.local.toObjectSync("./test/mytest.txt");
|
2016-03-18 16:34:31 +00:00
|
|
|
});
|
|
|
|
it("should read an " + ".json".blue + " file to an object",function(){
|
2016-03-19 21:07:59 +00:00
|
|
|
let testData = smartfile.local.toObjectSync("./test/mytest.json");
|
2016-03-18 16:34:31 +00:00
|
|
|
testData.should.have.property("key1","this works");
|
|
|
|
testData.should.have.property("key2","this works too");
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
2016-03-19 21:07:59 +00:00
|
|
|
describe(".toStringSync()".yellow,function(){
|
|
|
|
it("should read a file to a string",function(){
|
|
|
|
should.equal(
|
|
|
|
smartfile.local.toStringSync("./test/mytest.txt"),
|
|
|
|
"Some TestString &&%$"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2016-03-18 16:34:31 +00:00
|
|
|
describe(".toVinylSync".yellow,function(){
|
|
|
|
it("should read an " + ".json OR .yaml".blue + " file to an " + "vinyl file object".cyan,function(){
|
2016-03-19 21:07:59 +00:00
|
|
|
let testData = smartfile.local.toVinylSync("./test/mytest.json");
|
2016-03-18 16:34:31 +00:00
|
|
|
(vinyl.isVinyl(testData)).should.be.true();
|
|
|
|
|
|
|
|
});
|
2016-03-14 02:50:14 +00:00
|
|
|
});
|
|
|
|
});
|
2016-04-04 13:44:00 +00:00
|
|
|
|
|
|
|
describe(".memory",function(){
|
|
|
|
describe(".toGulpStream()",function(){
|
|
|
|
it("should produce a valid gulp stream",function(){
|
|
|
|
let localArray = ["test1","test2","test3"];
|
|
|
|
smartfile.memory.toGulpStream(localArray)
|
|
|
|
.pipe(gulp.dest("./test/temp/"));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe("toVinylFileSync()",function(){
|
|
|
|
it("should produce a vinylFile",function(){
|
|
|
|
let localString = "myString";
|
|
|
|
let localOptions = {filename:"vinylfile2",base:"/someDir"};
|
|
|
|
(smartfile.memory.toVinylFileSync(localString,localOptions) instanceof vinyl).should.be.true();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe("toVinylArraySync()",function(){
|
|
|
|
it("should produce a an array of vinylfiles",function(){
|
|
|
|
let localStringArray = ["string1","string2","string3"];
|
|
|
|
let localOptions = {filename:"vinylfile2",base:"/someDir"};
|
|
|
|
let testResult = smartfile.memory.toVinylArraySync(localStringArray,localOptions);
|
|
|
|
testResult.should.be.Array();
|
|
|
|
(testResult.length === 3).should.be.true();
|
|
|
|
for (let myKey in testResult){
|
|
|
|
(testResult[myKey] instanceof vinyl).should.be.true();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe("toStringSync()",function(){
|
|
|
|
it("should produce a String from vinyl file",function(){
|
|
|
|
let localString = smartfile.memory.toStringSync(new vinyl({
|
|
|
|
base:"/",
|
|
|
|
path:"/test.txt",
|
|
|
|
contents: new Buffer("myString")
|
|
|
|
}));
|
|
|
|
localString.should.equal("myString");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe("toFs()",function(){
|
|
|
|
it("should write a file to disk and return a promise",function(done){
|
|
|
|
let localString = "myString";
|
|
|
|
smartfile.memory.toFs(
|
|
|
|
localString,
|
|
|
|
{
|
|
|
|
fileName:"./test/temp/testMemToFs.txt",
|
|
|
|
filePath:process.cwd()
|
|
|
|
}
|
|
|
|
).then(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe("toFsSync()",function(){
|
|
|
|
it("should write a file to disk and return true if successfull",function(){
|
|
|
|
let localString = "myString";
|
|
|
|
smartfile.memory.toFsSync(
|
|
|
|
localString,{
|
|
|
|
fileName:"./test/temp/testMemToFsSync.txt",
|
|
|
|
filePath:process.cwd()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-03-18 16:34:31 +00:00
|
|
|
describe(".remote",function(){
|
2016-03-19 21:07:59 +00:00
|
|
|
describe("toGulpStreamSync()",function(){
|
|
|
|
it("should produce a gulp stream",function(done){
|
|
|
|
smartfile.remote.toGulpStreamSync("mytest.txt","https://raw.githubusercontent.com/pushrocks/smartfile/master/test/")
|
|
|
|
.pipe(smartfile.local.toGulpDestSync("./test/temp/"))
|
|
|
|
.pipe(gFunction(done,"atEnd"));
|
|
|
|
});
|
|
|
|
});
|
2016-03-18 16:34:31 +00:00
|
|
|
describe(".toString()",function(){
|
|
|
|
it("should load a remote file to a variable",function(done){
|
|
|
|
this.timeout(5000);
|
|
|
|
smartfile.remote.toString("https://raw.githubusercontent.com/pushrocks/smartfile/master/test/mytest.txt")
|
|
|
|
.then(function(responseString){
|
|
|
|
should.equal(responseString,"Some TestString &&%$");
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it("should reject a Promise when the link is false",function(done){
|
2016-04-02 21:03:18 +00:00
|
|
|
this.timeout(10000);
|
2016-03-18 16:34:31 +00:00
|
|
|
smartfile.remote.toString("https://push.rocks/doesnotexist.txt")
|
|
|
|
.then(function(){
|
|
|
|
throw new Error("this test should not be resolved");
|
|
|
|
},function(){
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})
|
2016-02-03 11:52:09 +00:00
|
|
|
});
|