From 2f3c3848687be6f80a84af530886f719db060fd0 Mon Sep 17 00:00:00 2001 From: Thanh Nguyen Date: Tue, 9 Oct 2018 13:51:19 -0400 Subject: [PATCH] Add test for fsPromises.rmdir() when dir not empty and dir is a file, Fix Issue 474 (#510) * Saving files before refreshing line endings * Adding test case for returning an error if the path is not a directory * Add return for fsPromises, and few other small fixes * Fix promises, and few done parameter * Update fs.rmdir.spec.js --- tests/spec/fs.rmdir.spec.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/spec/fs.rmdir.spec.js b/tests/spec/fs.rmdir.spec.js index 6e183be..de04079 100644 --- a/tests/spec/fs.rmdir.spec.js +++ b/tests/spec/fs.rmdir.spec.js @@ -121,3 +121,34 @@ describe('fs.rmdir', function() { }); }); }); + +describe('fs.promises.rmdir', function(){ + beforeEach(util.setup); + afterEach(util.cleanup); + + it('should return an error if the directory is not empty', function() { + var fs = util.fs(); + var fsPromises = fs.promises; + + return fsPromises.mkdir('/tmp') + .then(() => fsPromises.mkdir('/tmp/mydir')) + .then(() => fsPromises.rmdir('/')) + .catch(error => { + expect(error).to.exist; + expect(error.code).to.equal('EBUSY'); + }); + }); + + it('should return an error if the path is not a directory', function() { + var fs = util.fs(); + var fsPromises = fs.promises; + + return fsPromises.mkdir('/tmp') + .then(() => fsPromises.writeFile('/tmp/myfile','Hello World')) + .then(() => fsPromises.rmdir('/tmp/myfile')) + .catch(error => { + expect(error).to.exist; + expect(error.code).to.equal('ENOTDIR'); + }); + }); +});