| 1 |
/* eslint max-lines: off */ |
| 2 |
|
| 3 |
"use strict"; |
| 4 |
|
| 5 |
var push = Array.prototype.push |
| 6 |
, fs = require("fs") |
| 7 |
, pathUtils = require("path") |
| 8 |
, aFrom = require("es5-ext/array/from") |
| 9 |
, diff = require("es5-ext/array/#/diff") |
| 10 |
, startsWith = require("es5-ext/string/#/starts-with") |
| 11 |
, deferred = require("deferred") |
| 12 |
, delay = deferred.delay |
| 13 |
, promisify = deferred.promisify |
| 14 |
, mkdir = promisify(fs.mkdir) |
| 15 |
, writeFile = promisify(fs.writeFile) |
| 16 |
, unlink = promisify(fs.unlink) |
| 17 |
, rmdir = promisify(fs.rmdir) |
| 18 |
, basename = pathUtils.basename |
| 19 |
, resolve = pathUtils.resolve |
| 20 |
, sep = pathUtils.sep |
| 21 |
, pgPath = resolve(__dirname, "./__playground/readdir"); |
| 22 |
|
| 23 |
module.exports = function (t) { |
| 24 |
var pathsAll, paths2, paths0, files2, replaceSep, DELAY = 100; |
| 25 |
replaceSep = function (path) { return path.replace(/\//g, sep); }; |
| 26 |
pathsAll = [ |
| 27 |
"done", "done/done", "done/done/dthree", "done/done/dthree/dthree", |
| 28 |
"done/done/dthree/dthree/foo", "done/done/dthree/dtwo", "done/done/dthree/dtwo/foo", |
| 29 |
"done/done/dthree/one", "done/done/dthree/three", "done/done/dthree/two", "done/done/dtwo", |
| 30 |
"done/done/dtwo/dtwo", "done/done/dtwo/dtwo/foo", "done/done/dtwo/one", |
| 31 |
"done/done/dtwo/three", "done/done/dtwo/two", "done/done/one", "done/done/three", |
| 32 |
"done/done/two", "done/dtwo", "done/dtwo/foo", "done/one", "done/three", "done/two", |
| 33 |
"dthree", "dthree/dthree", "dthree/dthree/done", "dthree/dthree/done/dthree", |
| 34 |
"dthree/dthree/done/dthree/foo", "dthree/dthree/done/one", "dthree/dthree/done/three", |
| 35 |
"dthree/dthree/done/two", "dthree/dthree/one", "dthree/dthree/three", "dthree/dthree/two", |
| 36 |
"dthree/dtwo", "dthree/dtwo/foo", "dthree/one", "dthree/three", "dthree/two", "dtwo", |
| 37 |
"dtwo/one", "dtwo/three", "dtwo/two", "one", "three", "two" |
| 38 |
].map(replaceSep); |
| 39 |
|
| 40 |
paths2 = pathsAll.filter(function (path) { return path.split(sep).length < 4; }); |
| 41 |
|
| 42 |
paths0 = pathsAll.filter(function (path) { return path.split(sep).length < 2; }); |
| 43 |
|
| 44 |
files2 = paths2.filter(function (path) { return basename(path)[0] !== "d"; }); |
| 45 |
|
| 46 |
return { |
| 47 |
"": { |
| 48 |
"0": function (a, d) { |
| 49 |
var reader = t(pgPath, { watch: true }) |
| 50 |
, testName = "foo" |
| 51 |
, testPath = resolve(pgPath, testName) |
| 52 |
, paths = paths0 |
| 53 |
, invoked = false; |
| 54 |
|
| 55 |
reader.on("change", function (data) { invoked = data; }); |
| 56 |
reader( |
| 57 |
delay(function (data) { |
| 58 |
a.deep(data.sort(), paths); |
| 59 |
return mkdir(testPath); |
| 60 |
}, DELAY * 2) |
| 61 |
)( |
| 62 |
delay(function () { |
| 63 |
a.deep(invoked.removed, [], "Created: removed"); |
| 64 |
a.deep(invoked.added, [testName], "Created: added"); |
| 65 |
invoked = false; |
| 66 |
reader(function (data) { |
| 67 |
var npaths = aFrom(paths); |
| 68 |
npaths.push(testName); |
| 69 |
a.deep(data.sort(), npaths.sort(), "Created: data"); |
| 70 |
}).done(); |
| 71 |
return t(pgPath); |
| 72 |
}, DELAY) |
| 73 |
)(function (data) { |
| 74 |
var npaths = aFrom(paths); |
| 75 |
npaths.push(testName); |
| 76 |
a.deep(data.sort(), npaths.sort(), "Not watched"); |
| 77 |
return rmdir(testPath); |
| 78 |
})( |
| 79 |
delay(function () { |
| 80 |
a.deep(invoked.removed, [testName], "Deleted: removed"); |
| 81 |
a.deep(invoked.added, [], "Deleted: added"); |
| 82 |
invoked = false; |
| 83 |
reader(function (data) { |
| 84 |
a.deep(data.sort(), paths, "Deleted: data"); |
| 85 |
}).done(); |
| 86 |
reader.close(); |
| 87 |
}, DELAY) |
| 88 |
).done(d, d); |
| 89 |
}, |
| 90 |
"2": function (a, d) { |
| 91 |
var reader = t(pgPath, { depth: 2, watch: true }) |
| 92 |
, testName = replaceSep("dtwo/foo") |
| 93 |
, testPath = resolve(pgPath, testName) |
| 94 |
, paths = paths2 |
| 95 |
, invoked = false; |
| 96 |
|
| 97 |
reader.on("change", function (data) { invoked = data; }); |
| 98 |
reader(function (data) { a.deep(data.sort(), paths); })( |
| 99 |
delay(function () { return mkdir(testPath); }, DELAY) |
| 100 |
)( |
| 101 |
delay(function () { |
| 102 |
a.deep(invoked.removed, [], "Created: removed"); |
| 103 |
a.deep(invoked.added, [testName], "Created: added"); |
| 104 |
invoked = false; |
| 105 |
reader(function (data) { |
| 106 |
var npaths = aFrom(paths); |
| 107 |
npaths.push(testName); |
| 108 |
a.deep(data.sort(), npaths.sort(), "Created: data"); |
| 109 |
}).done(); |
| 110 |
return t(pgPath, { depth: 2 }); |
| 111 |
}, DELAY) |
| 112 |
)(function (data) { |
| 113 |
var npaths = aFrom(paths); |
| 114 |
npaths.push(testName); |
| 115 |
a.deep(data.sort(), npaths.sort(), "Not watched"); |
| 116 |
return rmdir(testPath); |
| 117 |
})( |
| 118 |
delay(function () { |
| 119 |
a.deep(invoked.removed, [testName], "Deleted: removed"); |
| 120 |
a.deep(invoked.added, [], "Deleted: added"); |
| 121 |
invoked = false; |
| 122 |
reader(function (data) { |
| 123 |
a.deep(data.sort(), paths, "Deleted: data"); |
| 124 |
}).done(); |
| 125 |
reader.close(); |
| 126 |
}, DELAY) |
| 127 |
).done(d, d); |
| 128 |
}, |
| 129 |
"∞": function (a, d) { |
| 130 |
var reader = t(pgPath, { depth: Infinity, watch: true }) |
| 131 |
, testName = replaceSep("done/done/dthree/test") |
| 132 |
, testPath = resolve(pgPath, testName) |
| 133 |
, paths = pathsAll |
| 134 |
, invoked = false; |
| 135 |
|
| 136 |
reader.on("change", function (data) { invoked = data; }); |
| 137 |
reader(function (data) { a.deep(data.sort(), paths); })( |
| 138 |
delay(function () { return writeFile(testPath, "foo"); }, DELAY) |
| 139 |
)( |
| 140 |
delay(function () { |
| 141 |
a.deep(invoked.removed, [], "Created: removed"); |
| 142 |
a.deep(invoked.added, [testName], "Created: added"); |
| 143 |
invoked = false; |
| 144 |
reader(function (data) { |
| 145 |
var npaths = aFrom(paths); |
| 146 |
npaths.push(testName); |
| 147 |
a.deep(data.sort(), npaths.sort(), "Created: data"); |
| 148 |
}).done(); |
| 149 |
return t(pgPath, { depth: Infinity }); |
| 150 |
}, DELAY) |
| 151 |
)(function (data) { |
| 152 |
var npaths = aFrom(paths); |
| 153 |
npaths.push(testName); |
| 154 |
a.deep(data.sort(), npaths.sort(), "Not watched"); |
| 155 |
return unlink(testPath); |
| 156 |
})( |
| 157 |
delay(function () { |
| 158 |
a.deep(invoked.removed, [testName], "Deleted: removed"); |
| 159 |
a.deep(invoked.added, [], "Deleted: added"); |
| 160 |
invoked = false; |
| 161 |
reader(function (data) { |
| 162 |
a.deep(data.sort(), paths, "Deleted: data"); |
| 163 |
}).done(); |
| 164 |
reader.close(); |
| 165 |
}, DELAY) |
| 166 |
).done(d, d); |
| 167 |
} |
| 168 |
}, |
| 169 |
"Loose": function (a, d) { |
| 170 |
var reader = t(resolve(pgPath, "not-existing"), { loose: true }); |
| 171 |
|
| 172 |
reader(function (data) { a(data, null); }).done(d, d); |
| 173 |
}, |
| 174 |
"Progress events": function (a, d) { |
| 175 |
var reader = t(pgPath, { depth: Infinity, stream: true }) |
| 176 |
, result = [] |
| 177 |
, lengths = [] |
| 178 |
, count = 0; |
| 179 |
|
| 180 |
reader.on("change", function (data) { |
| 181 |
++count; |
| 182 |
lengths.push(data.added.length); |
| 183 |
a.deep(data.removed, [], "Removed #" + count); |
| 184 |
push.apply(result, data.added); |
| 185 |
a.deep(result.sort(), data.data.sort(), "Data #" + count); |
| 186 |
}); |
| 187 |
reader(function (data) { |
| 188 |
a.deep(lengths.sort(), [1, 1, 1, 1, 1, 1, 3, 4, 4, 4, 5, 5, 5, 5, 6], "Events"); |
| 189 |
a.deep(result.sort(), data.sort(), "Result"); |
| 190 |
}).done(d, d); |
| 191 |
}, |
| 192 |
"Type": function (a, d) { |
| 193 |
var reader = t(pgPath, { depth: 2, type: { file: true }, watch: true }) |
| 194 |
, testName = replaceSep("dtwo/test") |
| 195 |
, testPath = resolve(pgPath, testName) |
| 196 |
, paths = files2 |
| 197 |
, invoked = false; |
| 198 |
|
| 199 |
reader.on("change", function (data) { invoked = data; }); |
| 200 |
reader(function (data) { |
| 201 |
a.deep(data.sort(), paths); |
| 202 |
return mkdir(testPath); |
| 203 |
})( |
| 204 |
delay(function () { |
| 205 |
a(invoked, false, "Created other type: event"); |
| 206 |
invoked = false; |
| 207 |
reader(function (data) { |
| 208 |
a.deep(data.sort(), paths, "Created other type: data"); |
| 209 |
}).done(); |
| 210 |
return rmdir(testPath); |
| 211 |
}, DELAY) |
| 212 |
)( |
| 213 |
delay(function () { |
| 214 |
a(invoked, false, "Deleted other type: event"); |
| 215 |
invoked = false; |
| 216 |
reader(function (data) { |
| 217 |
a.deep(data.sort(), paths, "Deleted other type: data"); |
| 218 |
}).done(); |
| 219 |
return writeFile(testPath, "foo"); |
| 220 |
}, DELAY) |
| 221 |
)( |
| 222 |
delay(function () { |
| 223 |
a.deep(invoked.removed, [], "Created: removed"); |
| 224 |
a.deep(invoked.added, [testName], "Created: added"); |
| 225 |
invoked = false; |
| 226 |
reader(function (data) { |
| 227 |
var npaths = aFrom(paths); |
| 228 |
npaths.push(testName); |
| 229 |
a.deep(data.sort(), npaths.sort(), "Created: data"); |
| 230 |
}).done(); |
| 231 |
return t(pgPath, { depth: 2, type: { file: true } }); |
| 232 |
}, DELAY) |
| 233 |
)(function (data) { |
| 234 |
var npaths = aFrom(paths); |
| 235 |
npaths.push(testName); |
| 236 |
a.deep(data.sort(), npaths.sort(), "Not watched"); |
| 237 |
return unlink(testPath); |
| 238 |
})( |
| 239 |
delay(function () { |
| 240 |
a.deep(invoked.removed, [testName], "Deleted: removed"); |
| 241 |
a.deep(invoked.added, [], "Deleted: added"); |
| 242 |
invoked = false; |
| 243 |
reader(function (data) { a.deep(data.sort(), paths, "Deleted: data"); }).done(); |
| 244 |
reader.close(); |
| 245 |
}, DELAY) |
| 246 |
).done(d, d); |
| 247 |
}, |
| 248 |
"Types": function (a, d) { |
| 249 |
var reader = t(pgPath, { depth: 2, type: { file: true, directory: true }, watch: true }) |
| 250 |
, testName = replaceSep("dtwo/foo") |
| 251 |
, testPath = resolve(pgPath, testName) |
| 252 |
, paths = paths2 |
| 253 |
, invoked = false; |
| 254 |
|
| 255 |
reader.on("change", function (data) { invoked = data; }); |
| 256 |
reader( |
| 257 |
delay(function (data) { |
| 258 |
a.deep(data.sort(), paths); |
| 259 |
return mkdir(testPath); |
| 260 |
}, DELAY) |
| 261 |
)( |
| 262 |
delay(function () { |
| 263 |
a.deep(invoked.removed, [], "Created: removed"); |
| 264 |
a.deep(invoked.added, [testName], "Created: added"); |
| 265 |
invoked = false; |
| 266 |
reader(function (data) { |
| 267 |
var npaths = aFrom(paths); |
| 268 |
npaths.push(testName); |
| 269 |
a.deep(data.sort(), npaths.sort(), "Created: data"); |
| 270 |
}).done(); |
| 271 |
return t(pgPath, { depth: 2, type: { file: true, directory: true } }); |
| 272 |
}, DELAY) |
| 273 |
)(function (data) { |
| 274 |
var npaths = aFrom(paths); |
| 275 |
npaths.push(testName); |
| 276 |
a.deep(data.sort(), npaths.sort(), "Not watched"); |
| 277 |
return rmdir(testPath); |
| 278 |
})( |
| 279 |
delay(function () { |
| 280 |
a.deep(invoked.removed, [testName], "Deleted: removed"); |
| 281 |
a.deep(invoked.added, [], "Deleted: added"); |
| 282 |
invoked = false; |
| 283 |
reader(function (data) { a.deep(data.sort(), paths, "Deleted: data"); }).done(); |
| 284 |
reader.close(); |
| 285 |
}, DELAY) |
| 286 |
).done(d, d); |
| 287 |
}, |
| 288 |
"Pattern": function (a, d) { |
| 289 |
var pattern = /one$/ |
| 290 |
, reader = t(pgPath, { depth: 2, pattern: pattern, watch: true }) |
| 291 |
, otherName = replaceSep("dtwo/test") |
| 292 |
, otherPath = resolve(pgPath, otherName) |
| 293 |
, testName = replaceSep("dtwo/fooone") |
| 294 |
, testPath = resolve(pgPath, testName) |
| 295 |
, paths = paths2.filter(function (path) { return pattern.test(path); }) |
| 296 |
, invoked = false; |
| 297 |
|
| 298 |
reader.on("change", function (data) { invoked = data; }); |
| 299 |
reader(function (data) { |
| 300 |
a.deep(data.sort(), paths); |
| 301 |
return mkdir(otherPath); |
| 302 |
})( |
| 303 |
delay(function () { |
| 304 |
a(invoked, false, "Created other type: event"); |
| 305 |
invoked = false; |
| 306 |
reader(function (data) { |
| 307 |
a.deep(data.sort(), paths, "Created other type: data"); |
| 308 |
}).done(); |
| 309 |
return rmdir(otherPath); |
| 310 |
}, DELAY) |
| 311 |
)( |
| 312 |
delay(function () { |
| 313 |
a(invoked, false, "Deleted other type: event"); |
| 314 |
invoked = false; |
| 315 |
reader(function (data) { |
| 316 |
a.deep(data.sort(), paths, "Deleted other type: data"); |
| 317 |
}).done(); |
| 318 |
return mkdir(testPath); |
| 319 |
}, DELAY) |
| 320 |
)( |
| 321 |
delay(function () { |
| 322 |
a.deep(invoked.removed, [], "Created: removed"); |
| 323 |
a.deep(invoked.added, [testName], "Created: added"); |
| 324 |
invoked = false; |
| 325 |
reader(function (data) { |
| 326 |
var npaths = aFrom(paths); |
| 327 |
npaths.push(testName); |
| 328 |
a.deep(data.sort(), npaths.sort(), "Created: data"); |
| 329 |
}).done(); |
| 330 |
return t(pgPath, { depth: 2, pattern: pattern }); |
| 331 |
}, DELAY) |
| 332 |
)(function (data) { |
| 333 |
var npaths = aFrom(paths); |
| 334 |
npaths.push(testName); |
| 335 |
a.deep(data.sort(), npaths.sort(), "Not watched"); |
| 336 |
return rmdir(testPath); |
| 337 |
})( |
| 338 |
delay(function () { |
| 339 |
a.deep(invoked.removed, [testName], "Deleted: removed"); |
| 340 |
a.deep(invoked.added, [], "Deleted: added"); |
| 341 |
invoked = false; |
| 342 |
reader(function (data) { a.deep(data.sort(), paths, "Deleted: data"); }).done(); |
| 343 |
reader.close(); |
| 344 |
}, DELAY) |
| 345 |
).done(d, d); |
| 346 |
}, |
| 347 |
"Global rules": function (a, d) { |
| 348 |
var rules = ["one"] |
| 349 |
, re = /(?:^|\/|\\)one(?:\/|\\|$)/ |
| 350 |
, reader = t(pgPath, { depth: 2, globalRules: rules, watch: true }) |
| 351 |
, otherName = replaceSep("dthree/dtwo/one") |
| 352 |
, otherPath = resolve(pgPath, otherName) |
| 353 |
, testName = replaceSep("dtwo/fooone") |
| 354 |
, testPath = resolve(pgPath, testName) |
| 355 |
, paths = paths2.filter(function (path) { return !re.test(path); }) |
| 356 |
, invoked = false; |
| 357 |
|
| 358 |
reader.on("change", function (data) { invoked = data; }); |
| 359 |
reader(function (data) { |
| 360 |
a.deep(data.sort(), paths); |
| 361 |
return mkdir(otherPath); |
| 362 |
})( |
| 363 |
delay(function () { |
| 364 |
a(invoked, false, "Created other type: event"); |
| 365 |
invoked = false; |
| 366 |
reader(function (data) { |
| 367 |
a.deep(data.sort(), paths, "Created other type: data"); |
| 368 |
}).done(); |
| 369 |
return rmdir(otherPath); |
| 370 |
}, DELAY) |
| 371 |
)( |
| 372 |
delay(function () { |
| 373 |
a(invoked, false, "Deleted other type: event"); |
| 374 |
invoked = false; |
| 375 |
reader(function (data) { |
| 376 |
a.deep(data.sort(), paths, "Deleted other type: data"); |
| 377 |
}).done(); |
| 378 |
return mkdir(testPath); |
| 379 |
}, DELAY) |
| 380 |
)( |
| 381 |
delay(function () { |
| 382 |
a.deep(invoked.removed, [], "Created: removed"); |
| 383 |
a.deep(invoked.added, [testName], "Created: added"); |
| 384 |
invoked = false; |
| 385 |
reader(function (data) { |
| 386 |
var npaths = aFrom(paths); |
| 387 |
npaths.push(testName); |
| 388 |
a.deep(data.sort(), npaths.sort(), "Created: data"); |
| 389 |
}).done(); |
| 390 |
return t(pgPath, { depth: 2, globalRules: rules }); |
| 391 |
}, DELAY) |
| 392 |
)(function (data) { |
| 393 |
var npaths = aFrom(paths); |
| 394 |
npaths.push(testName); |
| 395 |
a.deep(data.sort(), npaths.sort(), "Not watched"); |
| 396 |
return rmdir(testPath); |
| 397 |
})( |
| 398 |
delay(function () { |
| 399 |
a.deep(invoked.removed, [testName], "Deleted: removed"); |
| 400 |
a.deep(invoked.added, [], "Deleted: added"); |
| 401 |
invoked = false; |
| 402 |
reader(function (data) { a.deep(data.sort(), paths, "Deleted: data"); }).done(); |
| 403 |
reader.close(); |
| 404 |
}, DELAY) |
| 405 |
).done(d, d); |
| 406 |
}, |
| 407 |
"Pattern & Type": function (a, d) { |
| 408 |
var pattern = /one$/ |
| 409 |
, reader = t(pgPath, { |
| 410 |
depth: 2, |
| 411 |
type: { file: true }, |
| 412 |
pattern: pattern, |
| 413 |
watch: true |
| 414 |
}) |
| 415 |
, testName = replaceSep("dtwo/fooone") |
| 416 |
, testPath = resolve(pgPath, testName) |
| 417 |
, paths = files2.filter(function (path) { return pattern.test(path); }) |
| 418 |
, invoked = false; |
| 419 |
|
| 420 |
reader.on("change", function (data) { invoked = data; }); |
| 421 |
reader( |
| 422 |
delay(function (data) { |
| 423 |
a.deep(data.sort(), paths); |
| 424 |
return mkdir(testPath); |
| 425 |
}, DELAY) |
| 426 |
)( |
| 427 |
delay(function () { |
| 428 |
a(invoked, false, "Created other type: event"); |
| 429 |
invoked = false; |
| 430 |
reader(function (data) { |
| 431 |
a.deep(data.sort(), paths, "Created other type: data"); |
| 432 |
}).done(); |
| 433 |
return rmdir(testPath); |
| 434 |
}, DELAY) |
| 435 |
)( |
| 436 |
delay(function () { |
| 437 |
a(invoked, false, "Deleted other type: event"); |
| 438 |
invoked = false; |
| 439 |
reader(function (data) { |
| 440 |
a.deep(data.sort(), paths, "Deleted other type: data"); |
| 441 |
}).done(); |
| 442 |
return writeFile(testPath, "foo"); |
| 443 |
}, DELAY) |
| 444 |
)( |
| 445 |
delay(function () { |
| 446 |
a.deep(invoked.removed, [], "Created: removed"); |
| 447 |
a.deep(invoked.added, [testName], "Created: added"); |
| 448 |
invoked = false; |
| 449 |
reader(function (data) { |
| 450 |
var npaths = aFrom(paths); |
| 451 |
npaths.push(testName); |
| 452 |
a.deep(data.sort(), npaths.sort(), "Created: data"); |
| 453 |
}).done(); |
| 454 |
return t(pgPath, { depth: 2, type: { file: true }, pattern: pattern }); |
| 455 |
}, DELAY) |
| 456 |
)(function (data) { |
| 457 |
var npaths = aFrom(paths); |
| 458 |
npaths.push(testName); |
| 459 |
a.deep(data.sort(), npaths.sort(), "Not watched"); |
| 460 |
return unlink(testPath); |
| 461 |
})( |
| 462 |
delay(function () { |
| 463 |
a.deep(invoked.removed, [testName], "Deleted: removed"); |
| 464 |
a.deep(invoked.added, [], "Deleted: added"); |
| 465 |
invoked = false; |
| 466 |
reader(function (data) { a.deep(data.sort(), paths, "Deleted: data"); }).done(); |
| 467 |
reader.close(); |
| 468 |
}, DELAY) |
| 469 |
).done(d, d); |
| 470 |
}, |
| 471 |
"Ignored": function (a, d) { |
| 472 |
var gitPath = resolve(pgPath, ".git") |
| 473 |
, ignoreFile = resolve(pgPath, ".gitignore") |
| 474 |
, otherName = replaceSep("dtwo/test") |
| 475 |
, otherPath = resolve(pgPath, otherName) |
| 476 |
, testName = replaceSep("dthree/fooone") |
| 477 |
, testPath = resolve(pgPath, testName) |
| 478 |
, paths = paths2.filter(function (path) { return path.indexOf("dtwo") === -1; }) |
| 479 |
, reader |
| 480 |
, invoked = [] |
| 481 |
, mergeInvoked |
| 482 |
, npaths; |
| 483 |
|
| 484 |
mergeInvoked = function () { |
| 485 |
var result; |
| 486 |
if (!invoked.length) { |
| 487 |
return false; |
| 488 |
} |
| 489 |
result = { data: invoked[0].data, removed: [], added: [] }; |
| 490 |
invoked.forEach(function (data) { |
| 491 |
push.apply(result.added, data.added); |
| 492 |
push.apply(result.removed, data.removed); |
| 493 |
}); |
| 494 |
invoked = []; |
| 495 |
return result; |
| 496 |
}; |
| 497 |
|
| 498 |
paths.push(".gitignore"); |
| 499 |
paths.sort(); |
| 500 |
|
| 501 |
npaths = paths.filter(function (path) { |
| 502 |
return ( |
| 503 |
path !== "one" && |
| 504 |
path.indexOf(sep + "one") === -1 && |
| 505 |
!startsWith.call(path, "dthree" + sep + "dthree") |
| 506 |
); |
| 507 |
}); |
| 508 |
|
| 509 |
deferred(mkdir(gitPath), writeFile(ignoreFile, "dtwo"))( |
| 510 |
delay(function () { |
| 511 |
reader = t(pgPath, { depth: 2, ignoreRules: "git", watch: true }); |
| 512 |
reader.on("change", function (data) { invoked.push(data); }); |
| 513 |
return reader; |
| 514 |
}, DELAY) |
| 515 |
)(function (data) { |
| 516 |
a.deep(data.sort(), paths); |
| 517 |
return mkdir(otherPath); |
| 518 |
})( |
| 519 |
delay(function () { |
| 520 |
var lInvoked = mergeInvoked(); |
| 521 |
a(lInvoked, false, "Created other type: event"); |
| 522 |
reader(function (data) { |
| 523 |
a.deep(data.sort(), paths, "Created other type: data"); |
| 524 |
}).done(); |
| 525 |
return rmdir(otherPath); |
| 526 |
}, DELAY) |
| 527 |
)( |
| 528 |
delay(function () { |
| 529 |
var lInvoked = mergeInvoked(); |
| 530 |
a(lInvoked, false, "Deleted other type: event"); |
| 531 |
reader(function (data) { |
| 532 |
a.deep(data.sort(), paths, "Deleted other type: data"); |
| 533 |
}).done(); |
| 534 |
return mkdir(testPath); |
| 535 |
}, DELAY) |
| 536 |
)( |
| 537 |
delay(function () { |
| 538 |
var lInvoked = mergeInvoked(); |
| 539 |
a.deep(lInvoked.removed, [], "Created: removed"); |
| 540 |
a.deep(lInvoked.added, [testName], "Created: added"); |
| 541 |
reader(function (data) { |
| 542 |
var npaths2 = aFrom(paths); |
| 543 |
npaths2.push(testName); |
| 544 |
a.deep(data.sort(), npaths2.sort(), "Created: data"); |
| 545 |
}).done(); |
| 546 |
return t(pgPath, { depth: 2, ignoreRules: "git" }); |
| 547 |
}, DELAY) |
| 548 |
)(function (data) { |
| 549 |
var npaths2 = aFrom(paths); |
| 550 |
npaths2.push(testName); |
| 551 |
a.deep(data.sort(), npaths2.sort(), "Not watched"); |
| 552 |
return rmdir(testPath); |
| 553 |
})( |
| 554 |
delay(function () { |
| 555 |
var lInvoked = mergeInvoked(); |
| 556 |
a.deep(lInvoked.removed, [testName], "Deleted: removed"); |
| 557 |
a.deep(lInvoked.added, [], "Deleted: added"); |
| 558 |
reader(function (data) { a.deep(data.sort(), paths, "Deleted: data"); }).done(); |
| 559 |
return writeFile(ignoreFile, "dtwo\none\n/dthree/dthree"); |
| 560 |
}, DELAY) |
| 561 |
)( |
| 562 |
delay(function () { |
| 563 |
var lInvoked = mergeInvoked(); |
| 564 |
a.deep( |
| 565 |
lInvoked && lInvoked.removed && lInvoked.removed.sort(), |
| 566 |
diff.call(paths, npaths).sort(), "Ignored: removed" |
| 567 |
); |
| 568 |
a.deep(lInvoked.added, [], "Ignored: added"); |
| 569 |
reader(function (data) { |
| 570 |
a.deep(data.sort(), npaths, "Ignored: data"); |
| 571 |
}).done(); |
| 572 |
return writeFile(ignoreFile, "dtwo"); |
| 573 |
}, DELAY) |
| 574 |
)( |
| 575 |
delay(function () { |
| 576 |
var lInvoked = mergeInvoked(); |
| 577 |
a.deep(lInvoked.removed, [], "Ignored revert: removed"); |
| 578 |
a.deep( |
| 579 |
lInvoked && lInvoked.added && lInvoked.added.sort(), |
| 580 |
diff.call(paths, npaths).sort(), "Ignored revert: added" |
| 581 |
); |
| 582 |
reader(function (data) { |
| 583 |
a.deep(data.sort(), paths, "Ignored revert: data"); |
| 584 |
}).done(); |
| 585 |
reader.close(); |
| 586 |
return deferred(rmdir(gitPath), unlink(ignoreFile))(false); |
| 587 |
}, DELAY) |
| 588 |
).done(d, d); |
| 589 |
}, |
| 590 |
"Ignored & Type": function (a, d) { |
| 591 |
var gitPath = resolve(pgPath, ".git") |
| 592 |
, ignoreFile = resolve(pgPath, ".gitignore") |
| 593 |
, otherName = replaceSep("dtwo/test") |
| 594 |
, otherPath = resolve(pgPath, otherName) |
| 595 |
, testName = replaceSep("dthree/fooone") |
| 596 |
, testPath = resolve(pgPath, testName) |
| 597 |
, paths = files2.filter(function (path) { return path.indexOf("dtwo") === -1; }) |
| 598 |
, reader |
| 599 |
, invoked = [] |
| 600 |
, mergeInvoked; |
| 601 |
|
| 602 |
mergeInvoked = function () { |
| 603 |
var result; |
| 604 |
if (!invoked.length) { |
| 605 |
return false; |
| 606 |
} |
| 607 |
result = { data: invoked[0].data, removed: [], added: [] }; |
| 608 |
invoked.forEach(function (data) { |
| 609 |
push.apply(result.added, data.added); |
| 610 |
push.apply(result.removed, data.removed); |
| 611 |
}); |
| 612 |
invoked = []; |
| 613 |
return result; |
| 614 |
}; |
| 615 |
|
| 616 |
paths.push(".gitignore"); |
| 617 |
paths.sort(); |
| 618 |
deferred(mkdir(gitPath), writeFile(ignoreFile, "dtwo"))( |
| 619 |
delay(function () { |
| 620 |
reader = t(pgPath, { |
| 621 |
depth: 2, |
| 622 |
type: { file: true }, |
| 623 |
ignoreRules: "git", |
| 624 |
watch: true |
| 625 |
}); |
| 626 |
reader.on("change", function (data) { invoked.push(data); }); |
| 627 |
return reader; |
| 628 |
}, DELAY) |
| 629 |
)( |
| 630 |
delay(function (data) { |
| 631 |
a.deep(data.sort(), paths); |
| 632 |
return writeFile(otherPath, "foo"); |
| 633 |
}, DELAY) |
| 634 |
)( |
| 635 |
delay(function () { |
| 636 |
var lInvoked = mergeInvoked(); |
| 637 |
a(lInvoked, false, "Created other type: event"); |
| 638 |
reader(function (data) { |
| 639 |
a.deep(data.sort(), paths, "Created other type: data"); |
| 640 |
}).done(); |
| 641 |
return unlink(otherPath); |
| 642 |
}, DELAY) |
| 643 |
)( |
| 644 |
delay(function () { |
| 645 |
var lInvoked = mergeInvoked(); |
| 646 |
a(lInvoked, false, "Deleted other type: event"); |
| 647 |
reader(function (data) { |
| 648 |
a.deep(data.sort(), paths, "Deleted other type: data"); |
| 649 |
}).done(); |
| 650 |
return writeFile(testPath, "foo"); |
| 651 |
}, DELAY) |
| 652 |
)( |
| 653 |
delay(function () { |
| 654 |
var lInvoked = mergeInvoked(); |
| 655 |
a.deep(lInvoked.removed, [], "Created: removed"); |
| 656 |
a.deep(lInvoked.added, [testName], "Created: added"); |
| 657 |
reader(function (data) { |
| 658 |
var npaths = aFrom(paths); |
| 659 |
npaths.push(testName); |
| 660 |
a.deep(data.sort(), npaths.sort(), "Created: data"); |
| 661 |
}).done(); |
| 662 |
return t(pgPath, { depth: 2, type: { file: true }, ignoreRules: "git" }); |
| 663 |
}, DELAY) |
| 664 |
)(function (data) { |
| 665 |
var npaths = aFrom(paths); |
| 666 |
npaths.push(testName); |
| 667 |
a.deep(data.sort(), npaths.sort(), "Not watched"); |
| 668 |
return unlink(testPath); |
| 669 |
})( |
| 670 |
delay(function () { |
| 671 |
var lInvoked = mergeInvoked(); |
| 672 |
a.deep(lInvoked.removed, [testName], "Deleted: removed"); |
| 673 |
a.deep(lInvoked.added, [], "Deleted: added"); |
| 674 |
reader(function (data) { a.deep(data.sort(), paths, "Deleted: data"); }).done(); |
| 675 |
}, DELAY) |
| 676 |
)(delay(function () { return writeFile(ignoreFile, "dtwo\none"); }, DELAY))( |
| 677 |
delay(function () { |
| 678 |
var lInvoked |
| 679 |
, npaths = paths |
| 680 |
.filter(function (path) { |
| 681 |
return path !== "one" && path.indexOf(sep + "one") === -1; |
| 682 |
}) |
| 683 |
.sort(); |
| 684 |
lInvoked = mergeInvoked(); |
| 685 |
a.deep( |
| 686 |
lInvoked.removed && lInvoked.removed.sort(), |
| 687 |
diff.call(paths, npaths).sort(), "Ignored: removed" |
| 688 |
); |
| 689 |
a.deep(lInvoked.added, [], "Ignored: added"); |
| 690 |
reader(function (data) { |
| 691 |
a.deep(data.sort(), npaths, "Ignored: data"); |
| 692 |
}).done(); |
| 693 |
reader.close(); |
| 694 |
return deferred(rmdir(gitPath), unlink(ignoreFile))(false); |
| 695 |
}, DELAY) |
| 696 |
).done(d, d); |
| 697 |
}, |
| 698 |
"Ignored & Pattern": function (a, d) { |
| 699 |
var pattern = /done/ |
| 700 |
, gitPath = resolve(pgPath, ".git") |
| 701 |
, ignoreFile = resolve(pgPath, ".gitignore") |
| 702 |
, otherName = replaceSep("dtwo/test") |
| 703 |
, otherPath = resolve(pgPath, otherName) |
| 704 |
, testName = replaceSep("done/fooone") |
| 705 |
, testPath = resolve(pgPath, testName) |
| 706 |
, paths = paths2.filter(function (path) { |
| 707 |
return path.indexOf("dtwo") === -1 && pattern.test(path); |
| 708 |
}) |
| 709 |
, reader |
| 710 |
, invoked = [] |
| 711 |
, mergeInvoked; |
| 712 |
|
| 713 |
mergeInvoked = function () { |
| 714 |
var result; |
| 715 |
if (!invoked.length) { |
| 716 |
return false; |
| 717 |
} |
| 718 |
result = { data: invoked[0].data, removed: [], added: [] }; |
| 719 |
invoked.forEach(function (data) { |
| 720 |
push.apply(result.added, data.added); |
| 721 |
push.apply(result.removed, data.removed); |
| 722 |
}); |
| 723 |
invoked = []; |
| 724 |
return result; |
| 725 |
}; |
| 726 |
|
| 727 |
deferred(mkdir(gitPath), writeFile(ignoreFile, "dtwo"))( |
| 728 |
delay(function () { |
| 729 |
reader = t(pgPath, { |
| 730 |
depth: 2, |
| 731 |
pattern: pattern, |
| 732 |
ignoreRules: "git", |
| 733 |
watch: true |
| 734 |
}); |
| 735 |
reader.on("change", function (data) { invoked.push(data); }); |
| 736 |
return reader; |
| 737 |
}, DELAY) |
| 738 |
)( |
| 739 |
delay(function (data) { |
| 740 |
a.deep(data.sort(), paths); |
| 741 |
return mkdir(otherPath); |
| 742 |
}, DELAY) |
| 743 |
)( |
| 744 |
delay(function () { |
| 745 |
var lInvoked = mergeInvoked(); |
| 746 |
a(lInvoked, false, "Created other type: event"); |
| 747 |
reader(function (data) { |
| 748 |
a.deep(data.sort(), paths, "Created other type: data"); |
| 749 |
}).done(); |
| 750 |
return rmdir(otherPath); |
| 751 |
}, DELAY) |
| 752 |
)( |
| 753 |
delay(function () { |
| 754 |
var lInvoked = mergeInvoked(); |
| 755 |
a(lInvoked, false, "Deleted other type: event"); |
| 756 |
reader(function (data) { |
| 757 |
a.deep(data.sort(), paths, "Deleted other type: data"); |
| 758 |
}).done(); |
| 759 |
return mkdir(testPath); |
| 760 |
}, DELAY) |
| 761 |
)( |
| 762 |
delay(function () { |
| 763 |
var lInvoked = mergeInvoked(); |
| 764 |
a.deep(lInvoked.removed, [], "Created: removed"); |
| 765 |
a.deep(lInvoked.added, [testName], "Created: added"); |
| 766 |
reader(function (data) { |
| 767 |
var npaths = aFrom(paths); |
| 768 |
npaths.push(testName); |
| 769 |
a.deep(data.sort(), npaths.sort(), "Created: data"); |
| 770 |
}).done(); |
| 771 |
return t(pgPath, { depth: 2, pattern: pattern, ignoreRules: "git" }); |
| 772 |
}, DELAY) |
| 773 |
)(function (data) { |
| 774 |
var npaths = aFrom(paths); |
| 775 |
npaths.push(testName); |
| 776 |
a.deep(data.sort(), npaths.sort(), "Not watched"); |
| 777 |
return rmdir(testPath); |
| 778 |
})( |
| 779 |
delay(function () { |
| 780 |
var lInvoked = mergeInvoked(); |
| 781 |
a.deep(lInvoked.removed, [testName], "Deleted: removed"); |
| 782 |
a.deep(lInvoked.added, [], "Deleted: added"); |
| 783 |
reader(function (data) { a.deep(data.sort(), paths, "Deleted: data"); }).done(); |
| 784 |
}, DELAY) |
| 785 |
)(delay(function () { return writeFile(ignoreFile, "dtwo\none"); }, DELAY))( |
| 786 |
delay(function () { |
| 787 |
var lInvoked |
| 788 |
, npaths = paths |
| 789 |
.filter(function (path) { |
| 790 |
return path !== "one" && path.indexOf(sep + "one") === -1; |
| 791 |
}) |
| 792 |
.sort(); |
| 793 |
lInvoked = mergeInvoked(); |
| 794 |
a.deep( |
| 795 |
lInvoked && lInvoked.removed && lInvoked.removed.sort(), |
| 796 |
diff.call(paths, npaths).sort(), "Ignored: removed" |
| 797 |
); |
| 798 |
a.deep(lInvoked.added, [], "Ignored: added"); |
| 799 |
reader(function (data) { |
| 800 |
a.deep(data.sort(), npaths, "Ignored: data"); |
| 801 |
}).done(); |
| 802 |
reader.close(); |
| 803 |
return deferred(rmdir(gitPath), unlink(ignoreFile))(false); |
| 804 |
}, DELAY) |
| 805 |
).done(d, d); |
| 806 |
}, |
| 807 |
"Ignored & Pattern & Type": function (a, d) { |
| 808 |
var pattern = /done/ |
| 809 |
, gitPath = resolve(pgPath, ".git") |
| 810 |
, ignoreFile = resolve(pgPath, ".gitignore") |
| 811 |
, otherName = replaceSep("dtwo/test") |
| 812 |
, otherPath = resolve(pgPath, otherName) |
| 813 |
, testName = replaceSep("done/fooone") |
| 814 |
, testPath = resolve(pgPath, testName) |
| 815 |
, paths = files2.filter(function (path) { |
| 816 |
return path.indexOf("dtwo") === -1 && pattern.test(path); |
| 817 |
}) |
| 818 |
, reader |
| 819 |
, invoked = [] |
| 820 |
, mergeInvoked; |
| 821 |
|
| 822 |
mergeInvoked = function () { |
| 823 |
var result; |
| 824 |
if (!invoked.length) { |
| 825 |
return false; |
| 826 |
} |
| 827 |
result = { data: invoked[0].data, removed: [], added: [] }; |
| 828 |
invoked.forEach(function (data) { |
| 829 |
push.apply(result.added, data.added); |
| 830 |
push.apply(result.removed, data.removed); |
| 831 |
}); |
| 832 |
invoked = []; |
| 833 |
return result; |
| 834 |
}; |
| 835 |
|
| 836 |
deferred(mkdir(gitPath), writeFile(ignoreFile, "dtwo"))( |
| 837 |
delay(function () { |
| 838 |
reader = t(pgPath, { |
| 839 |
depth: 2, |
| 840 |
type: { file: true }, |
| 841 |
pattern: pattern, |
| 842 |
ignoreRules: "git", |
| 843 |
watch: true |
| 844 |
}); |
| 845 |
reader.on("change", function (data) { invoked.push(data); }); |
| 846 |
return reader; |
| 847 |
}, DELAY) |
| 848 |
)( |
| 849 |
delay(function (data) { |
| 850 |
a.deep(data.sort(), paths); |
| 851 |
return writeFile(otherPath, "foo"); |
| 852 |
}, DELAY) |
| 853 |
)( |
| 854 |
delay(function () { |
| 855 |
var lInvoked = mergeInvoked(); |
| 856 |
a(lInvoked, false, "Created other type: event"); |
| 857 |
reader(function (data) { |
| 858 |
a.deep(data.sort(), paths, "Created other type: data"); |
| 859 |
}).done(); |
| 860 |
return unlink(otherPath); |
| 861 |
}, DELAY) |
| 862 |
)( |
| 863 |
delay(function () { |
| 864 |
var lInvoked = mergeInvoked(); |
| 865 |
a(lInvoked, false, "Deleted other type: event"); |
| 866 |
reader(function (data) { |
| 867 |
a.deep(data.sort(), paths, "Deleted other type: data"); |
| 868 |
}).done(); |
| 869 |
return writeFile(testPath, "foo"); |
| 870 |
}, DELAY) |
| 871 |
)( |
| 872 |
delay(function () { |
| 873 |
var lInvoked = mergeInvoked(); |
| 874 |
a.deep(lInvoked.removed, [], "Created: removed"); |
| 875 |
a.deep(lInvoked.added, [testName], "Created: added"); |
| 876 |
reader(function (data) { |
| 877 |
var npaths = aFrom(paths); |
| 878 |
npaths.push(testName); |
| 879 |
a.deep(data.sort(), npaths.sort(), "Created: data"); |
| 880 |
}).done(); |
| 881 |
return t(pgPath, { |
| 882 |
depth: 2, |
| 883 |
type: { file: true }, |
| 884 |
pattern: pattern, |
| 885 |
ignoreRules: "git" |
| 886 |
}); |
| 887 |
}, DELAY) |
| 888 |
)(function (data) { |
| 889 |
var npaths = aFrom(paths); |
| 890 |
npaths.push(testName); |
| 891 |
a.deep(data.sort(), npaths.sort(), "Not watched"); |
| 892 |
return unlink(testPath); |
| 893 |
})( |
| 894 |
delay(function () { |
| 895 |
var lInvoked = mergeInvoked(); |
| 896 |
a.deep(lInvoked.removed, [testName], "Deleted: removed"); |
| 897 |
a.deep(lInvoked.added, [], "Deleted: added"); |
| 898 |
reader(function (data) { a.deep(data.sort(), paths, "Deleted: data"); }).done(); |
| 899 |
}, DELAY) |
| 900 |
)(delay(function () { return writeFile(ignoreFile, "dtwo\none"); }, DELAY))( |
| 901 |
delay(function () { |
| 902 |
var lInvoked |
| 903 |
, npaths = paths |
| 904 |
.filter(function (path) { |
| 905 |
return path !== "one" && path.indexOf(sep + "one") === -1; |
| 906 |
}) |
| 907 |
.sort(); |
| 908 |
lInvoked = mergeInvoked(); |
| 909 |
a.deep( |
| 910 |
lInvoked && lInvoked.removed && lInvoked.removed.sort(), |
| 911 |
diff.call(paths, npaths).sort(), "Ignored: removed" |
| 912 |
); |
| 913 |
a.deep(lInvoked.added, [], "Ignored: added"); |
| 914 |
reader(function (data) { |
| 915 |
a.deep(data.sort(), npaths, "Ignored: data"); |
| 916 |
}).done(); |
| 917 |
reader.close(); |
| 918 |
return deferred(rmdir(gitPath), unlink(ignoreFile))(false); |
| 919 |
}, DELAY) |
| 920 |
).done(d, d); |
| 921 |
}, |
| 922 |
"cb": function (a, d) { |
| 923 |
t(pgPath, function (err, result) { |
| 924 |
if (err) { |
| 925 |
d(err); |
| 926 |
return; |
| 927 |
} |
| 928 |
a.deep(result.sort(), ["done", "dthree", "dtwo", "one", "three", "two"]); |
| 929 |
d(); |
| 930 |
}); |
| 931 |
} |
| 932 |
}; |
| 933 |
}; |