mkpath.js 1000 B

123456789101112131415161718192021222324252627282930313233
  1. /* Tests borrowed from substack's node-mkdirp
  2. * https://github.com/substack/node-mkdirp */
  3. var mkpath = require('../');
  4. var path = require('path');
  5. var fs = require('fs');
  6. var test = require('tap').test;
  7. test('woo', function (t) {
  8. t.plan(2);
  9. var x = Math.floor(Math.random() * Math.pow(16,4)).toString(16);
  10. var y = Math.floor(Math.random() * Math.pow(16,4)).toString(16);
  11. var z = Math.floor(Math.random() * Math.pow(16,4)).toString(16);
  12. var file = '/tmp/' + [x,y,z].join('/');
  13. mkpath(file, 0755, function (err) {
  14. if (err) t.fail(err);
  15. else path.exists(file, function (ex) {
  16. if (!ex) t.fail('file not created')
  17. else fs.stat(file, function (err, stat) {
  18. if (err) t.fail(err)
  19. else {
  20. t.equal(stat.mode & 0777, 0755);
  21. t.ok(stat.isDirectory(), 'target not a directory');
  22. t.end();
  23. }
  24. })
  25. })
  26. });
  27. });