sync.js 983 B

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('sync', 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. try {
  14. mkpath.sync(file, 0755);
  15. } catch (err) {
  16. t.fail(err);
  17. return t.end();
  18. }
  19. path.exists(file, function (ex) {
  20. if (!ex) t.fail('file not created')
  21. else fs.stat(file, function (err, stat) {
  22. if (err) t.fail(err)
  23. else {
  24. t.equal(stat.mode & 0777, 0755);
  25. t.ok(stat.isDirectory(), 'target not a directory');
  26. t.end();
  27. }
  28. });
  29. });
  30. });