rmdirSyncRecursive.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. var testCase = require('nodeunit').testCase;
  2. var fs = require('fs');
  3. var wrench = require('../lib/wrench');
  4. var path = require('path');
  5. module.exports = testCase({
  6. test_rmdirSyncRecursive: function(test) {
  7. var dir = __dirname + '/_tmp2/foo/bar';
  8. wrench.mkdirSyncRecursive(dir, '777');
  9. var f1Path = path.join(dir, 'test1.txt');
  10. var f2Path = path.join(path.dirname(dir), 'test2.txt');
  11. var f3Path = path.join(path.dirname(path.dirname(dir)), 'test3.txt');
  12. fs.writeFileSync(f1Path, 'foo bar baz');
  13. fs.writeFileSync(f2Path, 'foo bar baz');
  14. fs.writeFileSync(f3Path, 'foo bar baz');
  15. fs.chmodSync(f1Path, '444');
  16. fs.chmodSync(f2Path, '444');
  17. fs.chmodSync(f3Path, '444');
  18. test.equals(fs.existsSync(dir), true, 'Dir should exist - mkdirSyncRecursive not working?');
  19. test.equals(fs.existsSync(f1Path), true, 'File should exist');
  20. test.equals(fs.existsSync(f2Path), true, 'File should exist');
  21. test.equals(fs.existsSync(f3Path), true, 'File should exist');
  22. wrench.rmdirSyncRecursive(dir);
  23. test.equals(fs.existsSync(dir), false, 'Dir should not exist now...');
  24. test.equals(fs.existsSync(f1Path), false, 'File should not exist');
  25. test.equals(fs.existsSync(f2Path), true, 'File should exist');
  26. test.equals(fs.existsSync(f3Path), true, 'File should exist');
  27. wrench.rmdirSyncRecursive(path.dirname(path.dirname(dir)));
  28. test.done();
  29. },
  30. test_rmdirSyncRecursiveFromRoot: function(test) {
  31. var dir = __dirname + '/_tmp3/foo/bar';
  32. wrench.mkdirSyncRecursive(dir, '777');
  33. var f1Path = path.join(dir, 'test1.txt');
  34. var f2Path = path.join(path.dirname(dir), 'test2.txt');
  35. var f3Path = path.join(path.dirname(path.dirname(dir)), 'test3.txt');
  36. fs.writeFileSync(f1Path, 'foo bar baz');
  37. fs.writeFileSync(f2Path, 'foo bar baz');
  38. fs.writeFileSync(f3Path, 'foo bar baz');
  39. fs.chmodSync(f1Path, '444');
  40. fs.chmodSync(f2Path, '444');
  41. fs.chmodSync(f3Path, '444');
  42. test.equals(fs.existsSync(dir), true, 'Dir should exist - mkdirSyncRecursive not working?');
  43. test.equals(fs.existsSync(f1Path), true, 'File should exist');
  44. test.equals(fs.existsSync(f2Path), true, 'File should exist');
  45. test.equals(fs.existsSync(f3Path), true, 'File should exist');
  46. wrench.rmdirSyncRecursive(path.dirname(path.dirname(dir)));
  47. test.equals(fs.existsSync(dir), false, 'Dir should not exist now...');
  48. test.equals(fs.existsSync(f1Path), false, 'File should not exist');
  49. test.equals(fs.existsSync(f2Path), false, 'File should not exist');
  50. test.equals(fs.existsSync(f3Path), false, 'File should not exist');
  51. test.done();
  52. }
  53. });
  54. // vim: et ts=4 sw=4