diff --git a/lib/project-item.js b/lib/project-item.js index db20835b..e119e3bd 100644 --- a/lib/project-item.js +++ b/lib/project-item.js @@ -51,7 +51,8 @@ exports.ProjectItem = class { create(relativeTo) { let fullPath = relativeTo ? this.calculateRelativePath(relativeTo) : this.name; - if (this.isDirectory) { + // Skip empty folder + if (this.isDirectory && this.children.length) { return fs.stat(fullPath) .then(result => result) .catch(() => fs.mkdir(fullPath)) diff --git a/spec/lib/project-item.spec.js b/spec/lib/project-item.spec.js index 7bddec2d..ee6598f4 100644 --- a/spec/lib/project-item.spec.js +++ b/spec/lib/project-item.spec.js @@ -48,7 +48,7 @@ describe('The ProjectItem module', () => { expect(fs.readFileSync(path.join('folder', 'deepFolder', 'file4.js'))).toBe('file4'); }); - it('Overwrites existing file', async() => { + it('overwrites existing file', async() => { mockfs({ 'folder': { 'file1.js': 'oldfile1', @@ -64,5 +64,16 @@ describe('The ProjectItem module', () => { expect(fs.readdirSync(path.join('folder', 'deepFolder')).sort()).toEqual(['file4.js']); expect(fs.readFileSync(path.join('folder', 'deepFolder', 'file4.js'))).toBe('file4'); }); + + it('skips empty folder', async() => { + folder.add(ProjectItem.directory('empty-folder')); + await folder.create('root'); + expect(fs.readdirSync('.')).toEqual(['folder']); + expect(fs.readdirSync('folder').sort()).toEqual(['deepFolder', 'file1.js', 'file2.js']); + expect(fs.readFileSync(path.join('folder', 'file1.js'))).toBe('file1'); + expect(fs.readFileSync(path.join('folder', 'file2.js'))).toBe('file2'); + expect(fs.readdirSync(path.join('folder', 'deepFolder')).sort()).toEqual(['file4.js']); + expect(fs.readFileSync(path.join('folder', 'deepFolder', 'file4.js'))).toBe('file4'); + }); }); });