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 LONG_PATH = path.join(SHORT_PATH, 'of', 'a', 'certain', 'length')
19 function log () { messages.push(Array.prototype.slice.call(arguments).join(' ')) }
21 var testPath, testBase
22 test('xXx setup xXx', function (t) {
23 mkdtemp(TEMP_OPTIONS, function (er, tmpdir) {
24 t.ifError(er, 'temp directory exists')
26 testBase = path.resolve(tmpdir, SHORT_PATH)
27 testPath = path.resolve(tmpdir, LONG_PATH)
29 mkdirp(testPath, function (er) {
30 t.ifError(er, 'made test path')
37 test('remove up to a point', function (t) {
38 vacuum(testPath, {purge: false, base: testBase, log: log}, function (er) {
39 t.ifError(er, 'cleaned up to base')
41 t.equal(messages.length, 5, 'got 4 removal & 1 finish message')
42 t.equal(messages[4], 'finished vacuuming up to ' + testBase)
45 var verifyPath = testPath
46 function verify () { stat = statSync(verifyPath) }
48 for (var i = 0; i < 4; i++) {
49 t.throws(verify, verifyPath + ' cannot be statted')
50 t.notOk(stat && stat.isDirectory(), verifyPath + ' is totally gone')
51 verifyPath = path.dirname(verifyPath)
54 t.doesNotThrow(function () {
55 stat = statSync(testBase)
56 }, testBase + ' can be statted')
57 t.ok(stat && stat.isDirectory(), testBase + ' is still a directory')