1
1
mirror of https://github.com/theoludwig/programming-challenges.git synced 2025-05-18 12:02:53 +02:00

feat: rewrite programming-challenges CLI (#3)

This commit is contained in:
Divlo
2021-06-09 20:31:45 +02:00
committed by GitHub
parent 7aa12f313e
commit 677a55a9d8
256 changed files with 16829 additions and 1881 deletions

View File

@ -0,0 +1,38 @@
import fsMock from 'mock-fs'
import fs from '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': {}
})
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'])
)
})
})

View File

@ -0,0 +1,33 @@
import fsMock from 'mock-fs'
import fs from 'fs'
import {
TEMPORARY_PATH,
createTemporaryEmptyFolder
} from '../createTemporaryEmptyFolder'
import { isExistingPath } from '../isExistingPath'
describe('utils/createTemporaryEmptyFolder', () => {
afterEach(async () => {
fsMock.restore()
})
it('should create the temporary folder', async () => {
fsMock({})
expect(await isExistingPath(TEMPORARY_PATH)).toBeFalsy()
await createTemporaryEmptyFolder()
expect(await isExistingPath(TEMPORARY_PATH)).toBeTruthy()
})
it('should remove and create again the temporary folder', async () => {
fsMock({
[TEMPORARY_PATH]: {
'file.txt': ''
}
})
expect(await isExistingPath(TEMPORARY_PATH)).toBeTruthy()
expect((await fs.promises.readdir(TEMPORARY_PATH)).length).toEqual(1)
await createTemporaryEmptyFolder()
expect((await fs.promises.readdir(TEMPORARY_PATH)).length).toEqual(0)
})
})

View File

@ -0,0 +1,23 @@
import fsMock from 'mock-fs'
import { isExistingPath } from '../isExistingPath'
describe('utils/isExistingFile', () => {
afterEach(async () => {
fsMock.restore()
})
it('should return true if the file exists', async () => {
fsMock({
'/file.txt': ''
})
expect(await isExistingPath('/file.txt')).toBeTruthy()
})
it("should return false if the file doesn't exists", async () => {
fsMock({
'/file.txt': ''
})
expect(await isExistingPath('/randomfile.txt')).toBeFalsy()
})
})