sync.js 828 B

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