1 // show that no match events happen while paused.
2 var tap = require("tap")
3 , child_process = require("child_process")
4 // just some gnarly pattern with lots of matches
5 , pattern = "test/a/!(symlink)/**"
6 , bashResults = require("./bash-results.json")
7 , patterns = Object.keys(bashResults)
8 , glob = require("../")
10 , path = require("path")
12 // run from the root of the project
13 // this is usually where you're at anyway, but be sure.
14 process.chdir(path.resolve(__dirname, ".."))
16 function alphasort (a, b) {
19 return a > b ? 1 : a < b ? -1 : 0
22 function cleanResults (m) {
23 // normalize discrepancies in ordering, duplication,
24 // and ending slashes.
25 return m.map(function (m) {
26 return m.replace(/\/+/g, "/").replace(/\/$/, "")
27 }).sort(alphasort).reduce(function (set, f) {
28 if (f !== set[set.length - 1]) set.push(f)
30 }, []).sort(alphasort).map(function (f) {
32 return (process.platform !== 'win32') ? f
33 : f.replace(/^[a-zA-Z]:\\\\/, '/').replace(/\\/g, '/')
38 tap.test("use a Glob object, and pause/resume it", function (t) {
39 var g = new Glob(pattern)
42 , expect = bashResults[pattern]
44 g.on("pause", function () {
45 console.error("pause")
48 g.on("resume", function () {
49 console.error("resume")
52 g.on("match", function (m) {
53 t.notOk(g.paused, "must not be paused")
56 t.ok(g.paused, "must be paused")
57 setTimeout(g.resume.bind(g), 10)
60 g.on("end", function (matches) {
61 t.pass("reached glob end")
62 globResults = cleanResults(globResults)
63 matches = cleanResults(matches)
64 t.deepEqual(matches, globResults,
65 "end event matches should be the same as match events")
67 t.deepEqual(matches, expect,
68 "glob matches should be the same as bash results")