Skip to content

Commit

Permalink
adding contents and path fields
Browse files Browse the repository at this point in the history
  • Loading branch information
MiguelCastillo committed Jan 3, 2018
1 parent 2f7a824 commit aefdbcd
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
14 changes: 11 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ function File(options, cwd) {
configurator.configure(this, options);
}

File.prototype.setPath = function(path) {
this.path = path;
return this;
};

File.prototype.setContents = function(contents) {
this.contents = contents;
return this;
};

File.prototype.setSrc = function(files) {
this.src = src(files, this.cwd, this.resolve);
return this;
Expand Down Expand Up @@ -65,9 +75,7 @@ function src(files, cwd, resolve) {
}

function dest(file, cwd) {
return types.isString(file) ?
path.isAbsolute(file) ? file : path.join(cwd, file) :
file;
return types.isString(file) ? (path.isAbsolute(file) ? file : path.join(cwd, file)) : file;
}

module.exports = File;
Expand Down
46 changes: 46 additions & 0 deletions test/spec/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,52 @@ describe("File unit test", function() {
});
});

describe("When creating a File with contents", function() {
const fileContents = "console.log('hello world')";

beforeEach(function() {
options = {
contents: fileContents
};
act();
});

it("then the file has no items in source", function() {
expect(result.src).to.have.lengthOf(0);
});

it("then the current directory contains src-dest", function() {
expect(result.cwd).to.contain("/src-dest");
});

it("then the file contents is what the file was configured with", function() {
expect(result.contents).to.equal(fileContents);
});
});

describe("When creating a File with a path", function() {
const filePath = "./some-random/path.js";

beforeEach(function() {
options = {
path: filePath
};
act();
});

it("then the file has no items in source", function() {
expect(result.src).to.have.lengthOf(0);
});

it("then the current directory contains src-dest", function() {
expect(result.cwd).to.contain("/src-dest");
});

it("then the file path is what the file was configured with", function() {
expect(result.path).to.equal(filePath);
});
});

describe("When creating a File with only a string as the input", function() {
beforeEach(function() {
options = "test/spec/file.js";
Expand Down

0 comments on commit aefdbcd

Please sign in to comment.