react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / fileset / node_modules / glob / test / pause-resume.js
80713 views// show that no match events happen while paused.1var tap = require("tap")2, child_process = require("child_process")3// just some gnarly pattern with lots of matches4, pattern = "test/a/!(symlink)/**"5, bashResults = require("./bash-results.json")6, patterns = Object.keys(bashResults)7, glob = require("../")8, Glob = glob.Glob9, path = require("path")1011// run from the root of the project12// this is usually where you're at anyway, but be sure.13process.chdir(path.resolve(__dirname, ".."))1415function alphasort (a, b) {16a = a.toLowerCase()17b = b.toLowerCase()18return a > b ? 1 : a < b ? -1 : 019}2021function cleanResults (m) {22// normalize discrepancies in ordering, duplication,23// and ending slashes.24return m.map(function (m) {25return m.replace(/\/+/g, "/").replace(/\/$/, "")26}).sort(alphasort).reduce(function (set, f) {27if (f !== set[set.length - 1]) set.push(f)28return set29}, []).sort(alphasort).map(function (f) {30// de-windows31return (process.platform !== 'win32') ? f32: f.replace(/^[a-zA-Z]:\\\\/, '/').replace(/\\/g, '/')33})34}3536var globResults = []37tap.test("use a Glob object, and pause/resume it", function (t) {38var g = new Glob(pattern)39, paused = false40, res = []41, expect = bashResults[pattern]4243g.on("pause", function () {44console.error("pause")45})4647g.on("resume", function () {48console.error("resume")49})5051g.on("match", function (m) {52t.notOk(g.paused, "must not be paused")53globResults.push(m)54g.pause()55t.ok(g.paused, "must be paused")56setTimeout(g.resume.bind(g), 10)57})5859g.on("end", function (matches) {60t.pass("reached glob end")61globResults = cleanResults(globResults)62matches = cleanResults(matches)63t.deepEqual(matches, globResults,64"end event matches should be the same as match events")6566t.deepEqual(matches, expect,67"glob matches should be the same as bash results")6869t.end()70})71})72737475