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

Add test for fs.appendFile to increase test coverage #629

Open
humphd opened this issue Dec 16, 2018 · 3 comments
Open

Add test for fs.appendFile to increase test coverage #629

humphd opened this issue Dec 16, 2018 · 3 comments
Labels
good first bug test-coverage Increase Test Coverage

Comments

@humphd
Copy link
Contributor

humphd commented Dec 16, 2018

We have a code path not being hit by our tests in fs.appendFile: https://codecov.io/gh/filerjs/filer/src/master/src/filesystem/implementation.js#L1895. To hit it, we need to:

  • add a test for fs.appendFile that pass invalid flags to options.flags (i.e., doesn't include a).
@humphd humphd added good first bug test-coverage Increase Test Coverage labels Dec 16, 2018
@PriyankaCodes99
Copy link
Contributor

I'm new to Open Source, but I would like to give this a try.

@humphd
Copy link
Contributor Author

humphd commented Feb 20, 2019

@PriyankaCodes99 OK, it's all yours. Here's how I would recommend you approach this.

First, you need a way to trigger this particular failure. Essentially, we want to have our test hit the code to deal with an invalid flag being passed. You can see the docs for appendFile, and they state that a flag is only valid if it's one of the strings in this list.

So we should be able to cause it if we do something like this (NOTE: I did this in node.js):

fs.appendFile('/file', 'data', { flag: 'invalid' }, function(err) { console.log(err); })
Error: Unknown file open flag: invalid
    at stringToFlags (internal/fs.js:59:9)
    at Object.fs.open (fs.js:637:16)
    at Object.fs.writeFile (fs.js:1277:6)
    at Object.fs.appendFile (fs.js:1332:6)

Now we need to turn that snippet of code into a test case that we can run. The file where you want to do this is tests/spec/fs.appendFile.spec.js. So you want to add another it() test to this file that tries to pass an invalid flag to appendFile and make sure we get back an error.

Let me know if you have questions about this, and I can say more.

@PriyankaCodes99
Copy link
Contributor

@humphd Thanks! I'll keep you updated with my progress.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first bug test-coverage Increase Test Coverage
Projects
None yet
Development

No branches or pull requests

2 participants