]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/node_modules/fs-vacuum/test/no-entries-no-purge.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / node_modules / fs-vacuum / test / no-entries-no-purge.js
1 var path = require('path')
2
3 var test = require('tap').test
4 var statSync = require('graceful-fs').statSync
5 var mkdtemp = require('tmp').dir
6 var mkdirp = require('mkdirp')
7
8 var vacuum = require('../vacuum.js')
9
10 // CONSTANTS
11 var TEMP_OPTIONS = {
12   unsafeCleanup: true,
13   mode: '0700'
14 }
15 var SHORT_PATH = path.join('i', 'am', 'a', 'path')
16 var LONG_PATH = path.join(SHORT_PATH, 'of', 'a', 'certain', 'length')
17
18 var messages = []
19 function log () { messages.push(Array.prototype.slice.call(arguments).join(' ')) }
20
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')
25
26     testBase = path.resolve(tmpdir, SHORT_PATH)
27     testPath = path.resolve(tmpdir, LONG_PATH)
28
29     mkdirp(testPath, function (er) {
30       t.ifError(er, 'made test path')
31
32       t.end()
33     })
34   })
35 })
36
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')
40
41     t.equal(messages.length, 5, 'got 4 removal & 1 finish message')
42     t.equal(messages[4], 'finished vacuuming up to ' + testBase)
43
44     var stat
45     var verifyPath = testPath
46     function verify () { stat = statSync(verifyPath) }
47
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)
52     }
53
54     t.doesNotThrow(function () {
55       stat = statSync(testBase)
56     }, testBase + ' can be statted')
57     t.ok(stat && stat.isDirectory(), testBase + ' is still a directory')
58
59     t.end()
60   })
61 })