clobber.js 908 B

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