clobber.js 855 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. var mkdirp = require('../').mkdirp;
  2. var path = require('path');
  3. var fs = require('fs');
  4. var test = require('tap').test;
  5. var _0755 = parseInt('0755', 8);
  6. var ps = [ '', 'tmp' ];
  7. for (var i = 0; i < 25; i++) {
  8. var dir = Math.floor(Math.random() * Math.pow(16,4)).toString(16);
  9. ps.push(dir);
  10. }
  11. var file = ps.join('/');
  12. // a file in the way
  13. var itw = ps.slice(0, 3).join('/');
  14. test('clobber-pre', function (t) {
  15. console.error("about to write to "+itw)
  16. fs.writeFileSync(itw, 'I AM IN THE WAY, THE TRUTH, AND THE LIGHT.');
  17. fs.stat(itw, function (er, stat) {
  18. t.ifError(er)
  19. t.ok(stat && stat.isFile(), 'should be file')
  20. t.end()
  21. })
  22. })
  23. test('clobber', function (t) {
  24. t.plan(2);
  25. mkdirp(file, _0755, function (err) {
  26. t.ok(err);
  27. t.equal(err.code, 'ENOTDIR');
  28. t.end();
  29. });
  30. });