clobber.js 880 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. 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. mkpath(file, 0755, function (err) {
  26. t.ok(err);
  27. t.equal(err.code, 'ENOTDIR');
  28. t.end();
  29. });
  30. });