Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

now using tap

  • Loading branch information...
commit fb5e9db7191ab1049edff2d52877cecd82945598 1 parent 13b5e63
@substack substack authored
Showing with 42 additions and 37 deletions.
  1. +2 −2 package.json
  2. +10 −12 test/mkdirp.js
  3. +20 −11 test/race.js
  4. +10 −12 test/rel.js
View
4 package.json
@@ -13,10 +13,10 @@
"url" : "http://github.com/substack/node-mkdirp.git"
},
"scripts" : {
- "test" : "expresso"
+ "test" : "node node_modules/tap/bin/tap.js test/*.js"
},
"devDependencies" : {
- "expresso" : "0.7.x"
+ "tap" : "0.0.x"
},
"license" : "MIT/X11",
"engines": { "node": "*" }
View
22 test/mkdirp.js
@@ -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();
}
})
})
});
-};
+});
View
31 test/race.js
@@ -1,9 +1,10 @@
-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++) {
@@ -11,22 +12,30 @@ exports.race = function () {
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();
}
})
})
});
}
-};
+});
View
22 test/rel.js
@@ -1,9 +1,10 @@
-var assert = require('assert');
var mkdirp = require('../');
var path = require('path');
var fs = require('fs');
+var test = require('tap').test;
-exports.rel = function () {
+test('rel', 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);
@@ -12,23 +13,20 @@ exports.rel = function () {
process.chdir('/tmp');
var file = [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);
process.chdir(cwd);
- 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();
}
})
})
});
-};
+});
Please sign in to comment.
Something went wrong with that request. Please try again.