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
2021-05-05 09:40:12 -04:00
committed by GitHub
parent 208fa83feb
commit 3491e2eeea
2 changed files with 32 additions and 3 deletions

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')