filer
filer copied to clipboard
Add test for fs.appendFile to increase test coverage
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.appendFilethat pass invalid flags tooptions.flags(i.e., doesn't includea).
I'm new to Open Source, but I would like to give this a try.
@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.
@humphd Thanks! I'll keep you updated with my progress.