Skip to content

Commit

Permalink
fix funky history passing, closes #35
Browse files Browse the repository at this point in the history
  • Loading branch information
Contra committed Sep 1, 2014
1 parent f33d6d5 commit d220c85
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
23 changes: 13 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ function File(file) {
if (!file) file = {};

// record path change
this.history = file.path ? [file.path] : [];
var history = file.path ? [file.path] : file.history;
this.history = history || [];

// TODO: should this be moved to vinyl-fs?
this.cwd = file.cwd || process.cwd();
Expand Down Expand Up @@ -59,21 +60,23 @@ File.prototype.clone = function(opt) {
opt.contents = opt.contents !== false;
}

var file = new File({
cwd: this.cwd,
base: this.base,
stat: (this.stat ? cloneStats(this.stat) : null)
});
file.history = this.history.slice();

// clone our file contents
var contents;
if (this.isStream()) {
file.contents = this.contents.pipe(new Stream.PassThrough());
contents = this.contents.pipe(new Stream.PassThrough());
this.contents = this.contents.pipe(new Stream.PassThrough());
} else if (this.isBuffer()) {
file.contents = opt.contents ? cloneBuffer(this.contents) : this.contents;
contents = opt.contents ? cloneBuffer(this.contents) : this.contents;
}

var file = new File({
cwd: this.cwd,
base: this.base,
stat: (this.stat ? cloneStats(this.stat) : null),
history: this.history.slice(),
contents: contents
});

// clone our custom properties
Object.keys(this).forEach(function(key) {
// ignore built-in fields
Expand Down
15 changes: 15 additions & 0 deletions test/File.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ describe('File', function() {
done();
});

it('should default history to []', function(done) {
var file = new File();
file.history.should.eql([]);
done();
});

it('should default stat to null', function(done) {
var file = new File();
should.not.exist(file.stat);
Expand Down Expand Up @@ -64,6 +70,15 @@ describe('File', function() {
var val = '/test.coffee';
var file = new File({path: val});
file.path.should.equal(val);
file.history.should.eql([val]);
done();
});

it('should set history to given value', function(done) {
var val = '/test.coffee';
var file = new File({history: [val]});
file.path.should.equal(val);
file.history.should.eql([val]);
done();
});

Expand Down

0 comments on commit d220c85

Please sign in to comment.