Add option to cp to only copy contents of directory (#788)

* Add option to not copy source directory

* Cleanup

* Update condition to be consistent
This commit is contained in:
Luke Tomlinson authored and GitHub committed 2021-05-05 09:40:12 -04:00
1 parent 9d8df321e0
commit 87cbde80d1
2 files changed
+32 -3

No files matched your search

+23
View File
@@ -90,6 +90,29 @@ describe('cp', () => {
)
})
it('copies directory into existing destination with -r without copying source directory', async () => {
const root: string = path.join(
getTestTemp(),
'cp_with_-r_existing_dest_no_source_dir'
)
const sourceFolder: string = path.join(root, 'cp_source')
const sourceFile: string = path.join(sourceFolder, 'cp_source_file')
const targetFolder: string = path.join(root, 'cp_target')
const targetFile: string = path.join(targetFolder, 'cp_source_file')
await io.mkdirP(sourceFolder)
await fs.writeFile(sourceFile, 'test file content', {encoding: 'utf8'})
await io.mkdirP(targetFolder)
await io.cp(sourceFolder, targetFolder, {
recursive: true,
copySourceDirectory: false
})
expect(await fs.readFile(targetFile, {encoding: 'utf8'})).toBe(
'test file content'
)
})
it('copies directory into non-existing destination with -r', async () => {
const root: string = path.join(getTestTemp(), 'cp_with_-r_nonexistent_dest')
const sourceFolder: string = path.join(root, 'cp_source')