- I started by looking at the list of fs methods in Node.js Documentation and found one (rename) that is clear to me.
- After forking filer to my account, I looked at the existing tests and found out that there is no tests for the case when oldPath=newPath.
- I wrote a test expecting that a path will be overwritten (as it is stated in Linux Programmer's Manual). By the way, Node.js Docs also state "in the case that newPath already exists, it will be overwritten.
- Unfortunately, my test failed. But after numerous experiments and attempts to fix the test, I came to the conclusion that this method might actually work differently.
- This is why I rewrote my test in a way that it expects failure in method execution. And it passed.
Here is a final version of my test:
it('should fail to overwrite an existing file to itself', function (done) {
var fs = util.fs();
fs.open('/myfile', 'w+', function (error, fd) {
if (error) throw error;
fs.close(fd, function (error) {
if (error) throw error;
fs.rename('/myfile', '/myfile', function (error) {
expect(error).to.exist;
expect(error.code).to.equal('EEXIST');
done();
});
});
});
});
I created an issue stating that this test was missing: https://github.com/filerjs/filer/issues/493 and pull request with a test: https://github.com/filerjs/filer/pull/502
I also reveiwed peer's pull request: https://github.com/filerjs/filer/pull/539
describe('fsPromises.Write', function () {
it('should write, read a utf8 file without specifying utf8 in writeFile', function () {
//var fs = util.fs();
//var contents = 'This is a file.';
var fsPromises = util.fs().promises;
return fsPromises.writeFile('/myfile', { encoding: 'utf8' })
.then(() => {
return fsPromises.readFile('/myfile', 'utf8')
.catch((error) => {
expect(error).not.to.exist;
//expect(data).to.equal(contents);
//done();
});
});
});
});
After looking at this test, I went to existing tests and found out that this test already exists. Also, in return fsPromises.writeFile('/myfile' , { encoding: 'utf8' }) data parameter is missing.
I let pull request creator know about my comments.
I let pull request creator know about my comments.