-
Notifications
You must be signed in to change notification settings - Fork 407
node_move-files_TetSh #335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,47 @@ | ||
| // write code here | ||
| /* eslint-disable no-console */ | ||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
|
|
||
| function main() { | ||
| const params = process.argv.slice(2); | ||
| const oldFile = params[0]; | ||
| let newFile = params[1]; | ||
|
|
||
| if (params.length < 2) { | ||
| console.error('2 parameters are required'); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| if (!fs.existsSync(oldFile)) { | ||
| console.error('Source file does not exist'); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| const fileName = path.basename(oldFile); | ||
|
|
||
| const endsWithSlash = newFile.endsWith('/'); | ||
| const targetExists = fs.existsSync(newFile); | ||
| const isDirectory = targetExists && fs.lstatSync(newFile).isDirectory(); | ||
|
|
||
| if (endsWithSlash || isDirectory) { | ||
| if (!targetExists && endsWithSlash) { | ||
| throw new Error('Destination directory does not exist'); | ||
| } | ||
|
|
||
| newFile = path.join(newFile, fileName); | ||
| } | ||
|
|
||
| const targetFolder = path.dirname(newFile); | ||
|
|
||
| if (!fs.existsSync(targetFolder)) { | ||
| console.error('Directory does not exist'); | ||
|
|
||
| return; | ||
|
Comment on lines
+38
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The requirements state that an error must be thrown if the destination directory doesn't exist. This implementation logs an error to the console instead. Please change this to |
||
| } | ||
|
|
||
| fs.renameSync(oldFile, newFile); | ||
| } | ||
|
|
||
| main(); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Thesis apto admiratio textor. Bibo vigor blandior tum terebro tricesimus absorbeo aspernatur. Aiunt solio amo sono tyrannus. | ||
| Conitor dens tamdiu acceptus vos cinis. Turpis varietas defungo pauci perferendis casso distinctio pauper. Patrocinor talio ducimus blandior deleo degusto pel sunt aliquam caecus. | ||
| Subnecto chirographum denego defessus tepidus beatae defessus. Est explicabo titulus valde pel testimonium tollo capto demo. Conculco omnis coepi placeat. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check correctly identifies that the destination directory doesn't exist. However, the requirement is to throw an error in this case, not just log a message to the console. Please change this to
throw new Error(...)to align with the requirements and the error handling on line 30.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I change this to :
if (!fs.existsSync(targetFolder)) {
throw new Error('Directory does not exist');
}
the tests are failing and I can't commit it
so I kept it as it is, because the tests are passing only with this console.error option