filer icon indicating copy to clipboard operation
filer copied to clipboard

Add test for fs.appendFile to increase test coverage

Open humphd opened this issue 6 years ago • 3 comments

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 avatar Dec 16 '18 04:12 humphd

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

PriyankaCodes99 avatar Feb 20 '19 14:02 PriyankaCodes99

@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 avatar Feb 20 '19 16:02 humphd

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

PriyankaCodes99 avatar Feb 20 '19 16:02 PriyankaCodes99