-
Notifications
You must be signed in to change notification settings - Fork 438
added solution #355
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?
added solution #355
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,68 @@ | ||
| // write code here | ||
| /* eslint-disable no-console */ | ||
| 'use strict'; | ||
|
|
||
| const fs = require('fs/promises'); | ||
| const path = require('path'); | ||
|
|
||
| async function moveFile() { | ||
| const args = process.argv.slice(2); | ||
|
|
||
| const originPath = args[0]; | ||
| const pathToMove = args[1]; | ||
|
|
||
| if (!originPath) { | ||
| console.error('Source file path was not provided'); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| if (!pathToMove) { | ||
| console.error('Destination path was not provided'); | ||
|
|
||
| return; | ||
| } | ||
|
Comment on lines
+19
to
+23
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. Similar to the previous check, this error message could be more precise. It's checking for a missing command-line argument, not a path on the filesystem. Consider changing it to something like 'Destination path was not provided'. |
||
|
|
||
| if (originPath === pathToMove) { | ||
| return; | ||
| } | ||
|
|
||
| let sourceStat = null; | ||
|
|
||
| try { | ||
| sourceStat = await fs.stat(originPath); | ||
| } catch (e) { | ||
| console.error('File does not exist'); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| if (sourceStat.isDirectory()) { | ||
| console.error('Error: Source is a directory'); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| try { | ||
| let finalDest = pathToMove; | ||
|
|
||
| try { | ||
| const destStat = await fs.stat(pathToMove); | ||
|
|
||
| if (destStat.isDirectory()) { | ||
| finalDest = path.join(pathToMove, path.basename(originPath)); | ||
| } | ||
| } catch (e) { | ||
| if (pathToMove.endsWith('/') || pathToMove.endsWith('\\')) { | ||
| console.error('Path does not exist'); | ||
|
|
||
| return; | ||
|
Comment on lines
+56
to
+58
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 requirement states that an error must be thrown if a destination directory does not exist. Logging an error and returning causes the program to exit with a success code (0), which incorrectly signals that the operation succeeded. You should
Author
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. How should I do this if Cypress tests don't support this option, and exiting via
Comment on lines
+56
to
+58
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. According to the requirements, when a destination directory does not exist, an error must be thrown. Using |
||
| } | ||
| } | ||
|
|
||
| await fs.rename(originPath, finalDest); | ||
| } catch (error) { | ||
| console.error('Error:', error.message); | ||
|
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. This |
||
| } | ||
|
Comment on lines
+63
to
+65
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. This
Comment on lines
+63
to
+65
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. This |
||
| } | ||
|
|
||
| moveFile(); | ||
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 error message is slightly misleading. At this point, the program is checking for the presence of a command-line argument, not for the existence of a file on the filesystem. A clearer message might be 'Source file path was not provided'.