Skip to content
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

Fix #405 - Added tests for chmod and fchmod using Promises #458

Merged
merged 4 commits into from Oct 9, 2018

Conversation

danielbogomazov
Copy link
Contributor

@danielbogomazov danielbogomazov commented Sep 23, 2018

Added test cases for chmod and fchmod using Promises

Fix issue #405

Tests:

  • Whether they are functions
  • Whether they return a Promise object
  • Whether they change the mode of a file

Note
I separated the chmod and fchmod tests to pinpoint any possible future problems. If we use the non-promise test model, it will only report on fchmod being broken - even if both functions break (since we test for fchmod before chmod). We should consider splitting up the non-promises tests too. Maybe put fchmod into its own file?

Also, should the mkdir test case be moved to the mkdir test file?
Even though the main point of the test is to check whether the correct mode is being set by the function, it makes more sense to me to place a mkdir test in a mkdir test file.

Copy link
Contributor

@coreyjjames coreyjjames left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, Great Job with the tests!
One thing I noticed is that you changed the .gitignore and package.json as well. You didn't mention that in your pull request, so I am guessing you did it by accident.
When you git add , just add the file that you want to change.

.gitignore Outdated
@@ -4,6 +4,7 @@ bower_components
*~
dist/filer-issue225.js
.vscode
.DS_Store
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here

package.json Outdated
@@ -40,7 +40,7 @@
},
"devDependencies": {
"chai": "^4.1.2",
"eslint": "^5.0.1",
"eslint": "^5.6.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here

@danielbogomazov
Copy link
Contributor Author

@coreyjjames
Thanks for the heads-up. The files have been removed from the PR.

it('should allow for updating mode of a given file', function() {
var fsPromise = util.fs().promises;

return fsPromise.open('/file', 'w')
Copy link
Contributor

@biskit1 biskit1 Sep 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering about how you've nested these .then() and .catch() statements.
Is there a better way these can be nested?
Maybe instead of doing the return within return, just call the functions and have the .then() and .catch() for that function nested separately?
i.e

var fsPromise = util.fs().promises;
     return fsPromise.open('/file', 'w')
         .then(()=>{
              fsPromise.chmod('/file', 0o444)
                  .then(...)
                  .catch(...);
          }) 
         .catch(...);

I'm not sure what's considered best practice, or if it there is even a 'better' or 'worse' way to do it at all...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading this article on promise chaining leads me to believe that this sort of nesting is fine. However, I think in this case if you have a .catch() that throws an error, any proceeding .then() is never run, and it will just jump to the next .catch(). (see rethrowing portion of the article)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed the redundant .catch() blocks.
Thanks for the review.

@humphd humphd merged commit 87230ce into filerjs:master Oct 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants