Skip to content

Commit 3e68a7b

Browse files
committed
some windows test affordances
1 parent 8c2e082 commit 3e68a7b

File tree

3 files changed

+57
-53
lines changed

3 files changed

+57
-53
lines changed

test/cwd-test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import { resolve } from 'path'
22
import t from 'tap'
33
import { glob } from '../'
4+
import { sep } from 'path'
5+
const j = (a: string[]) => a.map(s => s.split('/').join(sep))
46

57
const origCwd = process.cwd()
68
process.chdir(__dirname + '/fixtures')
79
t.teardown(() => process.chdir(origCwd))
810

911
t.test('changing cwd and searching for **/d', t => {
1012
const expect = Object.entries({
11-
a: new Set(['c/d', 'b/c/d']),
12-
'a/b': new Set(['c/d']),
13-
'': new Set(['a/b/c/d', 'a/c/d']),
13+
a: new Set(j(['c/d', 'b/c/d'])),
14+
'a/b': new Set(j(['c/d'])),
15+
'': new Set(j(['a/b/c/d', 'a/c/d'])),
1416
})
1517
t.plan(expect.length)
1618
for (const [cwd, matches] of expect) {

test/ignore.ts

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import t from 'tap'
55
import glob from '../'
66
import type { GlobOptions } from '../src/index.js'
77

8+
import { sep } from 'path'
9+
const alphasort = (a:string, b:string) => a.localeCompare(b, 'en')
10+
const j = (a: string[]) => a.map(s => s.split('/').join(sep)).sort(alphasort)
11+
812
// [pattern, ignore, expect, opt (object) or cwd (string)]
913
type Case = [
1014
pattern: string,
@@ -16,24 +20,24 @@ const cases: Case[] = [
1620
[
1721
'*',
1822
null,
19-
['abcdef', 'abcfed', 'b', 'bc', 'c', 'cb', 'symlink', 'x', 'z'],
23+
j(['abcdef', 'abcfed', 'b', 'bc', 'c', 'cb', 'symlink', 'x', 'z']),
2024
'a',
2125
],
2226
[
2327
'*',
2428
'b',
25-
['abcdef', 'abcfed', 'bc', 'c', 'cb', 'symlink', 'x', 'z'],
29+
j(['abcdef', 'abcfed', 'bc', 'c', 'cb', 'symlink', 'x', 'z']),
2630
'a',
2731
],
28-
['*', 'b*', ['abcdef', 'abcfed', 'c', 'cb', 'symlink', 'x', 'z'], 'a'],
29-
['b/**', 'b/c/d', ['b', 'b/c'], 'a'],
30-
['b/**', 'd', ['b', 'b/c', 'b/c/d'], 'a'],
32+
['*', 'b*', j(['abcdef', 'abcfed', 'c', 'cb', 'symlink', 'x', 'z']), 'a'],
33+
['b/**', 'b/c/d', j(['b', 'b/c']), 'a'],
34+
['b/**', 'd', j(['b', 'b/c', 'b/c/d']), 'a'],
3135
['b/**', 'b/c/**', ['b'], 'a'],
32-
['**/d', 'b/c/d', ['c/d'], 'a'],
36+
['**/d', 'b/c/d', j(['c/d']), 'a'],
3337
[
3438
'a/**/[gh]',
3539
['a/abcfed/g/h'],
36-
['a/abcdef/g', 'a/abcdef/g/h', 'a/abcfed/g'],
40+
j(['a/abcdef/g', 'a/abcdef/g/h', 'a/abcfed/g']),
3741
],
3842
[
3943
'*',
@@ -44,7 +48,7 @@ const cases: Case[] = [
4448
[
4549
'**',
4650
['c/**', 'bc/**', 'symlink/**', 'abcdef/**'],
47-
[
51+
j([
4852
'',
4953
'abcfed',
5054
'abcfed/g',
@@ -57,16 +61,16 @@ const cases: Case[] = [
5761
'cb/e/f',
5862
'x',
5963
'z',
60-
],
64+
]),
6165
'a',
6266
],
6367
['a/**', ['a/**'], []],
6468
['a/**', ['a/**/**'], []],
65-
['a/b/**', ['a/b'], ['a/b/c', 'a/b/c/d']],
69+
['a/b/**', ['a/b'], j(['a/b/c', 'a/b/c/d'])],
6670
[
6771
'**',
6872
['b'],
69-
[
73+
j([
7074
'',
7175
'abcdef',
7276
'abcdef/g',
@@ -92,13 +96,13 @@ const cases: Case[] = [
9296
'symlink/a/b/c',
9397
'x',
9498
'z',
95-
],
99+
]),
96100
'a',
97101
],
98102
[
99103
'**',
100104
['b', 'c'],
101-
[
105+
j([
102106
'',
103107
'abcdef',
104108
'abcdef/g',
@@ -123,13 +127,13 @@ const cases: Case[] = [
123127
'symlink/a/b/c',
124128
'x',
125129
'z',
126-
],
130+
]),
127131
'a',
128132
],
129133
[
130134
'**',
131135
['b**'],
132-
[
136+
j([
133137
'',
134138
'abcdef',
135139
'abcdef/g',
@@ -154,13 +158,13 @@ const cases: Case[] = [
154158
'symlink/a/b/c',
155159
'x',
156160
'z',
157-
],
161+
]),
158162
'a',
159163
],
160164
[
161165
'**',
162166
['b/**'],
163-
[
167+
j([
164168
'',
165169
'abcdef',
166170
'abcdef/g',
@@ -184,13 +188,13 @@ const cases: Case[] = [
184188
'symlink/a/b/c',
185189
'x',
186190
'z',
187-
],
191+
]),
188192
'a',
189193
],
190194
[
191195
'**',
192196
['b**/**'],
193-
[
197+
j([
194198
'',
195199
'abcdef',
196200
'abcdef/g',
@@ -211,13 +215,13 @@ const cases: Case[] = [
211215
'symlink/a/b/c',
212216
'x',
213217
'z',
214-
],
218+
]),
215219
'a',
216220
],
217221
[
218222
'**',
219223
['ab**ef/**'],
220-
[
224+
j([
221225
'',
222226
'abcfed',
223227
'abcfed/g',
@@ -241,13 +245,13 @@ const cases: Case[] = [
241245
'symlink/a/b/c',
242246
'x',
243247
'z',
244-
],
248+
]),
245249
'a',
246250
],
247251
[
248252
'**',
249253
['abc{def,fed}/**'],
250-
[
254+
j([
251255
'',
252256
'b',
253257
'b/c',
@@ -268,13 +272,13 @@ const cases: Case[] = [
268272
'symlink/a/b/c',
269273
'x',
270274
'z',
271-
],
275+
]),
272276
'a',
273277
],
274278
[
275279
'**',
276280
['abc{def,fed}/*'],
277-
[
281+
j([
278282
'',
279283
'abcdef',
280284
'abcdef/g/h',
@@ -299,23 +303,23 @@ const cases: Case[] = [
299303
'symlink/a/b/c',
300304
'x',
301305
'z',
302-
],
306+
]),
303307
'a',
304308
],
305-
['c/**', ['c/*'], ['c', 'c/d/c', 'c/d/c/b'], 'a'],
306-
['a/c/**', ['a/c/*'], ['a/c', 'a/c/d/c', 'a/c/d/c/b']],
309+
['c/**', ['c/*'], j(['c', 'c/d/c', 'c/d/c/b']), 'a'],
310+
['a/c/**', ['a/c/*'], j(['a/c', 'a/c/d/c', 'a/c/d/c/b'])],
307311
['a/c/**', ['a/c/**', 'a/c/*', 'a/c/*/c'], []],
308-
['a/**/.y', ['a/x/**'], ['a/z/.y']],
309-
['a/**/.y', ['a/x/**'], ['a/z/.y'], { dot: true }],
310-
['a/**/b', ['a/x/**'], ['a/b', 'a/c/d/c/b', 'a/symlink/a/b']],
312+
['a/**/.y', ['a/x/**'], j(['a/z/.y'])],
313+
['a/**/.y', ['a/x/**'], j(['a/z/.y']), { dot: true }],
314+
['a/**/b', ['a/x/**'], j(['a/b', 'a/c/d/c/b', 'a/symlink/a/b'])],
311315
[
312316
'a/**/b',
313317
['a/x/**'],
314-
['a/b', 'a/c/d/c/b', 'a/symlink/a/b', 'a/z/.y/b'],
318+
j(['a/b', 'a/c/d/c/b', 'a/symlink/a/b', 'a/z/.y/b']),
315319
{ dot: true },
316320
],
317321
['*/.abcdef', 'a/**', []],
318-
['a/*/.y/b', 'a/x/**', ['a/z/.y/b']],
322+
['a/*/.y/b', 'a/x/**', j(['a/z/.y/b'])],
319323
]
320324

321325
process.chdir(__dirname + '/fixtures')

test/mark.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import glob from '../'
33
process.chdir(__dirname + '/fixtures')
44

55
const alphasort = (a:string, b:string) => a.localeCompare(b, 'en')
6+
import { sep } from 'path'
7+
const j = (a: string[]) => a.map(s=>s.split('/').join(sep)).sort(alphasort)
68

79
t.test('mark with cwd', async t => {
810
const pattern = '*/*'
@@ -14,15 +16,15 @@ t.test('mark with cwd', async t => {
1416
'bc/e/',
1517
'c/d/',
1618
'cb/e/',
17-
].sort(alphasort)
19+
]
1820

1921
const res = await glob(pattern, opt)
2022
if (process.platform !== 'win32') {
2123
expect.push('symlink/a/')
2224
}
2325

24-
t.same(res.sort(alphasort), expect)
25-
t.same(glob.sync(pattern, opt).sort(alphasort), expect)
26+
t.same(res.sort(alphasort), j(expect))
27+
t.same(glob.sync(pattern, opt).sort(alphasort), j(expect))
2628
})
2729

2830
t.test('mark, with **', async t => {
@@ -46,8 +48,8 @@ t.test('mark, with **', async t => {
4648
'a/cb/e/f',
4749
].sort(alphasort)
4850

49-
t.same((await glob(pattern, opt)).sort(alphasort), expect, 'async')
50-
t.same(glob.sync(pattern, opt).sort(alphasort), expect, 'sync')
51+
t.same((await glob(pattern, opt)).sort(alphasort), j(expect), 'async')
52+
t.same(glob.sync(pattern, opt).sort(alphasort), j(expect), 'sync')
5153
})
5254

5355
t.test('mark, no / on pattern', async t => {
@@ -66,10 +68,9 @@ t.test('mark, no / on pattern', async t => {
6668
if (process.platform !== 'win32') {
6769
expect.push('a/symlink/')
6870
}
69-
expect.sort(alphasort)
7071
const results = (await glob(pattern, opt)).sort(alphasort)
71-
t.same(results, expect)
72-
t.same(glob.sync(pattern, opt).sort(alphasort), expect)
72+
t.same(results, j(expect))
73+
t.same(glob.sync(pattern, opt).sort(alphasort), j(expect))
7374
})
7475

7576
t.test('mark=false, no / on pattern', async t => {
@@ -87,11 +88,10 @@ t.test('mark=false, no / on pattern', async t => {
8788
if (process.platform !== 'win32') {
8889
expect.push('a/symlink')
8990
}
90-
expect.sort(alphasort)
9191
const results = (await glob(pattern)).sort(alphasort)
9292

93-
t.same(results, expect)
94-
t.same(glob.sync(pattern).sort(alphasort), expect)
93+
t.same(results, j(expect))
94+
t.same(glob.sync(pattern).sort(alphasort), j(expect))
9595
})
9696

9797
t.test('mark=true, / on pattern', async t => {
@@ -111,10 +111,9 @@ t.test('mark=true, / on pattern', async t => {
111111
if (process.platform !== 'win32') {
112112
expect.push('a/symlink/')
113113
}
114-
expect.sort(alphasort)
115114
const results = (await glob(pattern, opt)).sort(alphasort)
116-
t.same(results, expect)
117-
t.same(glob.sync(pattern, opt).sort(alphasort), expect)
115+
t.same(results, j(expect))
116+
t.same(glob.sync(pattern, opt).sort(alphasort), j(expect))
118117
})
119118

120119
t.test('mark=false, / on pattern', async t => {
@@ -132,11 +131,10 @@ t.test('mark=false, / on pattern', async t => {
132131
if (process.platform !== 'win32') {
133132
expect.push('a/symlink')
134133
}
135-
expect.sort(alphasort)
136134

137135
const results = (await glob(pattern)).sort(alphasort)
138-
t.same(results, expect)
139-
t.same(glob.sync(pattern).sort(alphasort), expect)
136+
t.same(results, j(expect))
137+
t.same(glob.sync(pattern).sort(alphasort), j(expect))
140138
})
141139

142140
const cwd = process

0 commit comments

Comments
 (0)