| 1 |
"use strict"; |
| 2 |
|
| 3 |
var isValue = require("es5-ext/object/is-value") |
| 4 |
, fs = require("fs") |
| 5 |
, deferred = require("deferred") |
| 6 |
, resolve = require("path").resolve |
| 7 |
, promisify = deferred.promisify |
| 8 |
, delay = deferred.delay |
| 9 |
, mkdir = promisify(fs.mkdir) |
| 10 |
, rmdir = promisify(fs.rmdir) |
| 11 |
, isArray = Array.isArray |
| 12 |
, rootPath = resolve(__dirname, "../../__playground/lib/ignore-modes/git"); |
| 13 |
|
| 14 |
module.exports = function (t, a, d) { |
| 15 |
var gitRoot = resolve(rootPath, ".git") |
| 16 |
, onePath = resolve(rootPath, "one") |
| 17 |
, gitOnePath = resolve(onePath, ".git") |
| 18 |
, twoPath = resolve(onePath, "two") |
| 19 |
, gitTwoPath = resolve(twoPath, ".git") |
| 20 |
, rootEvents = [] |
| 21 |
, oneEvents = [] |
| 22 |
, twoEvents = [] |
| 23 |
, w1 |
| 24 |
, w2 |
| 25 |
, w3; |
| 26 |
|
| 27 |
a(typeof t.filename, "string", "Filename"); |
| 28 |
a(!isValue(t.globalRules) || isArray(t.globalRules), true, "Global rules"); |
| 29 |
|
| 30 |
// Create /.git |
| 31 |
mkdir(gitRoot)(function () { |
| 32 |
// Create /one |
| 33 |
return mkdir(onePath); |
| 34 |
})(function () { |
| 35 |
// Create /one/.git |
| 36 |
return mkdir(gitOnePath); |
| 37 |
})(function () { |
| 38 |
w1 = t.isRootWatcher(rootPath); |
| 39 |
w1.on("change", function (value) { rootEvents.push(value); }); |
| 40 |
w2 = t.isRootWatcher(onePath); |
| 41 |
w2.on("change", function (value) { oneEvents.push(value); }); |
| 42 |
w3 = t.isRootWatcher(twoPath); |
| 43 |
w3.on("change", function (value) { twoEvents.push(value); }); |
| 44 |
return deferred(w1, w2, w3); |
| 45 |
})( |
| 46 |
delay(function (data) { |
| 47 |
a.deep(data, [true, true, false], "#1"); |
| 48 |
a(String(rootEvents), "", "#1: Root Event"); |
| 49 |
a(String(oneEvents), "", "#1: One Event"); |
| 50 |
a(String(twoEvents), "", "#1: Two Event"); |
| 51 |
rootEvents = []; |
| 52 |
oneEvents = []; |
| 53 |
twoEvents = []; |
| 54 |
|
| 55 |
// Create /one/two |
| 56 |
return mkdir(twoPath); |
| 57 |
}, 20) |
| 58 |
)( |
| 59 |
delay(function () { |
| 60 |
// Create /one/two/.git |
| 61 |
return mkdir(gitTwoPath); |
| 62 |
}, 20) |
| 63 |
)( |
| 64 |
delay(function () { |
| 65 |
a(String(rootEvents), "", "#2: Root Event"); |
| 66 |
a(String(oneEvents), "", "#2: One Event"); |
| 67 |
a(String(twoEvents), "true", "#2: Two Event"); |
| 68 |
rootEvents = []; |
| 69 |
oneEvents = []; |
| 70 |
twoEvents = []; |
| 71 |
|
| 72 |
return deferred(t.isRoot(rootPath), t.isRoot(onePath), t.isRoot(twoPath)); |
| 73 |
}, 20) |
| 74 |
)(function (data) { |
| 75 |
a.deep(data, [true, true, true], "#2"); |
| 76 |
|
| 77 |
// Remove /one/.git |
| 78 |
return rmdir(gitOnePath); |
| 79 |
})( |
| 80 |
delay(function () { |
| 81 |
a(String(rootEvents), "", "#3: Root Event"); |
| 82 |
a(String(oneEvents), "false", "#3: One Event"); |
| 83 |
a(String(twoEvents), "", "#3: Two Event"); |
| 84 |
rootEvents = []; |
| 85 |
oneEvents = []; |
| 86 |
twoEvents = []; |
| 87 |
|
| 88 |
return deferred(t.isRoot(rootPath), t.isRoot(onePath), t.isRoot(twoPath)); |
| 89 |
}, 20) |
| 90 |
)(function (data) { |
| 91 |
a.deep(data, [true, false, true], "#3"); |
| 92 |
|
| 93 |
// Remove /one/two/.git |
| 94 |
return rmdir(gitTwoPath); |
| 95 |
})( |
| 96 |
delay(function () { |
| 97 |
a(String(rootEvents), "", "#4: Root Event"); |
| 98 |
a(String(oneEvents), "", "#4: One Event"); |
| 99 |
a(String(twoEvents), "false", "#4: Two Event"); |
| 100 |
rootEvents = []; |
| 101 |
oneEvents = []; |
| 102 |
twoEvents = []; |
| 103 |
|
| 104 |
return deferred(t.isRoot(rootPath), t.isRoot(onePath), t.isRoot(twoPath)); |
| 105 |
}, 20) |
| 106 |
)(function (data) { |
| 107 |
a.deep(data, [true, false, false], "#4"); |
| 108 |
|
| 109 |
// Create /one/two/.git |
| 110 |
return mkdir(gitTwoPath); |
| 111 |
})( |
| 112 |
delay(function () { |
| 113 |
a(String(rootEvents), "", "#5: Root Event"); |
| 114 |
a(String(oneEvents), "", "#5: One Event"); |
| 115 |
a(String(twoEvents), "true", "#5: Two Event"); |
| 116 |
rootEvents = []; |
| 117 |
oneEvents = []; |
| 118 |
twoEvents = []; |
| 119 |
|
| 120 |
return deferred(t.isRoot(rootPath), t.isRoot(onePath), t.isRoot(twoPath)); |
| 121 |
}, 20) |
| 122 |
)(function (data) { |
| 123 |
a.deep(data, [true, false, true], "#5"); |
| 124 |
|
| 125 |
// Remove /one/two/.git |
| 126 |
return rmdir(gitTwoPath); |
| 127 |
})( |
| 128 |
delay(function () { |
| 129 |
a(String(rootEvents), "", "#6: Root Event"); |
| 130 |
a(String(oneEvents), "", "#6: One Event"); |
| 131 |
a(String(twoEvents), "false", "#6: Two Event"); |
| 132 |
rootEvents = []; |
| 133 |
oneEvents = []; |
| 134 |
twoEvents = []; |
| 135 |
|
| 136 |
return deferred(t.isRoot(rootPath), t.isRoot(onePath), t.isRoot(twoPath)); |
| 137 |
}, 20) |
| 138 |
)(function (data) { a.deep(data, [true, false, false], "#6"); })(function () { |
| 139 |
// Remove /one/two |
| 140 |
return rmdir(twoPath); |
| 141 |
})(function () { |
| 142 |
// Remove /one |
| 143 |
return rmdir(onePath); |
| 144 |
})( |
| 145 |
delay(function () { |
| 146 |
a(String(rootEvents), "", "#7: Root Event"); |
| 147 |
a(String(oneEvents), "", "#7: One Event"); |
| 148 |
a(String(twoEvents), "", "#7: Two Event"); |
| 149 |
rootEvents = []; |
| 150 |
oneEvents = []; |
| 151 |
twoEvents = []; |
| 152 |
|
| 153 |
return deferred(t.isRoot(rootPath), t.isRoot(onePath), t.isRoot(twoPath)); |
| 154 |
}, 20) |
| 155 |
)(function (data) { |
| 156 |
a.deep(data, [true, false, false], "#7"); |
| 157 |
|
| 158 |
w1.close(); |
| 159 |
w2.close(); |
| 160 |
w3.close(); |
| 161 |
return rmdir(gitRoot); |
| 162 |
}).done(d, d); |
| 163 |
}; |