rel.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  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('rel', 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 cwd = process.cwd();
  13. process.chdir('/tmp');
  14. var file = [x,y,z].join('/');
  15. mkpath(file, 0755, function (err) {
  16. if (err) t.fail(err);
  17. else path.exists(file, function (ex) {
  18. if (!ex) t.fail('file not created')
  19. else fs.stat(file, function (err, stat) {
  20. if (err) t.fail(err)
  21. else {
  22. process.chdir(cwd);
  23. t.equal(stat.mode & 0777, 0755);
  24. t.ok(stat.isDirectory(), 'target not a directory');
  25. t.end();
  26. }
  27. })
  28. })
  29. });
  30. });