Skip to content

Commit

Permalink
chore: Add test for readdir error
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Aug 26, 2022
1 parent 7b66e09 commit 1c20531
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"eslint-plugin-node": "^11.1.0",
"expect": "^27.0.0",
"mocha": "^8.0.0",
"nyc": "^15.0.0"
"nyc": "^15.0.0",
"sinon": "^12.0.1"
},
"nyc": {
"reporter": [
Expand Down
16 changes: 16 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var fs = require('fs');
var path = require('path');

var expect = require('expect');
var sinon = require('sinon');

var emptyDir = require('../');
try {
Expand Down Expand Up @@ -79,6 +80,21 @@ describe('emptyDir', function () {
});
});

it('surfaces readdir error if one occurs', function (done) {
sinon.stub(fs, 'readdir').callsFake(function (dirpath, cb) {
cb(new Error('boom'));
});

emptyDir('./test/empty', function (err, empty) {
fs.readdir.restore();

expect(err).toBeDefined();
expect(empty).toBeUndefined();

done();
});
});

describe('without a callback argument', function () {
it('should return a Promise', function (done) {
var p = emptyDir('./test/empty');
Expand Down

0 comments on commit 1c20531

Please sign in to comment.