2016-03-14 02:50:14 +00:00
|
|
|
/// <reference path="../ts/typings/main.d.ts" />
|
|
|
|
var smartfile = require("../dist/index.js");
|
2016-02-03 11:52:09 +00:00
|
|
|
var beautylog = require("beautylog");
|
|
|
|
var should = require("should");
|
|
|
|
var vinyl = require("vinyl");
|
2016-03-19 21:07:59 +00:00
|
|
|
var gFunction = require("gulp-function");
|
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-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-20 23:28:29 +00:00
|
|
|
describe(".remove()", function () {
|
|
|
|
it("should remove an entire directory", function () {
|
|
|
|
});
|
|
|
|
it("should remove single files");
|
|
|
|
});
|
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 () {
|
|
|
|
var testData = smartfile.local.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 () {
|
|
|
|
var testData = smartfile.local.toObjectSync("./test/mytest.txt");
|
|
|
|
});
|
|
|
|
it("should read an " + ".json".blue + " file to an object", function () {
|
|
|
|
var testData = smartfile.local.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 () {
|
|
|
|
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 () {
|
|
|
|
var testData = smartfile.local.toVinylSync("./test/mytest.json");
|
|
|
|
(vinyl.isVinyl(testData)).should.be.true();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
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) {
|
|
|
|
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-03-18 09:19:46 +00:00
|
|
|
|
2016-03-20 23:28:29 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsZ0RBQWdEO0FBQ2hELElBQUksU0FBUyxHQUFHLE9BQU8sQ0FBQyxrQkFBa0IsQ0FBQyxDQUFDO0FB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