diff --git a/index.js b/index.js index d99094e..3a16e91 100644 --- a/index.js +++ b/index.js @@ -128,6 +128,10 @@ File.prototype.clone = function(opt) { contents: contents, }); + if (this.isSymbolic()) { + file.symlink = this.symlink; + } + // Clone our custom properties Object.keys(this).forEach(function(key) { if (self.constructor.isCustomProp(key)) { diff --git a/test/file.js b/test/file.js index 27e5dac..2a4636c 100644 --- a/test/file.js +++ b/test/file.js @@ -419,6 +419,12 @@ describe('File', function() { describe('clone()', function() { + var fakeStat = { + isSymbolicLink: function() { + return true; + }, + }; + it('copies all attributes over with Buffer contents', function(done) { var options = { cwd: '/', @@ -577,6 +583,24 @@ describe('File', function() { ], done); }); + it('fixes file.symlink if file is a symbolic link', function(done) { + var val = '/test/test.js'; + var options = { + cwd: '/', + base: '/test/', + path: '/test/test.coffee', + content: null, + stat: fakeStat, + symlink: val, + }; + var file = new File(options); + var file2 = file.clone(); + + expect(file2).toNotBe(file); + expect(file2.symlink).toEqual(file.symlink); + done(); + }); + it('copies all attributes over with null contents', function(done) { var options = { cwd: '/',