mirror of
https://github.com/theoludwig/programming-challenges.git
synced 2025-05-18 12:02:53 +02:00
chore: better Prettier config for easier reviews
This commit is contained in:
@ -1,92 +1,92 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import fs from 'node:fs'
|
||||
import test from "node:test"
|
||||
import assert from "node:assert/strict"
|
||||
import fs from "node:fs"
|
||||
|
||||
import fsMock from 'mock-fs'
|
||||
import fsMock from "mock-fs"
|
||||
|
||||
import { copyDirectory } from '../copyDirectory.js'
|
||||
import { copyDirectory } from "../copyDirectory.js"
|
||||
|
||||
await test('utils/copyDirectory', async (t) => {
|
||||
await test("utils/copyDirectory", async (t) => {
|
||||
t.afterEach(() => {
|
||||
fsMock.restore()
|
||||
})
|
||||
|
||||
await t.test('copy the files', async () => {
|
||||
await t.test("copy the files", async () => {
|
||||
fsMock({
|
||||
'/source': {
|
||||
'default.png': '',
|
||||
'index.ts': ''
|
||||
"/source": {
|
||||
"default.png": "",
|
||||
"index.ts": "",
|
||||
},
|
||||
'/destination': {}
|
||||
"/destination": {},
|
||||
})
|
||||
|
||||
let destinationDirectoryContent = await fs.promises.readdir('/destination')
|
||||
let sourceDirectoryContent = await fs.promises.readdir('/source')
|
||||
let destinationDirectoryContent = await fs.promises.readdir("/destination")
|
||||
let sourceDirectoryContent = await fs.promises.readdir("/source")
|
||||
assert.strictEqual(destinationDirectoryContent.length, 0)
|
||||
assert.strictEqual(sourceDirectoryContent.length, 2)
|
||||
|
||||
await copyDirectory('/source', '/destination')
|
||||
destinationDirectoryContent = await fs.promises.readdir('/destination')
|
||||
sourceDirectoryContent = await fs.promises.readdir('/source')
|
||||
await copyDirectory("/source", "/destination")
|
||||
destinationDirectoryContent = await fs.promises.readdir("/destination")
|
||||
sourceDirectoryContent = await fs.promises.readdir("/source")
|
||||
assert.strictEqual(destinationDirectoryContent.length, 2)
|
||||
assert.strictEqual(sourceDirectoryContent.length, 2)
|
||||
assert.deepStrictEqual(destinationDirectoryContent, [
|
||||
'default.png',
|
||||
'index.ts'
|
||||
"default.png",
|
||||
"index.ts",
|
||||
])
|
||||
assert.deepStrictEqual(sourceDirectoryContent, ['default.png', 'index.ts'])
|
||||
assert.deepStrictEqual(sourceDirectoryContent, ["default.png", "index.ts"])
|
||||
})
|
||||
|
||||
await t.test('copy the files and folders recursively', async () => {
|
||||
await t.test("copy the files and folders recursively", async () => {
|
||||
fsMock({
|
||||
'/source': {
|
||||
'random-folder': {
|
||||
'default.png': '',
|
||||
'second-random-folder': {
|
||||
'mycode.ts': ''
|
||||
}
|
||||
"/source": {
|
||||
"random-folder": {
|
||||
"default.png": "",
|
||||
"second-random-folder": {
|
||||
"mycode.ts": "",
|
||||
},
|
||||
},
|
||||
'index.ts': ''
|
||||
"index.ts": "",
|
||||
},
|
||||
'/destination': {}
|
||||
"/destination": {},
|
||||
})
|
||||
|
||||
let destinationDirectoryContent = await fs.promises.readdir('/destination')
|
||||
let sourceDirectoryContent = await fs.promises.readdir('/source')
|
||||
let randomFolderContent = await fs.promises.readdir('/source/random-folder')
|
||||
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'
|
||||
"/source/random-folder/second-random-folder",
|
||||
)
|
||||
assert.strictEqual(randomFolderContent.length, 2)
|
||||
assert.strictEqual(secondRandomFolderContent.length, 1)
|
||||
assert.strictEqual(destinationDirectoryContent.length, 0)
|
||||
assert.strictEqual(sourceDirectoryContent.length, 2)
|
||||
|
||||
await copyDirectory('/source', '/destination')
|
||||
destinationDirectoryContent = await fs.promises.readdir('/destination')
|
||||
sourceDirectoryContent = await fs.promises.readdir('/source')
|
||||
await copyDirectory("/source", "/destination")
|
||||
destinationDirectoryContent = await fs.promises.readdir("/destination")
|
||||
sourceDirectoryContent = await fs.promises.readdir("/source")
|
||||
randomFolderContent = await fs.promises.readdir(
|
||||
'/destination/random-folder'
|
||||
"/destination/random-folder",
|
||||
)
|
||||
secondRandomFolderContent = await fs.promises.readdir(
|
||||
'/destination/random-folder/second-random-folder'
|
||||
"/destination/random-folder/second-random-folder",
|
||||
)
|
||||
assert.strictEqual(destinationDirectoryContent.length, 2)
|
||||
assert.strictEqual(sourceDirectoryContent.length, 2)
|
||||
assert.deepStrictEqual(destinationDirectoryContent, [
|
||||
'index.ts',
|
||||
'random-folder'
|
||||
"index.ts",
|
||||
"random-folder",
|
||||
])
|
||||
assert.deepStrictEqual(sourceDirectoryContent, [
|
||||
'index.ts',
|
||||
'random-folder'
|
||||
"index.ts",
|
||||
"random-folder",
|
||||
])
|
||||
assert.strictEqual(randomFolderContent.length, 2)
|
||||
assert.strictEqual(secondRandomFolderContent.length, 1)
|
||||
assert.deepStrictEqual(randomFolderContent, [
|
||||
'default.png',
|
||||
'second-random-folder'
|
||||
"default.png",
|
||||
"second-random-folder",
|
||||
])
|
||||
assert.deepStrictEqual(secondRandomFolderContent, ['mycode.ts'])
|
||||
assert.deepStrictEqual(secondRandomFolderContent, ["mycode.ts"])
|
||||
})
|
||||
})
|
||||
|
@ -1,26 +1,26 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import test from "node:test"
|
||||
import assert from "node:assert/strict"
|
||||
|
||||
import fsMock from 'mock-fs'
|
||||
import fsMock from "mock-fs"
|
||||
|
||||
import { isExistingPath } from '../isExistingPath.js'
|
||||
import { isExistingPath } from "../isExistingPath.js"
|
||||
|
||||
await test('utils/isExistingPath', async (t) => {
|
||||
await test("utils/isExistingPath", async (t) => {
|
||||
t.afterEach(() => {
|
||||
fsMock.restore()
|
||||
})
|
||||
|
||||
await t.test('should return true if the file exists', async () => {
|
||||
await t.test("should return true if the file exists", async () => {
|
||||
fsMock({
|
||||
'/file.txt': ''
|
||||
"/file.txt": "",
|
||||
})
|
||||
assert.strictEqual(await isExistingPath('/file.txt'), true)
|
||||
assert.strictEqual(await isExistingPath("/file.txt"), true)
|
||||
})
|
||||
|
||||
await t.test("should return false if the file doesn't exists", async () => {
|
||||
fsMock({
|
||||
'/file.txt': ''
|
||||
"/file.txt": "",
|
||||
})
|
||||
assert.strictEqual(await isExistingPath('/randomfile.txt'), false)
|
||||
assert.strictEqual(await isExistingPath("/randomfile.txt"), false)
|
||||
})
|
||||
})
|
||||
|
@ -1,9 +1,9 @@
|
||||
import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
import fs from "node:fs"
|
||||
import path from "node:path"
|
||||
|
||||
export const copyDirectory = async (
|
||||
source: string,
|
||||
destination: string
|
||||
destination: string,
|
||||
): Promise<void> => {
|
||||
const filesToCreate = await fs.promises.readdir(source)
|
||||
for (const file of filesToCreate) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import fs from 'node:fs'
|
||||
import fs from "node:fs"
|
||||
|
||||
export const isExistingPath = async (path: string): Promise<boolean> => {
|
||||
try {
|
||||
|
@ -1,6 +1,6 @@
|
||||
export const parseCommandOutput = (output: string): string[] => {
|
||||
return output
|
||||
.split('\n')
|
||||
.split("\n")
|
||||
.map((line) => {
|
||||
return line.trim()
|
||||
})
|
||||
|
Reference in New Issue
Block a user