react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / fileset / node_modules / glob / test / bash-comparison.js
80724 views// basic test1// show that it does the same thing by default as the shell.2var tap = require("tap")3, child_process = require("child_process")4, bashResults = require("./bash-results.json")5, globs = Object.keys(bashResults)6, glob = require("../")7, path = require("path")89// run from the root of the project10// this is usually where you're at anyway, but be sure.11process.chdir(path.resolve(__dirname, ".."))1213function alphasort (a, b) {14a = a.toLowerCase()15b = b.toLowerCase()16return a > b ? 1 : a < b ? -1 : 017}1819globs.forEach(function (pattern) {20var expect = bashResults[pattern]21// anything regarding the symlink thing will fail on windows, so just skip it22if (process.platform === "win32" &&23expect.some(function (m) {24return /\/symlink\//.test(m)25}))26return2728tap.test(pattern, function (t) {29glob(pattern, function (er, matches) {30if (er)31throw er3233// sort and unmark, just to match the shell results34matches = cleanResults(matches)3536t.deepEqual(matches, expect, pattern)37t.end()38})39})4041tap.test(pattern + " sync", function (t) {42var matches = cleanResults(glob.sync(pattern))4344t.deepEqual(matches, expect, "should match shell")45t.end()46})47})4849function cleanResults (m) {50// normalize discrepancies in ordering, duplication,51// and ending slashes.52return m.map(function (m) {53return m.replace(/\/+/g, "/").replace(/\/$/, "")54}).sort(alphasort).reduce(function (set, f) {55if (f !== set[set.length - 1]) set.push(f)56return set57}, []).sort(alphasort).map(function (f) {58// de-windows59return (process.platform !== 'win32') ? f60: f.replace(/^[a-zA-Z]:[\/\\]+/, '/').replace(/[\\\/]+/g, '/')61})62}636465