1 var path = require('path')
3 var test = require('tap').test
4 var statSync = require('graceful-fs').statSync
5 var mkdtemp = require('tmp').dir
6 var mkdirp = require('mkdirp')
8 var vacuum = require('../vacuum.js')
15 var SHORT_PATH = path.join('i', 'am', 'a', 'path')
16 var REMOVE_PATH = path.join(SHORT_PATH, 'of', 'a', 'certain', 'length')
17 var OTHER_PATH = path.join(SHORT_PATH, 'of', 'no', 'qualities')
20 function log () { messages.push(Array.prototype.slice.call(arguments).join(' ')) }
22 var testBase, testPath, otherPath
23 test('xXx setup xXx', function (t) {
24 mkdtemp(TEMP_OPTIONS, function (er, tmpdir) {
25 t.ifError(er, 'temp directory exists')
27 testBase = path.resolve(tmpdir, SHORT_PATH)
28 testPath = path.resolve(tmpdir, REMOVE_PATH)
29 otherPath = path.resolve(tmpdir, OTHER_PATH)
31 mkdirp(testPath, function (er) {
32 t.ifError(er, 'made test path')
34 mkdirp(otherPath, function (er) {
35 t.ifError(er, 'made other path')
43 test('remove up to a point', function (t) {
44 vacuum(testPath, {purge: false, base: testBase, log: log}, function (er) {
45 t.ifError(er, 'cleaned up to base')
47 t.equal(messages.length, 4, 'got 3 removal & 1 finish message')
49 messages[3], 'quitting because other entries in ' + testBase + '/of',
50 'got expected final message'
54 var verifyPath = testPath
55 function verify () { stat = statSync(verifyPath) }
57 for (var i = 0; i < 3; i++) {
58 t.throws(verify, verifyPath + ' cannot be statted')
59 t.notOk(stat && stat.isDirectory(), verifyPath + ' is totally gone')
60 verifyPath = path.dirname(verifyPath)
63 t.doesNotThrow(function () {
64 stat = statSync(otherPath)
65 }, otherPath + ' can be statted')
66 t.ok(stat && stat.isDirectory(), otherPath + ' is still a directory')
68 var intersection = path.join(testBase, 'of')
69 t.doesNotThrow(function () {
70 stat = statSync(intersection)
71 }, intersection + ' can be statted')
72 t.ok(stat && stat.isDirectory(), intersection + ' is still a directory')