Skip to content

Commit fe63339

Browse files
committed
Update: Reach 100% code coverage
1 parent 2901690 commit fe63339

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

mkdirp.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var path = require('path');
44

55
var fs = require('graceful-fs');
66

7+
var MASK_MODE = parseInt('7777', 8);
78
var DEFAULT_DIR_MODE = parseInt('0777', 8);
89

910
function mkdirp(dirpath, customMode, callback) {
@@ -45,7 +46,8 @@ function mkdirp(dirpath, customMode, callback) {
4546
return callback(mkdirErr);
4647
}
4748

48-
if (stats.mode === mode) {
49+
// TODO: Is it proper to mask like this?
50+
if ((stats.mode & MASK_MODE) === mode) {
4951
return callback();
5052
}
5153

test/index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,27 @@ describe('mkdirpStream', function() {
165165
], done);
166166
});
167167

168+
it('bubbles mkdir errors', function(done) {
169+
170+
expect.spyOn(fs, 'mkdir').andCall(function(dirpath, mode, cb) {
171+
cb(new Error('boom'));
172+
});
173+
174+
function notExists() {
175+
statMode(outputDirpath);
176+
}
177+
178+
function assert(err) {
179+
expect(err).toExist();
180+
expect(notExists).toThrow();
181+
done();
182+
}
183+
184+
pipe([
185+
from(['test']),
186+
mkdirpStream(outputDirpath),
187+
concat(),
188+
], assert);
189+
});
190+
168191
});

test/mkdirp.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,4 +262,57 @@ describe('mkdirp', function() {
262262
});
263263
});
264264
});
265+
266+
it('surfaces mkdir errors that happening during recursion', function(done) {
267+
268+
var ogMkdir = fs.mkdir;
269+
270+
var spy = expect.spyOn(fs, 'mkdir').andCall(function(dirpath, mode, cb) {
271+
if (spy.calls.length === 1) {
272+
return ogMkdir(dirpath, mode, cb);
273+
}
274+
cb(new Error('boom'));
275+
});
276+
277+
mkdirp(outputNestedDirpath, function(err) {
278+
expect(err).toExist();
279+
280+
done();
281+
});
282+
});
283+
284+
it('surfaces fs.stat errors', function(done) {
285+
286+
expect.spyOn(fs, 'stat').andCall(function(dirpath, cb) {
287+
cb(new Error('boom'));
288+
});
289+
290+
mkdirp(outputDirpath, function(err) {
291+
expect(err).toExist();
292+
293+
done();
294+
});
295+
});
296+
297+
it('does not attempt fs.chmod if custom mode matches mode on disk', function(done) {
298+
if (isWindows) {
299+
this.skip();
300+
return;
301+
}
302+
303+
var mode = applyUmask('700');
304+
305+
mkdirp(outputDirpath, mode, function(err) {
306+
expect(err).toNotExist();
307+
308+
var spy = expect.spyOn(fs, 'chmod').andCallThrough();
309+
310+
mkdirp(outputDirpath, mode, function(err) {
311+
expect(err).toNotExist();
312+
expect(spy.calls.length).toEqual(0);
313+
314+
done();
315+
});
316+
});
317+
});
265318
});

0 commit comments

Comments
 (0)