smartfile/test/test.js

187 lines
30 KiB
JavaScript
Raw Normal View History

2016-04-04 13:44:00 +00:00
"use strict";
require("typings-test");
2016-06-23 16:31:55 +00:00
var smartfile = require("../dist/index");
2016-02-03 11:52:09 +00:00
var beautylog = require("beautylog");
2016-04-04 13:44:00 +00:00
var gulp = require("gulp");
var gFunction = require("gulp-function");
2016-02-03 11:52:09 +00:00
var should = require("should");
var vinyl = require("vinyl");
describe("smartfile".yellow, function () {
2016-06-23 16:31:55 +00:00
describe(".fs".yellow, function () {
2016-02-04 13:21:48 +00:00
describe(".fileExistsSync".yellow, function () {
it("should return an accurate boolean", function () {
2016-06-23 16:31:55 +00:00
(smartfile.fs.fileExistsSync("./test/mytest.json")).should.be.true();
(smartfile.fs.fileExistsSync("./test/notthere.json")).should.be.false();
2016-02-04 13:21:48 +00:00
});
});
describe(".fileExists".yellow, function () {
it("should return a working promise", function () {
2016-06-23 16:31:55 +00:00
(smartfile.fs.fileExists("./test/mytest.json")).should.be.Promise();
(smartfile.fs.fileExists("./test/mytest.json")).should.be.fulfilled();
(smartfile.fs.fileExists("./test/notthere.json")).should.not.be.fulfilled();
});
});
2016-06-23 16:39:02 +00:00
describe(".listFoldersSync()", function () {
2016-06-23 16:31:55 +00:00
it("should get the file type from a string", function () {
2016-06-23 16:39:02 +00:00
smartfile.fs.listFoldersSync("./test/").should.containDeep(["testfolder"]);
smartfile.fs.listFoldersSync("./test/").should.not.containDeep(["notExistentFolder"]);
2016-06-23 16:31:55 +00:00
});
});
2016-06-23 16:39:02 +00:00
describe(".listFolders()", function () {
2016-06-23 16:31:55 +00:00
it("should get the file type from a string", function (done) {
2016-06-23 16:39:02 +00:00
smartfile.fs.listFolders("./test/")
2016-06-23 16:31:55 +00:00
.then(function (folderArrayArg) {
folderArrayArg.should.containDeep(["testfolder"]);
folderArrayArg.should.not.containDeep(["notExistentFolder"]);
done();
});
2016-02-04 13:21:48 +00:00
});
});
describe(".copy()".yellow, function () {
it("should copy a directory", function () {
2016-06-23 16:31:55 +00:00
smartfile.fs.copy("./test/testfolder/", "./test/temp/");
});
it("should copy a file", function () {
2016-06-23 16:31:55 +00:00
smartfile.fs.copy("./test/mytest.yaml", "./test/temp/");
});
it("should copy a file and rename it", function () {
2016-06-23 16:31:55 +00:00
smartfile.fs.copy("./test/mytest.yaml", "./test/temp/mytestRenamed.yaml");
});
});
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-03-20 23:28:29 +00:00
});
});
2016-06-23 16:31:55 +00:00
describe(".interpreter", function () {
describe(".filetype()", function () {
it("should get the file type from a string", function () {
2016-06-23 16:31:55 +00:00
smartfile.interpreter.filetype("./somefolder/data.json").should.equal("json");
});
});
});
2016-06-23 16:31:55 +00:00
describe(".fs".yellow, function () {
2016-03-19 21:07:59 +00:00
describe("toGulpStreamSync() and toGulpDestSync", function () {
it("should produce a gulp stream", function (done) {
2016-06-23 16:31:55 +00:00
smartfile.fs.toGulpStreamSync("./test/my*")
.pipe(smartfile.fs.toGulpDestSync("./test/temp/"))
2016-03-19 21:07:59 +00:00
.pipe(gFunction(done, "atEnd"));
});
2016-03-14 02:50:14 +00:00
});
describe(".toObjectSync()".yellow, function () {
it("should read an " + ".yaml".blue + " file to an object", function () {
2016-06-23 16:31:55 +00:00
var testData = smartfile.fs.toObjectSync("./test/mytest.yaml");
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-06-23 16:31:55 +00:00
var testData = smartfile.fs.toObjectSync("./test/mytest.txt");
});
it("should read an " + ".json".blue + " file to an object", function () {
2016-06-23 16:31:55 +00:00
var testData = smartfile.fs.toObjectSync("./test/mytest.json");
testData.should.have.property("key1", "this works");
testData.should.have.property("key2", "this works too");
});
2016-03-14 02:50:14 +00:00
});
2016-03-19 21:07:59 +00:00
describe(".toStringSync()".yellow, function () {
it("should read a file to a string", function () {
2016-06-23 16:31:55 +00:00
should.equal(smartfile.fs.toStringSync("./test/mytest.txt"), "Some TestString &&%$");
2016-03-19 21:07:59 +00:00
});
});
describe(".toVinylSync".yellow, function () {
it("should read an " + ".json OR .yaml".blue + " file to an " + "vinyl file object".cyan, function () {
2016-06-23 16:31:55 +00:00
var testData = smartfile.fs.toVinylSync("./test/mytest.json");
(vinyl.isVinyl(testData)).should.be.true();
});
});
});
2016-04-04 13:44:00 +00:00
describe(".memory", function () {
describe(".toGulpStream()", function () {
it("should produce a valid gulp stream", function () {
var localArray = ["test1", "test2", "test3"];
smartfile.memory.toGulpStream(localArray)
.pipe(gulp.dest("./test/temp/"));
});
});
describe("toVinylFileSync()", function () {
it("should produce a vinylFile", function () {
var localString = "myString";
var 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 () {
var localStringArray = ["string1", "string2", "string3"];
var localOptions = { filename: "vinylfile2", base: "/someDir" };
var testResult = smartfile.memory.toVinylArraySync(localStringArray, localOptions);
testResult.should.be.Array();
(testResult.length === 3).should.be.true();
for (var myKey in testResult) {
(testResult[myKey] instanceof vinyl).should.be.true();
}
});
});
describe("toStringSync()", function () {
it("should produce a String from vinyl file", function () {
var 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) {
var 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 () {
var localString = "myString";
smartfile.memory.toFsSync(localString, {
fileName: "./test/temp/testMemToFsSync.txt",
filePath: process.cwd()
});
});
});
});
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/")
2016-06-23 16:31:55 +00:00
.pipe(smartfile.fs.toGulpDestSync("./test/temp/"))
2016-03-19 21:07:59 +00:00
.pipe(gFunction(done, "atEnd"));
});
});
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);
smartfile.remote.toString("https://push.rocks/doesnotexist.txt")
.then(function () {
throw new Error("this test should not be resolved");
}, function () {
done();
});
});
2016-03-14 02:50:14 +00:00
});
});
2016-02-03 11:52:09 +00:00
});
2016-06-23 16:39:02 +00:00
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFDdEIsSUFBWSxTQUFTLFdBQU0sZUFBZSxDQUFDLENBQUE7QUFDM0MsSUFBSSxTQUFTLEdBQUcsT0FBTyxDQUFDLFdBQVcsQ0FBQyxDQUFDO0FBQ3JDLElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxNQUFNLENBQUMsQ0FBQztBQUMzQixJQUFJLFNBQVMsR0FBRyxPQUFPLENBQUMsZUFBZSxDQUFDLENBQUM7QUFDekMsSUFBTyxNQUFNLFdBQVcsUUFBUSxDQUFDLENBQUM7QUFDbEMsSUFBSSxLQUFLLEdBQUcsT0FBTyxDQUFDLE9BQU8sQ0FBQyxDQUFDO0FBRTdCLFFBQVEsQ0FBQyxXQUFXLENBQUMsTUFBTSxFQUFDO0lBR3hCLFFBQVEsQ0FBQyxLQUFLLENBQUMsTUFBTSxFQUFDO1FBQ2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