| 1 |
"use strict"; |
| 2 |
|
| 3 |
var fs = require("fs") |
| 4 |
, deferred = require("deferred") |
| 5 |
, resolve = require("path").resolve |
| 6 |
, promisify = deferred.promisify |
| 7 |
, delay = deferred.delay |
| 8 |
, mkdir = promisify(fs.mkdir) |
| 9 |
, rmdir = promisify(fs.rmdir) |
| 10 |
, gitMode = require("../../lib/ignore-modes/git") |
| 11 |
, rootPath = resolve(__dirname, "../__playground/lib/find-root"); |
| 12 |
|
| 13 |
module.exports = function (t, a, d) { |
| 14 |
var gitRoot = resolve(rootPath, ".git") |
| 15 |
, onePath = resolve(rootPath, "one") |
| 16 |
, gitOnePath = resolve(onePath, ".git") |
| 17 |
, twoPath = resolve(onePath, "two") |
| 18 |
, gitTwoPath = resolve(twoPath, ".git") |
| 19 |
, filePath = resolve(twoPath, "file.xxx"); |
| 20 |
|
| 21 |
var DELAY = 100, watcher, events = []; |
| 22 |
|
| 23 |
// Create /.git |
| 24 |
mkdir(gitRoot)(function () { |
| 25 |
// Create /one |
| 26 |
return mkdir(onePath); |
| 27 |
})(function () { |
| 28 |
// Create /one/.git |
| 29 |
return mkdir(gitOnePath); |
| 30 |
})(function () { |
| 31 |
watcher = t(gitMode.isRootWatcher, filePath, { watch: true }); |
| 32 |
watcher.on("change", function (path) { events.push(path); }); |
| 33 |
return watcher; |
| 34 |
})(function (path) { a(path, onePath, "#1"); })( |
| 35 |
delay(function () { |
| 36 |
a(String(events), "", "#1: Event"); |
| 37 |
events = []; |
| 38 |
|
| 39 |
// Create /one/two |
| 40 |
return mkdir(twoPath); |
| 41 |
}, DELAY) |
| 42 |
)( |
| 43 |
delay(function () { |
| 44 |
// Create /one/two/.git |
| 45 |
return mkdir(gitTwoPath); |
| 46 |
}, DELAY) |
| 47 |
)( |
| 48 |
delay(function () { |
| 49 |
a(String(events), twoPath, "#2: Event"); |
| 50 |
events = []; |
| 51 |
return t(gitMode.isRoot, filePath); |
| 52 |
}, DELAY) |
| 53 |
)(function (path) { |
| 54 |
a(path, twoPath, "#2"); |
| 55 |
|
| 56 |
// Remove /one/.git |
| 57 |
return rmdir(gitOnePath); |
| 58 |
})( |
| 59 |
delay(function () { |
| 60 |
// Remove /one/two/.git |
| 61 |
return rmdir(gitTwoPath); |
| 62 |
}, DELAY) |
| 63 |
)( |
| 64 |
delay(function () { |
| 65 |
a(String(events), rootPath, "#3: Event"); |
| 66 |
events = []; |
| 67 |
return t(gitMode.isRoot, filePath); |
| 68 |
}, DELAY) |
| 69 |
)(function (path) { |
| 70 |
a(path, rootPath, "#3"); |
| 71 |
|
| 72 |
// Create /one/two/.git |
| 73 |
return mkdir(gitTwoPath); |
| 74 |
})( |
| 75 |
delay(function () { |
| 76 |
a(String(events), twoPath, "#4: Event"); |
| 77 |
events = []; |
| 78 |
return t(gitMode.isRoot, filePath); |
| 79 |
}, DELAY) |
| 80 |
)(function (path) { |
| 81 |
a(path, twoPath, "#4"); |
| 82 |
|
| 83 |
// Remove /one/two/.git |
| 84 |
return rmdir(gitTwoPath); |
| 85 |
})(function () { |
| 86 |
// Remove /one/two |
| 87 |
return rmdir(twoPath); |
| 88 |
})(function () { |
| 89 |
// Remove /one |
| 90 |
return rmdir(onePath); |
| 91 |
})( |
| 92 |
delay(function () { |
| 93 |
a(String(events), rootPath, "#5: Event"); |
| 94 |
events = []; |
| 95 |
return t(gitMode.isRoot, filePath); |
| 96 |
}, DELAY) |
| 97 |
)(function (path) { |
| 98 |
a(path, rootPath, "#5"); |
| 99 |
|
| 100 |
watcher.close(); |
| 101 |
return rmdir(gitRoot); |
| 102 |
}).done(d, d); |
| 103 |
}; |