forked from dominictarr/node-mkdirp
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
James Halliday
committed
Sep 10, 2011
1 parent
13b5e63
commit fb5e9db
Showing
4 changed files
with
42 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,28 @@ | ||
var assert = require('assert'); | ||
var mkdirp = require('../'); | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
var test = require('tap').test; | ||
|
||
exports.woo = function () { | ||
test('woo', function (t) { | ||
t.plan(2); | ||
var x = Math.floor(Math.random() * Math.pow(16,4)).toString(16); | ||
var y = Math.floor(Math.random() * Math.pow(16,4)).toString(16); | ||
var z = Math.floor(Math.random() * Math.pow(16,4)).toString(16); | ||
|
||
var file = '/tmp/' + [x,y,z].join('/'); | ||
var to = setTimeout(function () { | ||
assert.fail('never called back'); | ||
}, 1000); | ||
|
||
mkdirp(file, 0755, function (err) { | ||
if (err) assert.fail(err); | ||
if (err) t.fail(err); | ||
else path.exists(file, function (ex) { | ||
if (!ex) assert.fail('file not created') | ||
if (!ex) t.fail('file not created') | ||
else fs.stat(file, function (err, stat) { | ||
if (err) assert.fail(err) | ||
if (err) t.fail(err) | ||
else { | ||
clearTimeout(to); | ||
assert.eql(stat.mode & 0777, 0755); | ||
assert.ok(stat.isDirectory(), 'target not a directory'); | ||
t.equal(stat.mode & 0777, 0755); | ||
t.ok(stat.isDirectory(), 'target not a directory'); | ||
t.end(); | ||
} | ||
}) | ||
}) | ||
}); | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,41 @@ | ||
var assert = require('assert'); | ||
var mkdirp = require('../').mkdirp; | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
var test = require('tap').test; | ||
|
||
exports.race = function () { | ||
test('race', function (t) { | ||
t.plan(4); | ||
var ps = [ '', 'tmp' ]; | ||
|
||
for (var i = 0; i < 25; i++) { | ||
var dir = Math.floor(Math.random() * Math.pow(16,4)).toString(16); | ||
ps.push(dir); | ||
} | ||
var file = ps.join('/'); | ||
mk(file); | ||
mk(file); | ||
|
||
function mk (file) { | ||
var res = 2; | ||
mk(file, function () { | ||
if (--res === 0) t.end(); | ||
}); | ||
|
||
mk(file, function () { | ||
if (--res === 0) t.end(); | ||
}); | ||
|
||
function mk (file, cb) { | ||
mkdirp(file, 0755, function (err) { | ||
if (err) assert.fail(err); | ||
if (err) t.fail(err); | ||
else path.exists(file, function (ex) { | ||
if (!ex) assert.fail('file not created') | ||
if (!ex) t.fail('file not created') | ||
else fs.stat(file, function (err, stat) { | ||
if (err) assert.fail(err) | ||
if (err) t.fail(err) | ||
else { | ||
assert.eql(stat.mode & 0777, 0755); | ||
assert.ok(stat.isDirectory(), 'target not a directory'); | ||
t.equal(stat.mode & 0777, 0755); | ||
t.ok(stat.isDirectory(), 'target not a directory'); | ||
if (cb) cb(); | ||
} | ||
}) | ||
}) | ||
}); | ||
} | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters