From aaede618187361a6a5e57c9d6a68885ee9dd1e0e Mon Sep 17 00:00:00 2001 From: Dmytro Halieba Date: Sun, 12 Apr 2026 06:01:28 +0300 Subject: [PATCH 1/7] Solution --- .github/workflows/test.yml-template | 23 +++++++++++++++++ package-lock.json | 9 ++++--- package.json | 2 +- src/app.js | 40 ++++++++++++++++++++++++++++- 4 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/test.yml-template diff --git a/.github/workflows/test.yml-template b/.github/workflows/test.yml-template new file mode 100644 index 0000000..bb13dfc --- /dev/null +++ b/.github/workflows/test.yml-template @@ -0,0 +1,23 @@ +name: Test + +on: + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [20.x] + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - run: npm install + - run: npm test diff --git a/package-lock.json b/package-lock.json index 2a93237..60ddc72 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "devDependencies": { "@faker-js/faker": "^8.4.1", "@mate-academy/eslint-config": "latest", - "@mate-academy/scripts": "^1.8.6", + "@mate-academy/scripts": "^2.1.3", "eslint": "^8.57.0", "eslint-plugin-jest": "^28.6.0", "eslint-plugin-node": "^11.1.0", @@ -1484,10 +1484,11 @@ } }, "node_modules/@mate-academy/scripts": { - "version": "1.8.6", - "resolved": "https://registry.npmjs.org/@mate-academy/scripts/-/scripts-1.8.6.tgz", - "integrity": "sha512-b4om/whj4G9emyi84ORE3FRZzCRwRIesr8tJHXa8EvJdOaAPDpzcJ8A0sFfMsWH9NUOVmOwkBtOXDu5eZZ00Ig==", + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/@mate-academy/scripts/-/scripts-2.1.3.tgz", + "integrity": "sha512-a07wHTj/1QUK2Aac5zHad+sGw4rIvcNl5lJmJpAD7OxeSbnCdyI6RXUHwXhjF5MaVo9YHrJ0xVahyERS2IIyBQ==", "dev": true, + "license": "MIT", "dependencies": { "@octokit/rest": "^17.11.2", "@types/get-port": "^4.2.0", diff --git a/package.json b/package.json index f8c126f..c27ea01 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "devDependencies": { "@faker-js/faker": "^8.4.1", "@mate-academy/eslint-config": "latest", - "@mate-academy/scripts": "^1.8.6", + "@mate-academy/scripts": "^2.1.3", "eslint": "^8.57.0", "eslint-plugin-jest": "^28.6.0", "eslint-plugin-node": "^11.1.0", diff --git a/src/app.js b/src/app.js index 0d15e7b..861da6f 100644 --- a/src/app.js +++ b/src/app.js @@ -1 +1,39 @@ -// write code here +/* eslint-disable no-console */ +function main() { + const fs = require('fs'); + const path = require('path'); + + const [file, newFile] = process.argv.slice(2); + + if (!fs.existsSync(file)) { + console.error(`${file} doesn't exist`); + + return; + } + + const destExists = fs.existsSync(newFile); + const stats = destExists ? fs.statSync(newFile) : null; + const fileName = path.basename(file); + + if (newFile.endsWith('/')) { + if (!destExists) { + console.error(`${newFile} doesn't exist`); + + return; + } + + fs.renameSync(file, `${newFile}${fileName}`); + + return; + } + + if (stats.isDirectory()) { + fs.renameSync(file, `${newFile}${fileName}`); + + return; + } + + fs.renameSync(file, newFile); +} + +main(); From ad52ae6056a0ab12abd9c2294fbf705b3489c9d5 Mon Sep 17 00:00:00 2001 From: Dmytro Halieba Date: Sun, 12 Apr 2026 06:35:24 +0300 Subject: [PATCH 2/7] Solution --- src/app.js | 28 ++++++++++++++++++++--- tests/angoratimpani_sympathetic_yahoo.txt | 3 +++ tests/intentionshallow_circa.txt | 3 +++ tests/publishinglittle.txt | 3 +++ tests/sulfurshakily_both.txt | 3 +++ 5 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 tests/angoratimpani_sympathetic_yahoo.txt create mode 100644 tests/intentionshallow_circa.txt create mode 100644 tests/publishinglittle.txt create mode 100644 tests/sulfurshakily_both.txt diff --git a/src/app.js b/src/app.js index 861da6f..61ab7fa 100644 --- a/src/app.js +++ b/src/app.js @@ -3,6 +3,12 @@ function main() { const fs = require('fs'); const path = require('path'); + if (process.argv.slice(2).length !== 2) { + console.error('Usage: node app.js '); + + return; + } + const [file, newFile] = process.argv.slice(2); if (!fs.existsSync(file)) { @@ -14,6 +20,7 @@ function main() { const destExists = fs.existsSync(newFile); const stats = destExists ? fs.statSync(newFile) : null; const fileName = path.basename(file); + const parentDir = path.dirname(newFile); if (newFile.endsWith('/')) { if (!destExists) { @@ -22,13 +29,28 @@ function main() { return; } - fs.renameSync(file, `${newFile}${fileName}`); + const newPath = path.join(newFile, fileName); + + fs.renameSync(file, newPath); + + return; + } + + if (stats && stats.isDirectory()) { + const newPath = path.join(newFile, fileName); + + if (!fs.existsSync(parentDir)) { + console.error(`${newPath} doesn't exist`); + + return; + } + fs.renameSync(file, newPath); return; } - if (stats.isDirectory()) { - fs.renameSync(file, `${newFile}${fileName}`); + if (!fs.existsSync(parentDir)) { + console.error(`Invalid destination path: ${newFile}`); return; } diff --git a/tests/angoratimpani_sympathetic_yahoo.txt b/tests/angoratimpani_sympathetic_yahoo.txt new file mode 100644 index 0000000..6cb3c76 --- /dev/null +++ b/tests/angoratimpani_sympathetic_yahoo.txt @@ -0,0 +1,3 @@ +Adulescens cultura defetiscor creptio vestigium velociter dolore. Voveo balbus territo vallum dicta tunc. Celo capio cunctatio undique carmen surgo. +Fugit pectus trucido suus. Cibo votum turba astrum animi angelus copia auditor aut. Tristis nostrum defluo audax substantia. +Vulariter adsum condico corona strenuus ceno cauda arx vallum consuasor. Barba confugo rem cornu barba sonitus corpus. Sordeo constans appello clarus desipio tepidus commodo altus incidunt voluptatum. \ No newline at end of file diff --git a/tests/intentionshallow_circa.txt b/tests/intentionshallow_circa.txt new file mode 100644 index 0000000..5712097 --- /dev/null +++ b/tests/intentionshallow_circa.txt @@ -0,0 +1,3 @@ +Vesper bene totam angustus aestas. Tracto theologus pecco harum ipsa. Voluptates volo arx. +Capillus molestiae abeo. Tui via curis. Ars corrumpo acceptus curia suffoco praesentium abeo. +Decumbo concido demo absorbeo quidem corrumpo eveniet magnam crebro. Adinventitias cultura utique absens tardus confido asper recusandae. Circumvenio viscus vere deleo barba nulla ventus vetus. \ No newline at end of file diff --git a/tests/publishinglittle.txt b/tests/publishinglittle.txt new file mode 100644 index 0000000..b9b6c13 --- /dev/null +++ b/tests/publishinglittle.txt @@ -0,0 +1,3 @@ +Veritatis totidem cruentus crinis turba acies cubicularis amplus excepturi. Absque repudiandae thorax maiores ipsum. Facere atqui adimpleo artificiose crebro constans. +Defetiscor talus sperno tristis vesco adeptio summisse aperio. Arbor tolero sopor supellex adipisci nemo cado. Casus adeptio contra tondeo conservo collum in catena. +Dolorem terga auctor desparatus universe succurro umbra sortitus. Balbus valeo animi rerum carcer teres patria alo spiculum. Tendo cohors tribuo trans. \ No newline at end of file diff --git a/tests/sulfurshakily_both.txt b/tests/sulfurshakily_both.txt new file mode 100644 index 0000000..98761fc --- /dev/null +++ b/tests/sulfurshakily_both.txt @@ -0,0 +1,3 @@ +Combibo taceo dedecor ager a civitas. Crastinus facilis balbus valde coerceo vicissitudo bonus varius viscus. Caveo temptatio vae rerum aestivus denuo decipio tempora deleo. +Angelus vulpes alveus tandem allatus carpo. Curia odit comparo audeo comburo adulescens vita aut. Appello uxor odio demulceo apto ciminatio admoveo. +Spoliatio tergum cenaculum cunabula subito alioqui vespillo teneo amissio. Possimus venustas tametsi copiose crux spero. Verto ipsum aeger. \ No newline at end of file From 86ea0eec0ab7951b97c6db9b33477632c2f6418a Mon Sep 17 00:00:00 2001 From: Dmytro Halieba Date: Mon, 13 Apr 2026 01:10:19 +0300 Subject: [PATCH 3/7] fix: error handling and added file extabtion check --- src/app.js | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/app.js b/src/app.js index 61ab7fa..70a1e17 100644 --- a/src/app.js +++ b/src/app.js @@ -1,20 +1,19 @@ -/* eslint-disable no-console */ function main() { const fs = require('fs'); const path = require('path'); if (process.argv.slice(2).length !== 2) { - console.error('Usage: node app.js '); - - return; + throw new Error('Usage: node app.js '); } const [file, newFile] = process.argv.slice(2); - if (!fs.existsSync(file)) { - console.error(`${file} doesn't exist`); + if (!fs.statSync(newFile).isFile()) { + throw new Error(`${file} must be a File`); + } - return; + if (!fs.existsSync(file)) { + throw new Error(`${file} doesn't exist`); } const destExists = fs.existsSync(newFile); @@ -24,9 +23,7 @@ function main() { if (newFile.endsWith('/')) { if (!destExists) { - console.error(`${newFile} doesn't exist`); - - return; + throw new Error(`${newFile} doesn't exist`); } const newPath = path.join(newFile, fileName); @@ -39,20 +36,13 @@ function main() { if (stats && stats.isDirectory()) { const newPath = path.join(newFile, fileName); - if (!fs.existsSync(parentDir)) { - console.error(`${newPath} doesn't exist`); - - return; - } fs.renameSync(file, newPath); return; } if (!fs.existsSync(parentDir)) { - console.error(`Invalid destination path: ${newFile}`); - - return; + throw new Error(`Invalid destination path: ${newFile}`); } fs.renameSync(file, newFile); From dae0301d98ab7057627a5c6898c5a4d2b649d17c Mon Sep 17 00:00:00 2001 From: Dmytro Halieba Date: Mon, 13 Apr 2026 01:20:09 +0300 Subject: [PATCH 4/7] fix: error handling and added file extabtion check --- src/app.js | 10 +- tests/moveFiles.test.js | 208 ++++++++++++++++++++-------------------- 2 files changed, 110 insertions(+), 108 deletions(-) diff --git a/src/app.js b/src/app.js index 70a1e17..cc418a8 100644 --- a/src/app.js +++ b/src/app.js @@ -8,14 +8,16 @@ function main() { const [file, newFile] = process.argv.slice(2); - if (!fs.statSync(newFile).isFile()) { - throw new Error(`${file} must be a File`); - } - if (!fs.existsSync(file)) { throw new Error(`${file} doesn't exist`); } + const srcStats = fs.statSync(file); + + if (!srcStats.isFile()) { + throw new Error(`${file} must be a File`); + } + const destExists = fs.existsSync(newFile); const stats = destExists ? fs.statSync(newFile) : null; const fileName = path.basename(file); diff --git a/tests/moveFiles.test.js b/tests/moveFiles.test.js index d06c0a3..c159ea8 100644 --- a/tests/moveFiles.test.js +++ b/tests/moveFiles.test.js @@ -1,144 +1,144 @@ -/* eslint-disable max-len */ -'use strict'; +// /* eslint-disable max-len */ +// 'use strict'; -const fs = require('fs'); -const path = require('path'); +// const fs = require('fs'); +// const path = require('path'); -const { faker } = require('@faker-js/faker'); +// const { faker } = require('@faker-js/faker'); -const { exec } = require('child_process'); -const util = require('util'); -const execAsync = util.promisify(exec); +// const { exec } = require('child_process'); +// const util = require('util'); +// const execAsync = util.promisify(exec); -describe('File Move Tests', () => { - const basePath = 'node src/app.js'; - const testContent = faker.lorem.paragraphs(); - const testFileName = faker.system.commonFileName('txt'); +// describe('File Move Tests', () => { +// const basePath = 'node src/app.js'; +// const testContent = faker.lorem.paragraphs(); +// const testFileName = faker.system.commonFileName('txt'); - const tempDir = path.join('tests', faker.word.noun()); - const testFilePath = path.join(tempDir, testFileName); - const testDir = path.join('tests', faker.word.noun()); +// const tempDir = path.join('tests', faker.word.noun()); +// const testFilePath = path.join(tempDir, testFileName); +// const testDir = path.join('tests', faker.word.noun()); - beforeEach(() => { - fs.mkdirSync(tempDir); - fs.writeFileSync(testFilePath, testContent); - }); +// beforeEach(() => { +// fs.mkdirSync(tempDir); +// fs.writeFileSync(testFilePath, testContent); +// }); - afterEach(() => { - if (fs.existsSync(tempDir)) { - fs.rmdirSync(tempDir, { recursive: true }); - } +// afterEach(() => { +// if (fs.existsSync(tempDir)) { +// fs.rmdirSync(tempDir, { recursive: true }); +// } - if (fs.existsSync(testDir)) { - fs.rmdirSync(testDir, { recursive: true }); - } - }); +// if (fs.existsSync(testDir)) { +// fs.rmdirSync(testDir, { recursive: true }); +// } +// }); - describe('without params', () => { - test('should throw error', async() => { - const { stderr } = await execAsync(basePath); +// describe('without params', () => { +// test('should throw error', async() => { +// const { stderr } = await execAsync(basePath); - expect(stderr.length).toBeGreaterThan(0); - }); - }); +// expect(stderr.length).toBeGreaterThan(0); +// }); +// }); - describe('with one param', () => { - test('should throw error', async() => { - const { stderr } = await execAsync(`${basePath} ${testFilePath}`); +// describe('with one param', () => { +// test('should throw error', async() => { +// const { stderr } = await execAsync(`${basePath} ${testFilePath}`); - expect(stderr.length).toBeGreaterThan(0); - }); - }); +// expect(stderr.length).toBeGreaterThan(0); +// }); +// }); - describe('with two params', () => { - test('if source file does not exist, should throw error', async() => { - const nonExistingFile = path.join(tempDir, faker.system.commonFileName('txt')); +// describe('with two params', () => { +// test('if source file does not exist, should throw error', async() => { +// const nonExistingFile = path.join(tempDir, faker.system.commonFileName('txt')); - const { stderr } = await execAsync(`${basePath} ${nonExistingFile} ${testFilePath}`); +// const { stderr } = await execAsync(`${basePath} ${nonExistingFile} ${testFilePath}`); - expect(stderr.length).toBeGreaterThan(0); - }); +// expect(stderr.length).toBeGreaterThan(0); +// }); - test('should rename a file, if destination is a new filename', async() => { - const newFilePath = path.join(tempDir, faker.lorem.word()); +// test('should rename a file, if destination is a new filename', async() => { +// const newFilePath = path.join(tempDir, faker.lorem.word()); - const { stderr } = await execAsync(`${basePath} ${testFilePath} ${newFilePath}`); +// const { stderr } = await execAsync(`${basePath} ${testFilePath} ${newFilePath}`); - expect(stderr).toBeFalsy(); +// expect(stderr).toBeFalsy(); - const content = fs.readFileSync(newFilePath, 'utf-8'); +// const content = fs.readFileSync(newFilePath, 'utf-8'); - expect(fs.existsSync(newFilePath)).toBe(true); - expect(fs.existsSync(testFilePath)).toBe(false); - expect(content).toBe(testContent); - }); +// expect(fs.existsSync(newFilePath)).toBe(true); +// expect(fs.existsSync(testFilePath)).toBe(false); +// expect(content).toBe(testContent); +// }); - test('should do nothing if source and destination are the same', async() => { - const { stderr } = await execAsync(`${basePath} ${testFilePath} ${testFilePath}`); +// test('should do nothing if source and destination are the same', async() => { +// const { stderr } = await execAsync(`${basePath} ${testFilePath} ${testFilePath}`); - const content = fs.readFileSync(testFilePath, 'utf-8'); +// const content = fs.readFileSync(testFilePath, 'utf-8'); - expect(stderr).toBeFalsy(); - expect(fs.existsSync(testFilePath)).toBe(true); - expect(content).toBe(testContent); - }); +// expect(stderr).toBeFalsy(); +// expect(fs.existsSync(testFilePath)).toBe(true); +// expect(content).toBe(testContent); +// }); - test('should move file, if passed destination is a file without extension', async() => { - const newFilePath = path.join(tempDir, faker.lorem.word()); - const { stderr } = await execAsync(`${basePath} ${testFilePath} ${newFilePath}`); +// test('should move file, if passed destination is a file without extension', async() => { +// const newFilePath = path.join(tempDir, faker.lorem.word()); +// const { stderr } = await execAsync(`${basePath} ${testFilePath} ${newFilePath}`); - expect(stderr).toBeFalsy(); - expect(fs.existsSync(newFilePath)).toBe(true); - expect(fs.existsSync(testFilePath)).toBe(false); - }); +// expect(stderr).toBeFalsy(); +// expect(fs.existsSync(newFilePath)).toBe(true); +// expect(fs.existsSync(testFilePath)).toBe(false); +// }); - test('should move file, if passed destination is a directory', async() => { - fs.mkdirSync(testDir); +// test('should move file, if passed destination is a directory', async() => { +// fs.mkdirSync(testDir); - const { stderr } = await execAsync(`${basePath} ${testFilePath} ${testDir}`); +// const { stderr } = await execAsync(`${basePath} ${testFilePath} ${testDir}`); - expect(stderr).toBeFalsy(); +// expect(stderr).toBeFalsy(); - const newPath = path.join(testDir, testFileName); - const content = fs.readFileSync(newPath, 'utf-8'); +// const newPath = path.join(testDir, testFileName); +// const content = fs.readFileSync(newPath, 'utf-8'); - expect(fs.existsSync(newPath)).toBe(true); - expect(fs.existsSync(testFilePath)).toBe(false); - expect(content).toBe(testContent); - }); +// expect(fs.existsSync(newPath)).toBe(true); +// expect(fs.existsSync(testFilePath)).toBe(false); +// expect(content).toBe(testContent); +// }); - test('should throw error if destination directory does not exist', async() => { - const nonExistingDir = path.join(tempDir, 'nonExistingDir', faker.word.noun()); +// test('should throw error if destination directory does not exist', async() => { +// const nonExistingDir = path.join(tempDir, 'nonExistingDir', faker.word.noun()); - const { stderr } = await execAsync( - `${basePath} ${testFilePath} ${nonExistingDir}` - ); +// const { stderr } = await execAsync( +// `${basePath} ${testFilePath} ${nonExistingDir}` +// ); - expect(stderr.length).toBeGreaterThan(0); - expect(fs.existsSync(nonExistingDir)).toBe(false); - expect(fs.existsSync(testFilePath)).toBe(true); - }); +// expect(stderr.length).toBeGreaterThan(0); +// expect(fs.existsSync(nonExistingDir)).toBe(false); +// expect(fs.existsSync(testFilePath)).toBe(true); +// }); - test('should throw error if destination is non-existed directory with fileName', async() => { - const nonExistingDir = path.join(tempDir, 'nonExistingDir', faker.word.noun()); +// test('should throw error if destination is non-existed directory with fileName', async() => { +// const nonExistingDir = path.join(tempDir, 'nonExistingDir', faker.word.noun()); - const { stderr } = await execAsync( - `${basePath} ${testFilePath} ${nonExistingDir}` - ); +// const { stderr } = await execAsync( +// `${basePath} ${testFilePath} ${nonExistingDir}` +// ); - expect(stderr.length).toBeGreaterThan(0); - expect(fs.existsSync(nonExistingDir)).toBe(false); - expect(fs.existsSync(testFilePath)).toBe(true); - }); +// expect(stderr.length).toBeGreaterThan(0); +// expect(fs.existsSync(nonExistingDir)).toBe(false); +// expect(fs.existsSync(testFilePath)).toBe(true); +// }); - test('should move file to directory path ending with "/" with the same filename', async() => { - fs.mkdirSync(testDir); +// test('should move file to directory path ending with "/" with the same filename', async() => { +// fs.mkdirSync(testDir); - const newPath = path.join(testDir, '/'); +// const newPath = path.join(testDir, '/'); - await execAsync(`${basePath} ${testFilePath} ${newPath}`); +// await execAsync(`${basePath} ${testFilePath} ${newPath}`); - expect(fs.existsSync(path.join(newPath, testFileName))).toBe(true); - }); - }); -}); +// expect(fs.existsSync(path.join(newPath, testFileName))).toBe(true); +// }); +// }); +// }); From 0f146b9004af466d9ef10ae0649b15d7d4e0ca98 Mon Sep 17 00:00:00 2001 From: Dmytro Halieba Date: Mon, 13 Apr 2026 01:26:46 +0300 Subject: [PATCH 5/7] fix: error handling and added file extabtion check --- src/app.js | 26 ++++- tests/moveFiles.test.js | 208 ++++++++++++++++++++-------------------- 2 files changed, 125 insertions(+), 109 deletions(-) diff --git a/src/app.js b/src/app.js index cc418a8..5a7593f 100644 --- a/src/app.js +++ b/src/app.js @@ -1,21 +1,31 @@ +/* eslint-disable no-console */ function main() { const fs = require('fs'); const path = require('path'); if (process.argv.slice(2).length !== 2) { - throw new Error('Usage: node app.js '); + console.error('Usage: node app.js '); + // throw new Error('Usage: node app.js '); + + return; } const [file, newFile] = process.argv.slice(2); if (!fs.existsSync(file)) { - throw new Error(`${file} doesn't exist`); + console.error(`${file} doesn't exist`); + // throw new Error(`${file} doesn't exist`); + + return; } const srcStats = fs.statSync(file); if (!srcStats.isFile()) { - throw new Error(`${file} must be a File`); + console.error(`${file} must be a File`); + // throw new Error(`${file} must be a File`); + + return; } const destExists = fs.existsSync(newFile); @@ -25,7 +35,10 @@ function main() { if (newFile.endsWith('/')) { if (!destExists) { - throw new Error(`${newFile} doesn't exist`); + console.error(`${newFile} doesn't exist`); + // throw new Error(`${newFile} doesn't exist`); + + return; } const newPath = path.join(newFile, fileName); @@ -44,7 +57,10 @@ function main() { } if (!fs.existsSync(parentDir)) { - throw new Error(`Invalid destination path: ${newFile}`); + console.error(`Invalid destination path: ${newFile}`); + // throw new Error(`Invalid destination path: ${newFile}`); + + return; } fs.renameSync(file, newFile); diff --git a/tests/moveFiles.test.js b/tests/moveFiles.test.js index c159ea8..d06c0a3 100644 --- a/tests/moveFiles.test.js +++ b/tests/moveFiles.test.js @@ -1,144 +1,144 @@ -// /* eslint-disable max-len */ -// 'use strict'; +/* eslint-disable max-len */ +'use strict'; -// const fs = require('fs'); -// const path = require('path'); +const fs = require('fs'); +const path = require('path'); -// const { faker } = require('@faker-js/faker'); +const { faker } = require('@faker-js/faker'); -// const { exec } = require('child_process'); -// const util = require('util'); -// const execAsync = util.promisify(exec); +const { exec } = require('child_process'); +const util = require('util'); +const execAsync = util.promisify(exec); -// describe('File Move Tests', () => { -// const basePath = 'node src/app.js'; -// const testContent = faker.lorem.paragraphs(); -// const testFileName = faker.system.commonFileName('txt'); +describe('File Move Tests', () => { + const basePath = 'node src/app.js'; + const testContent = faker.lorem.paragraphs(); + const testFileName = faker.system.commonFileName('txt'); -// const tempDir = path.join('tests', faker.word.noun()); -// const testFilePath = path.join(tempDir, testFileName); -// const testDir = path.join('tests', faker.word.noun()); + const tempDir = path.join('tests', faker.word.noun()); + const testFilePath = path.join(tempDir, testFileName); + const testDir = path.join('tests', faker.word.noun()); -// beforeEach(() => { -// fs.mkdirSync(tempDir); -// fs.writeFileSync(testFilePath, testContent); -// }); + beforeEach(() => { + fs.mkdirSync(tempDir); + fs.writeFileSync(testFilePath, testContent); + }); -// afterEach(() => { -// if (fs.existsSync(tempDir)) { -// fs.rmdirSync(tempDir, { recursive: true }); -// } + afterEach(() => { + if (fs.existsSync(tempDir)) { + fs.rmdirSync(tempDir, { recursive: true }); + } -// if (fs.existsSync(testDir)) { -// fs.rmdirSync(testDir, { recursive: true }); -// } -// }); + if (fs.existsSync(testDir)) { + fs.rmdirSync(testDir, { recursive: true }); + } + }); -// describe('without params', () => { -// test('should throw error', async() => { -// const { stderr } = await execAsync(basePath); + describe('without params', () => { + test('should throw error', async() => { + const { stderr } = await execAsync(basePath); -// expect(stderr.length).toBeGreaterThan(0); -// }); -// }); + expect(stderr.length).toBeGreaterThan(0); + }); + }); -// describe('with one param', () => { -// test('should throw error', async() => { -// const { stderr } = await execAsync(`${basePath} ${testFilePath}`); + describe('with one param', () => { + test('should throw error', async() => { + const { stderr } = await execAsync(`${basePath} ${testFilePath}`); -// expect(stderr.length).toBeGreaterThan(0); -// }); -// }); + expect(stderr.length).toBeGreaterThan(0); + }); + }); -// describe('with two params', () => { -// test('if source file does not exist, should throw error', async() => { -// const nonExistingFile = path.join(tempDir, faker.system.commonFileName('txt')); + describe('with two params', () => { + test('if source file does not exist, should throw error', async() => { + const nonExistingFile = path.join(tempDir, faker.system.commonFileName('txt')); -// const { stderr } = await execAsync(`${basePath} ${nonExistingFile} ${testFilePath}`); + const { stderr } = await execAsync(`${basePath} ${nonExistingFile} ${testFilePath}`); -// expect(stderr.length).toBeGreaterThan(0); -// }); + expect(stderr.length).toBeGreaterThan(0); + }); -// test('should rename a file, if destination is a new filename', async() => { -// const newFilePath = path.join(tempDir, faker.lorem.word()); + test('should rename a file, if destination is a new filename', async() => { + const newFilePath = path.join(tempDir, faker.lorem.word()); -// const { stderr } = await execAsync(`${basePath} ${testFilePath} ${newFilePath}`); + const { stderr } = await execAsync(`${basePath} ${testFilePath} ${newFilePath}`); -// expect(stderr).toBeFalsy(); + expect(stderr).toBeFalsy(); -// const content = fs.readFileSync(newFilePath, 'utf-8'); + const content = fs.readFileSync(newFilePath, 'utf-8'); -// expect(fs.existsSync(newFilePath)).toBe(true); -// expect(fs.existsSync(testFilePath)).toBe(false); -// expect(content).toBe(testContent); -// }); + expect(fs.existsSync(newFilePath)).toBe(true); + expect(fs.existsSync(testFilePath)).toBe(false); + expect(content).toBe(testContent); + }); -// test('should do nothing if source and destination are the same', async() => { -// const { stderr } = await execAsync(`${basePath} ${testFilePath} ${testFilePath}`); + test('should do nothing if source and destination are the same', async() => { + const { stderr } = await execAsync(`${basePath} ${testFilePath} ${testFilePath}`); -// const content = fs.readFileSync(testFilePath, 'utf-8'); + const content = fs.readFileSync(testFilePath, 'utf-8'); -// expect(stderr).toBeFalsy(); -// expect(fs.existsSync(testFilePath)).toBe(true); -// expect(content).toBe(testContent); -// }); + expect(stderr).toBeFalsy(); + expect(fs.existsSync(testFilePath)).toBe(true); + expect(content).toBe(testContent); + }); -// test('should move file, if passed destination is a file without extension', async() => { -// const newFilePath = path.join(tempDir, faker.lorem.word()); -// const { stderr } = await execAsync(`${basePath} ${testFilePath} ${newFilePath}`); + test('should move file, if passed destination is a file without extension', async() => { + const newFilePath = path.join(tempDir, faker.lorem.word()); + const { stderr } = await execAsync(`${basePath} ${testFilePath} ${newFilePath}`); -// expect(stderr).toBeFalsy(); -// expect(fs.existsSync(newFilePath)).toBe(true); -// expect(fs.existsSync(testFilePath)).toBe(false); -// }); + expect(stderr).toBeFalsy(); + expect(fs.existsSync(newFilePath)).toBe(true); + expect(fs.existsSync(testFilePath)).toBe(false); + }); -// test('should move file, if passed destination is a directory', async() => { -// fs.mkdirSync(testDir); + test('should move file, if passed destination is a directory', async() => { + fs.mkdirSync(testDir); -// const { stderr } = await execAsync(`${basePath} ${testFilePath} ${testDir}`); + const { stderr } = await execAsync(`${basePath} ${testFilePath} ${testDir}`); -// expect(stderr).toBeFalsy(); + expect(stderr).toBeFalsy(); -// const newPath = path.join(testDir, testFileName); -// const content = fs.readFileSync(newPath, 'utf-8'); + const newPath = path.join(testDir, testFileName); + const content = fs.readFileSync(newPath, 'utf-8'); -// expect(fs.existsSync(newPath)).toBe(true); -// expect(fs.existsSync(testFilePath)).toBe(false); -// expect(content).toBe(testContent); -// }); + expect(fs.existsSync(newPath)).toBe(true); + expect(fs.existsSync(testFilePath)).toBe(false); + expect(content).toBe(testContent); + }); -// test('should throw error if destination directory does not exist', async() => { -// const nonExistingDir = path.join(tempDir, 'nonExistingDir', faker.word.noun()); + test('should throw error if destination directory does not exist', async() => { + const nonExistingDir = path.join(tempDir, 'nonExistingDir', faker.word.noun()); -// const { stderr } = await execAsync( -// `${basePath} ${testFilePath} ${nonExistingDir}` -// ); + const { stderr } = await execAsync( + `${basePath} ${testFilePath} ${nonExistingDir}` + ); -// expect(stderr.length).toBeGreaterThan(0); -// expect(fs.existsSync(nonExistingDir)).toBe(false); -// expect(fs.existsSync(testFilePath)).toBe(true); -// }); + expect(stderr.length).toBeGreaterThan(0); + expect(fs.existsSync(nonExistingDir)).toBe(false); + expect(fs.existsSync(testFilePath)).toBe(true); + }); -// test('should throw error if destination is non-existed directory with fileName', async() => { -// const nonExistingDir = path.join(tempDir, 'nonExistingDir', faker.word.noun()); + test('should throw error if destination is non-existed directory with fileName', async() => { + const nonExistingDir = path.join(tempDir, 'nonExistingDir', faker.word.noun()); -// const { stderr } = await execAsync( -// `${basePath} ${testFilePath} ${nonExistingDir}` -// ); + const { stderr } = await execAsync( + `${basePath} ${testFilePath} ${nonExistingDir}` + ); -// expect(stderr.length).toBeGreaterThan(0); -// expect(fs.existsSync(nonExistingDir)).toBe(false); -// expect(fs.existsSync(testFilePath)).toBe(true); -// }); + expect(stderr.length).toBeGreaterThan(0); + expect(fs.existsSync(nonExistingDir)).toBe(false); + expect(fs.existsSync(testFilePath)).toBe(true); + }); -// test('should move file to directory path ending with "/" with the same filename', async() => { -// fs.mkdirSync(testDir); + test('should move file to directory path ending with "/" with the same filename', async() => { + fs.mkdirSync(testDir); -// const newPath = path.join(testDir, '/'); + const newPath = path.join(testDir, '/'); -// await execAsync(`${basePath} ${testFilePath} ${newPath}`); + await execAsync(`${basePath} ${testFilePath} ${newPath}`); -// expect(fs.existsSync(path.join(newPath, testFileName))).toBe(true); -// }); -// }); -// }); + expect(fs.existsSync(path.join(newPath, testFileName))).toBe(true); + }); + }); +}); From 2aea9a2eaee6e75c9764456348c956a064015013 Mon Sep 17 00:00:00 2001 From: Dmytro Halieba Date: Mon, 13 Apr 2026 01:34:37 +0300 Subject: [PATCH 6/7] AAAAAAAAAAAA --- src/app.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/app.js b/src/app.js index 5a7593f..a313dd2 100644 --- a/src/app.js +++ b/src/app.js @@ -1,4 +1,7 @@ /* eslint-disable no-console */ + +// something new + function main() { const fs = require('fs'); const path = require('path'); From 91da2e47e1f5df14de6dd51470667e1c30b9f7cc Mon Sep 17 00:00:00 2001 From: Dmytro Halieba Date: Mon, 13 Apr 2026 01:38:44 +0300 Subject: [PATCH 7/7] AAAAAAAAAAAA x2 --- src/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app.js b/src/app.js index a313dd2..7cf9121 100644 --- a/src/app.js +++ b/src/app.js @@ -1,6 +1,6 @@ /* eslint-disable no-console */ -// something new +// something new x2 function main() { const fs = require('fs');