-
-
Notifications
You must be signed in to change notification settings - Fork 127
/
index.test-d.ts
135 lines (121 loc) · 3.87 KB
/
index.test-d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import {Buffer} from 'node:buffer';
import {URL} from 'node:url';
import {expectType} from 'tsd';
import {
GlobTask,
GlobEntry,
GlobbyFilterFunction,
globby,
globbySync,
globbyStream,
generateGlobTasks,
isDynamicPattern,
isGitIgnored,
isGitIgnoredSync,
} from './index.js';
const __dirname = '';
// Globby
expectType<Promise<string[]>>(globby('*.tmp'));
expectType<Promise<string[]>>(globby(['a.tmp', '*.tmp', '!{c,d,e}.tmp']));
expectType<Promise<string[]>>(globby('*.tmp', {expandDirectories: false}));
expectType<Promise<string[]>>(
globby('*.tmp', {expandDirectories: ['a*', 'b*']}),
);
expectType<Promise<string[]>>(
globby('*.tmp', {
expandDirectories: {
files: ['a', 'b'],
extensions: ['tmp'],
},
}),
);
expectType<Promise<string[]>>(globby('*.tmp', {gitignore: true}));
expectType<Promise<string[]>>(globby('*.tmp', {ignore: ['**/b.tmp']}));
expectType<Promise<GlobEntry[]>>(globby('*.tmp', {objectMode: true}));
// Globby (sync)
expectType<string[]>(globbySync('*.tmp'));
expectType<string[]>(globbySync(['a.tmp', '*.tmp', '!{c,d,e}.tmp']));
expectType<string[]>(globbySync('*.tmp', {expandDirectories: false}));
expectType<string[]>(globbySync('*.tmp', {expandDirectories: ['a*', 'b*']}));
expectType<string[]>(
globbySync('*.tmp', {
expandDirectories: {
files: ['a', 'b'],
extensions: ['tmp'],
},
}),
);
expectType<string[]>(globbySync('*.tmp', {gitignore: true}));
expectType<string[]>(globbySync('*.tmp', {ignore: ['**/b.tmp']}));
expectType<GlobEntry[]>(globbySync('*.tmp', {objectMode: true}));
// Globby (stream)
expectType<NodeJS.ReadableStream>(globbyStream('*.tmp'));
expectType<NodeJS.ReadableStream>(globbyStream(['a.tmp', '*.tmp', '!{c,d,e}.tmp']));
expectType<NodeJS.ReadableStream>(globbyStream('*.tmp', {expandDirectories: false}));
expectType<NodeJS.ReadableStream>(globbyStream('*.tmp', {expandDirectories: ['a*', 'b*']}));
expectType<NodeJS.ReadableStream>(
globbyStream('*.tmp', {
expandDirectories: {
files: ['a', 'b'],
extensions: ['tmp'],
},
}),
);
expectType<NodeJS.ReadableStream>(globbyStream('*.tmp', {gitignore: true}));
expectType<NodeJS.ReadableStream>(globbyStream('*.tmp', {ignore: ['**/b.tmp']}));
(async () => {
const streamResult = [];
for await (const path of globbyStream('*.tmp')) {
streamResult.push(path);
}
// `NodeJS.ReadableStream` is not generic, unfortunately,
// so it seems `(string | Buffer)[]` is the best we can get here
expectType<Array<string | Buffer>>(streamResult);
})();
// GenerateGlobTasks
expectType<GlobTask[]>(generateGlobTasks('*.tmp'));
expectType<GlobTask[]>(generateGlobTasks(['a.tmp', '*.tmp', '!{c,d,e}.tmp']));
expectType<GlobTask[]>(generateGlobTasks('*.tmp', {expandDirectories: false}));
expectType<GlobTask[]>(
generateGlobTasks('*.tmp', {expandDirectories: ['a*', 'b*']}),
);
expectType<GlobTask[]>(
generateGlobTasks('*.tmp', {
expandDirectories: {
files: ['a', 'b'],
extensions: ['tmp'],
},
}),
);
expectType<GlobTask[]>(generateGlobTasks('*.tmp', {gitignore: true}));
expectType<GlobTask[]>(generateGlobTasks('*.tmp', {ignore: ['**/b.tmp']}));
// IsDynamicPattern
expectType<boolean>(isDynamicPattern('**'));
expectType<boolean>(isDynamicPattern(['**', 'path1', 'path2']));
expectType<boolean>(isDynamicPattern(['**', 'path1', 'path2'], {extglob: false}));
expectType<boolean>(isDynamicPattern(['**'], {cwd: new URL('https://example.com')}));
expectType<boolean>(isDynamicPattern(['**'], {cwd: __dirname}));
// IsGitIgnored
expectType<Promise<GlobbyFilterFunction>>(isGitIgnored());
expectType<Promise<GlobbyFilterFunction>>(
isGitIgnored({
cwd: __dirname,
}),
);
expectType<Promise<GlobbyFilterFunction>>(
isGitIgnored({
ignore: ['**/b.tmp'],
}),
);
// IsGitIgnoredSync
expectType<GlobbyFilterFunction>(isGitIgnoredSync());
expectType<GlobbyFilterFunction>(
isGitIgnoredSync({
cwd: __dirname,
}),
);
expectType<GlobbyFilterFunction>(
isGitIgnoredSync({
ignore: ['**/b.tmp'],
}),
);