Skip to content
This repository was archived by the owner on Aug 15, 2024. It is now read-only.

Commit 4bd3ce4

Browse files
author
Spencer Elliott
committed
For async mkdir, call the callback when passed as the third argument
This is for parity with the Node.js fs.mkdir implementation, which may accept optional options as the 2nd argument.
1 parent 20dcd92 commit 4bd3ce4

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

lib/MemoryFileSystem.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ MemoryFileSystem.prototype.createWriteStream = function(path, options) {
273273

274274
// async functions
275275

276-
["stat", "readdir", "mkdirp", "mkdir", "rmdir", "unlink", "readlink"].forEach(function(fn) {
276+
["stat", "readdir", "mkdirp", "rmdir", "unlink", "readlink"].forEach(function(fn) {
277277
MemoryFileSystem.prototype[fn] = function(path, callback) {
278278
try {
279279
var result = this[fn + "Sync"](path);
@@ -284,23 +284,25 @@ MemoryFileSystem.prototype.createWriteStream = function(path, options) {
284284
};
285285
});
286286

287+
["mkdir", "readFile"].forEach(function(fn) {
288+
MemoryFileSystem.prototype[fn] = function(path, optArg, callback) {
289+
if(!callback) {
290+
callback = optArg;
291+
optArg = undefined;
292+
}
293+
try {
294+
var result = this[fn + "Sync"](path, optArg);
295+
} catch(e) {
296+
return callback(e);
297+
}
298+
return callback(null, result);
299+
};
300+
});
301+
287302
MemoryFileSystem.prototype.exists = function(path, callback) {
288303
return callback(this.existsSync(path));
289304
}
290305

291-
MemoryFileSystem.prototype.readFile = function(path, optArg, callback) {
292-
if(!callback) {
293-
callback = optArg;
294-
optArg = undefined;
295-
}
296-
try {
297-
var result = this.readFileSync(path, optArg);
298-
} catch(e) {
299-
return callback(e);
300-
}
301-
return callback(null, result);
302-
};
303-
304306
MemoryFileSystem.prototype.writeFile = function (path, content, encoding, callback) {
305307
if(!callback) {
306308
callback = encoding;

test/MemoryFileSystem.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ describe("directory", function() {
6565
stat.isDirectory().should.be.eql(true);
6666
fs.readdirSync("D:\\//a/depth/\\sub").should.be.eql(["dir"]);
6767
});
68+
it("should call a mkdir callback when passed as the third argument", function(done) {
69+
var fs = new MemoryFileSystem();
70+
fs.mkdir('/test', {}, function(err) {
71+
if (err) throw err;
72+
done();
73+
});
74+
});
6875
});
6976
describe("files", function() {
7077
it("should make and remove files", function() {

0 commit comments

Comments
 (0)