62 lines
10 KiB
JavaScript
62 lines
10 KiB
JavaScript
/// <reference path="../ts/typings/main.d.ts" />
|
|
var smartfile = require("../dist/index.js");
|
|
var beautylog = require("beautylog");
|
|
var should = require("should");
|
|
var vinyl = require("vinyl");
|
|
describe("smartfile", function () {
|
|
describe(".readFileToString".yellow, function () {
|
|
it("should read a file to a string", function () {
|
|
should.equal(smartfile.readFileToString("./test/mytest.txt"), "Some TestString &&%$");
|
|
});
|
|
});
|
|
describe(".readFileToObject".yellow, function () {
|
|
it("should read an " + ".yaml".blue + " file to an object", function () {
|
|
var testData = smartfile.readFileToObject("./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.readFileToObject("./test/mytest.txt");
|
|
});
|
|
it("should read an " + ".json".blue + " file to an object", function () {
|
|
var testData = smartfile.readFileToObject("./test/mytest.json");
|
|
testData.should.have.property("key1", "this works");
|
|
testData.should.have.property("key2", "this works too");
|
|
});
|
|
});
|
|
describe(".readFileToVinyl".yellow, function () {
|
|
it("should read an " + ".json OR .yaml".blue + " file to an " + "vinyl file object".cyan, function () {
|
|
var testData = smartfile.readFileToVinyl("./test/mytest.json");
|
|
(vinyl.isVinyl(testData)).should.be.true();
|
|
});
|
|
});
|
|
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();
|
|
});
|
|
});
|
|
});
|
|
describe("copy", function () {
|
|
it("should copy a directory", function () {
|
|
smartfile.copy("./test/testfolder/", "./test/assets/");
|
|
});
|
|
it("should copy a file", function () {
|
|
smartfile.copy("./test/mytest.yaml", "./test/assets/");
|
|
});
|
|
it("should copy a file and rename it", function () {
|
|
smartfile.copy("./test/mytest.yaml", "./test/assets/mytestRenamed.yaml");
|
|
});
|
|
});
|
|
});
|
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsZ0RBQWdEO0FBQ2hELElBQUksU0FBUyxHQUFHLE9BQU8sQ0FBQyxrQkFBa0IsQ0FBQyxDQUFDO0FBQzVDLElBQUksU0FBUyxHQUFHLE9BQU8sQ0FBQyxXQUFXLENBQUMsQ0FBQztBQUNyQyxJQUFJLE1BQU0sR0FBRyxPQUFPLENBQUMsUUFBUSxDQUFDLENBQUM7QUFDL0IsSUFBSSxLQUFLLEdBQUcsT0FBTyxDQUFDLE9BQU8sQ0FBQyxDQUFDO0FBRTdCLFFBQVEsQ0FBQyxXQUFXLEVBQUM7SUFDakIsUUFBUSxDQUFDLG1CQUFtQixDQUFDLE1BQU0sRUFBQztRQUNoQyxFQUFFLENBQUMsZ0NBQWdDLEVBQUM7WUFDaEMsTUFBTSxDQUFDLEtBQUssQ0FDUixTQUFTLENBQUMsZ0JBQWdCLENBQUMsbUJBQW1CLENBQUMsRUFDL0Msc0JBQXNCLENBQ3pCLENBQUM7UUFDTixDQUFDLENBQUMsQ0FBQztJQUNQLENBQUMsQ0FBQyxDQUFDO0lBQ0gsUUFBUSxDQUFDLG1CQUFtQixDQUFDLE1BQU0sRUFBQztRQUNoQyxFQUFFLENBQUMsaUJBQWlCLEdBQUcsT0FBTyxDQUFDLElBQUksR0FBRyxvQkFBb0IsRUFBQztZQUN2RCxJQUFJLFFBQVEsR0FBRyxTQUFTLENBQUMsZ0JBQWdCLENBQUMsb0JBQW9CLEN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