]> 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/other-directories-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 / other-directories-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 REMOVE_PATH = path.join(SHORT_PATH, 'of', 'a', 'certain', 'length')
17 var OTHER_PATH = path.join(SHORT_PATH, 'of', 'no', 'qualities')
18
19 var messages = []
20 function log () { messages.push(Array.prototype.slice.call(arguments).join(' ')) }
21
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')
26
27     testBase = path.resolve(tmpdir, SHORT_PATH)
28     testPath = path.resolve(tmpdir, REMOVE_PATH)
29     otherPath = path.resolve(tmpdir, OTHER_PATH)
30
31     mkdirp(testPath, function (er) {
32       t.ifError(er, 'made test path')
33
34       mkdirp(otherPath, function (er) {
35         t.ifError(er, 'made other path')
36
37         t.end()
38       })
39     })
40   })
41 })
42
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')
46
47     t.equal(messages.length, 4, 'got 3 removal & 1 finish message')
48     t.equal(
49       messages[3], 'quitting because other entries in ' + testBase + '/of',
50       'got expected final message'
51     )
52
53     var stat
54     var verifyPath = testPath
55     function verify () { stat = statSync(verifyPath) }
56
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)
61     }
62
63     t.doesNotThrow(function () {
64       stat = statSync(otherPath)
65     }, otherPath + ' can be statted')
66     t.ok(stat && stat.isDirectory(), otherPath + ' is still a directory')
67
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')
73
74     t.end()
75   })
76 })