Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80724 views
1
// basic test
2
// show that it does the same thing by default as the shell.
3
var tap = require("tap")
4
, child_process = require("child_process")
5
, bashResults = require("./bash-results.json")
6
, globs = Object.keys(bashResults)
7
, glob = require("../")
8
, path = require("path")
9
10
// run from the root of the project
11
// this is usually where you're at anyway, but be sure.
12
process.chdir(path.resolve(__dirname, ".."))
13
14
function alphasort (a, b) {
15
a = a.toLowerCase()
16
b = b.toLowerCase()
17
return a > b ? 1 : a < b ? -1 : 0
18
}
19
20
globs.forEach(function (pattern) {
21
var expect = bashResults[pattern]
22
// anything regarding the symlink thing will fail on windows, so just skip it
23
if (process.platform === "win32" &&
24
expect.some(function (m) {
25
return /\/symlink\//.test(m)
26
}))
27
return
28
29
tap.test(pattern, function (t) {
30
glob(pattern, function (er, matches) {
31
if (er)
32
throw er
33
34
// sort and unmark, just to match the shell results
35
matches = cleanResults(matches)
36
37
t.deepEqual(matches, expect, pattern)
38
t.end()
39
})
40
})
41
42
tap.test(pattern + " sync", function (t) {
43
var matches = cleanResults(glob.sync(pattern))
44
45
t.deepEqual(matches, expect, "should match shell")
46
t.end()
47
})
48
})
49
50
function cleanResults (m) {
51
// normalize discrepancies in ordering, duplication,
52
// and ending slashes.
53
return m.map(function (m) {
54
return m.replace(/\/+/g, "/").replace(/\/$/, "")
55
}).sort(alphasort).reduce(function (set, f) {
56
if (f !== set[set.length - 1]) set.push(f)
57
return set
58
}, []).sort(alphasort).map(function (f) {
59
// de-windows
60
return (process.platform !== 'win32') ? f
61
: f.replace(/^[a-zA-Z]:[\/\\]+/, '/').replace(/[\\\/]+/g, '/')
62
})
63
}
64
65