2021-07-03 18:40:17 +02:00
|
|
|
import fs from 'node:fs'
|
|
|
|
|
2021-06-09 20:31:45 +02:00
|
|
|
import fsMock from 'mock-fs'
|
|
|
|
|
|
|
|
import { copyDirectory } from '../copyDirectory'
|
|
|
|
|
|
|
|
describe('utils/copyDirectory', () => {
|
|
|
|
afterEach(async () => {
|
|
|
|
fsMock.restore()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('copy the files', async () => {
|
|
|
|
fsMock({
|
|
|
|
'/source': {
|
|
|
|
'default.png': '',
|
|
|
|
'index.ts': '',
|
|
|
|
'.npmignore': ''
|
|
|
|
},
|
|
|
|
'/destination': {}
|
2021-12-06 17:18:14 +01:00
|
|
|
}, { createCwd: false })
|
2021-06-09 20:31:45 +02:00
|
|
|
|
|
|
|
let destinationDirectoryContent = await fs.promises.readdir('/destination')
|
|
|
|
let sourceDirectoryContent = await fs.promises.readdir('/source')
|
|
|
|
expect(destinationDirectoryContent.length).toEqual(0)
|
|
|
|
expect(sourceDirectoryContent.length).toEqual(3)
|
|
|
|
|
|
|
|
await copyDirectory('/source', '/destination')
|
|
|
|
destinationDirectoryContent = await fs.promises.readdir('/destination')
|
|
|
|
sourceDirectoryContent = await fs.promises.readdir('/source')
|
|
|
|
expect(destinationDirectoryContent.length).toEqual(3)
|
|
|
|
expect(sourceDirectoryContent.length).toEqual(3)
|
|
|
|
expect(destinationDirectoryContent).toEqual(
|
|
|
|
expect.arrayContaining(['default.png', 'index.ts', '.npmignore'])
|
|
|
|
)
|
|
|
|
expect(sourceDirectoryContent).toEqual(
|
|
|
|
expect.arrayContaining(['default.png', 'index.ts', '.npmignore'])
|
|
|
|
)
|
|
|
|
})
|
2021-08-27 13:03:41 +02:00
|
|
|
|
|
|
|
it('copy the files and folders recursively', async () => {
|
|
|
|
fsMock({
|
|
|
|
'/source': {
|
|
|
|
'random-folder': {
|
|
|
|
'default.png': '',
|
|
|
|
'second-random-folder': {
|
|
|
|
'mycode.ts': ''
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'index.ts': '',
|
|
|
|
'.npmignore': ''
|
|
|
|
},
|
|
|
|
'/destination': {}
|
2021-12-06 17:18:14 +01:00
|
|
|
}, { createCwd: false })
|
2021-08-27 13:03:41 +02:00
|
|
|
|
|
|
|
let destinationDirectoryContent = await fs.promises.readdir('/destination')
|
|
|
|
let sourceDirectoryContent = await fs.promises.readdir('/source')
|
|
|
|
let randomFolderContent = await fs.promises.readdir('/source/random-folder')
|
|
|
|
let secondRandomFolderContent = await fs.promises.readdir(
|
|
|
|
'/source/random-folder/second-random-folder'
|
|
|
|
)
|
|
|
|
expect(randomFolderContent.length).toEqual(2)
|
|
|
|
expect(secondRandomFolderContent.length).toEqual(1)
|
|
|
|
expect(destinationDirectoryContent.length).toEqual(0)
|
|
|
|
expect(sourceDirectoryContent.length).toEqual(3)
|
|
|
|
|
|
|
|
await copyDirectory('/source', '/destination')
|
|
|
|
destinationDirectoryContent = await fs.promises.readdir('/destination')
|
|
|
|
sourceDirectoryContent = await fs.promises.readdir('/source')
|
|
|
|
randomFolderContent = await fs.promises.readdir('/destination/random-folder')
|
|
|
|
secondRandomFolderContent = await fs.promises.readdir(
|
|
|
|
'/destination/random-folder/second-random-folder'
|
|
|
|
)
|
|
|
|
expect(destinationDirectoryContent.length).toEqual(3)
|
|
|
|
expect(sourceDirectoryContent.length).toEqual(3)
|
|
|
|
expect(destinationDirectoryContent).toEqual(
|
|
|
|
expect.arrayContaining(['random-folder', 'index.ts', '.npmignore'])
|
|
|
|
)
|
|
|
|
expect(sourceDirectoryContent).toEqual(
|
|
|
|
expect.arrayContaining(['random-folder', 'index.ts', '.npmignore'])
|
|
|
|
)
|
|
|
|
expect(randomFolderContent.length).toEqual(2)
|
|
|
|
expect(secondRandomFolderContent.length).toEqual(1)
|
|
|
|
expect(randomFolderContent).toEqual(
|
|
|
|
expect.arrayContaining(['default.png', 'second-random-folder'])
|
|
|
|
)
|
|
|
|
expect(secondRandomFolderContent).toEqual(
|
|
|
|
expect.arrayContaining(['mycode.ts'])
|
|
|
|
)
|
|
|
|
})
|
2021-06-09 20:31:45 +02:00
|
|
|
})
|