@tkeron/tools 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/npm_deploy.yml +12 -8
- package/bun.lock +8 -8
- package/changelog.md +25 -0
- package/package.json +13 -4
- package/readme.md +3 -6
- package/src/getPaths.ts +90 -103
- package/src/stack.ts +46 -63
- package/tests/getPaths.test.ts +528 -0
- package/{src → tests}/random.test.ts +1 -1
- package/{src → tests}/stack.test.ts +2 -2
- package/src/getPaths.test.ts +0 -513
package/src/getPaths.test.ts
DELETED
|
@@ -1,513 +0,0 @@
|
|
|
1
|
-
import { describe, test, expect, beforeAll, afterAll, it } from "bun:test";
|
|
2
|
-
import { mkdirSync, writeFileSync, rmSync } from "fs";
|
|
3
|
-
import { join } from "path";
|
|
4
|
-
import { getPaths, getFilePaths, getDirectoryPaths } from "./getPaths";
|
|
5
|
-
|
|
6
|
-
const testDir = join(process.cwd(), "test-temp");
|
|
7
|
-
|
|
8
|
-
describe("getPaths Tests", () => {
|
|
9
|
-
|
|
10
|
-
beforeAll(() => {
|
|
11
|
-
mkdirSync(testDir, { recursive: true });
|
|
12
|
-
|
|
13
|
-
writeFileSync(join(testDir, "file1.txt"), "content");
|
|
14
|
-
writeFileSync(join(testDir, "file2.js"), "content");
|
|
15
|
-
writeFileSync(join(testDir, "README.md"), "content");
|
|
16
|
-
|
|
17
|
-
mkdirSync(join(testDir, "src"), { recursive: true });
|
|
18
|
-
writeFileSync(join(testDir, "src", "index.ts"), "content");
|
|
19
|
-
writeFileSync(join(testDir, "src", "utils.ts"), "content");
|
|
20
|
-
|
|
21
|
-
mkdirSync(join(testDir, "docs"), { recursive: true });
|
|
22
|
-
writeFileSync(join(testDir, "docs", "guide.md"), "content");
|
|
23
|
-
|
|
24
|
-
mkdirSync(join(testDir, "empty-dir"), { recursive: true });
|
|
25
|
-
|
|
26
|
-
mkdirSync(join(testDir, "src", "components"), { recursive: true });
|
|
27
|
-
writeFileSync(join(testDir, "src", "components", "Button.tsx"), "content");
|
|
28
|
-
|
|
29
|
-
writeFileSync(join(testDir, ".env"), "content");
|
|
30
|
-
mkdirSync(join(testDir, ".git"), { recursive: true });
|
|
31
|
-
writeFileSync(join(testDir, ".git", "config"), "content");
|
|
32
|
-
|
|
33
|
-
writeFileSync(join(testDir, "file with spaces.txt"), "content");
|
|
34
|
-
writeFileSync(join(testDir, "file-no-extension"), "content");
|
|
35
|
-
writeFileSync(join(testDir, "UPPERCASE.TXT"), "content");
|
|
36
|
-
writeFileSync(join(testDir, "números-ñ-ü.js"), "content");
|
|
37
|
-
|
|
38
|
-
writeFileSync(join(testDir, "config.json"), "content");
|
|
39
|
-
writeFileSync(join(testDir, "styles.css"), "content");
|
|
40
|
-
writeFileSync(join(testDir, "script.jsx"), "content");
|
|
41
|
-
|
|
42
|
-
mkdirSync(join(testDir, "deep", "very", "nested", "structure"), { recursive: true });
|
|
43
|
-
writeFileSync(join(testDir, "deep", "very", "nested", "structure", "deep-file.txt"), "content");
|
|
44
|
-
|
|
45
|
-
mkdirSync(join(testDir, "node_modules"), { recursive: true });
|
|
46
|
-
writeFileSync(join(testDir, "node_modules", "package.json"), "content");
|
|
47
|
-
mkdirSync(join(testDir, "build"), { recursive: true });
|
|
48
|
-
writeFileSync(join(testDir, "build", "output.js"), "content");
|
|
49
|
-
|
|
50
|
-
for (let i = 123; i <= 129; i++) {
|
|
51
|
-
mkdirSync(join(testDir, `build`, `qwerty_${i}.com`), { recursive: true });
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
afterAll(() => {
|
|
56
|
-
rmSync(testDir, { recursive: true, force: true });
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
describe("getPaths", () => {
|
|
60
|
-
test("should return both files and directories when includeDirectories is 'yes'", () => {
|
|
61
|
-
const result = getPaths(testDir, "**/*", "yes");
|
|
62
|
-
|
|
63
|
-
expect(result.length).toBeGreaterThan(0);
|
|
64
|
-
expect(result.some(path => path.includes("file1.txt"))).toBe(true);
|
|
65
|
-
expect(result.some(path => path.includes("src"))).toBe(true);
|
|
66
|
-
expect(result.some(path => path.includes("docs"))).toBe(true);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
test("should return only files when includeDirectories is 'no'", () => {
|
|
70
|
-
const result = getPaths(testDir, "**/*", "no");
|
|
71
|
-
|
|
72
|
-
expect(result.length).toBeGreaterThan(0);
|
|
73
|
-
expect(result.some(path => path.includes("file1.txt"))).toBe(true);
|
|
74
|
-
expect(result.some(path => path.includes("index.ts"))).toBe(true);
|
|
75
|
-
expect(result.some(path => path.endsWith("src"))).toBe(false);
|
|
76
|
-
expect(result.some(path => path.endsWith("docs"))).toBe(false);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
test("should return only directories when includeDirectories is 'onlyDirectories'", () => {
|
|
80
|
-
const result = getPaths(testDir, "**/*", "onlyDirectories");
|
|
81
|
-
|
|
82
|
-
expect(result.length).toBeGreaterThan(0);
|
|
83
|
-
expect(result.some(path => path.endsWith("src"))).toBe(true);
|
|
84
|
-
expect(result.some(path => path.endsWith("docs"))).toBe(true);
|
|
85
|
-
expect(result.some(path => path.endsWith("empty-dir"))).toBe(true);
|
|
86
|
-
expect(result.some(path => path.includes("file1.txt"))).toBe(false);
|
|
87
|
-
expect(result.some(path => path.includes("index.ts"))).toBe(false);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
test("should use default includeDirectories value ('no')", () => {
|
|
91
|
-
const result = getPaths(testDir, "**/*");
|
|
92
|
-
const filesOnlyResult = getPaths(testDir, "**/*", "no");
|
|
93
|
-
|
|
94
|
-
expect(result).toEqual(filesOnlyResult);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
test("should work with specific patterns", () => {
|
|
98
|
-
const result = getPaths(testDir, "*.txt", "no");
|
|
99
|
-
|
|
100
|
-
expect(result.some(path => path.includes("file1.txt"))).toBe(true);
|
|
101
|
-
expect(result.some(path => path.includes("file2.js"))).toBe(false);
|
|
102
|
-
expect(result.some(path => path.includes("README.md"))).toBe(false);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
test("should include hidden files and directories", () => {
|
|
106
|
-
const allResult = getPaths(testDir, "**/*", "yes");
|
|
107
|
-
|
|
108
|
-
expect(allResult.some(path => path.includes(".env"))).toBe(true);
|
|
109
|
-
expect(allResult.some(path => path.includes(".git"))).toBe(true);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
test("should return empty array for non-existent path", () => {
|
|
113
|
-
const result = getPaths("/non/existent/path", "**/*", "yes");
|
|
114
|
-
|
|
115
|
-
expect(result).toEqual([]);
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
describe("getFilePaths", () => {
|
|
120
|
-
test("should return only files", () => {
|
|
121
|
-
const result = getFilePaths(testDir, "**/*");
|
|
122
|
-
|
|
123
|
-
expect(result.length).toBeGreaterThan(0);
|
|
124
|
-
expect(result.some(path => path.includes("file1.txt"))).toBe(true);
|
|
125
|
-
expect(result.some(path => path.includes("index.ts"))).toBe(true);
|
|
126
|
-
expect(result.some(path => path.includes("Button.tsx"))).toBe(true);
|
|
127
|
-
expect(result.some(path => path.endsWith("src"))).toBe(false);
|
|
128
|
-
expect(result.some(path => path.endsWith("docs"))).toBe(false);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
test("should work with specific file patterns", () => {
|
|
132
|
-
const jsFiles = getFilePaths(testDir, "**/*.js");
|
|
133
|
-
const tsFiles = getFilePaths(testDir, "**/*.ts");
|
|
134
|
-
|
|
135
|
-
expect(jsFiles.some(path => path.includes("file2.js"))).toBe(true);
|
|
136
|
-
expect(jsFiles.some(path => path.includes("file1.txt"))).toBe(false);
|
|
137
|
-
|
|
138
|
-
expect(tsFiles.some(path => path.includes("index.ts"))).toBe(true);
|
|
139
|
-
expect(tsFiles.some(path => path.includes("utils.ts"))).toBe(true);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
test("should include hidden files", () => {
|
|
143
|
-
const result = getFilePaths(testDir, "**/*");
|
|
144
|
-
|
|
145
|
-
expect(result.some(path => path.includes(".env"))).toBe(true);
|
|
146
|
-
expect(result.some(path => path.includes(".git/config"))).toBe(true);
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
test("should return empty array for non-existent path", () => {
|
|
150
|
-
const result = getFilePaths("/non/existent/path", "**/*");
|
|
151
|
-
|
|
152
|
-
expect(result).toEqual([]);
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
describe("getDirectoryPaths", () => {
|
|
157
|
-
test("should return only directories", () => {
|
|
158
|
-
const result = getDirectoryPaths(testDir, "**/*");
|
|
159
|
-
|
|
160
|
-
expect(result.length).toBeGreaterThan(0);
|
|
161
|
-
expect(result.some(path => path.endsWith("src"))).toBe(true);
|
|
162
|
-
expect(result.some(path => path.endsWith("docs"))).toBe(true);
|
|
163
|
-
expect(result.some(path => path.endsWith("empty-dir"))).toBe(true);
|
|
164
|
-
expect(result.some(path => path.endsWith("components"))).toBe(true);
|
|
165
|
-
expect(result.some(path => path.includes("file1.txt"))).toBe(false);
|
|
166
|
-
expect(result.some(path => path.includes("index.ts"))).toBe(false);
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
test("should include hidden directories", () => {
|
|
170
|
-
const result = getDirectoryPaths(testDir, "**/*");
|
|
171
|
-
|
|
172
|
-
expect(result.some(path => path.includes(".git"))).toBe(true);
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
test("should work with directory patterns", () => {
|
|
176
|
-
const result = getDirectoryPaths(testDir, "src/**");
|
|
177
|
-
|
|
178
|
-
expect(result.some(path => path.endsWith("components"))).toBe(true);
|
|
179
|
-
expect(result.some(path => path.endsWith("docs"))).toBe(false);
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
test("should return empty array for non-existent path", () => {
|
|
183
|
-
const result = getDirectoryPaths("/non/existent/path", "**/*");
|
|
184
|
-
|
|
185
|
-
expect(result).toEqual([]);
|
|
186
|
-
});
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
describe("Edge cases", () => {
|
|
190
|
-
test("should handle empty directory", () => {
|
|
191
|
-
const emptyDirPath = join(testDir, "empty-dir");
|
|
192
|
-
const files = getFilePaths(emptyDirPath, "**/*");
|
|
193
|
-
const dirs = getDirectoryPaths(emptyDirPath, "**/*");
|
|
194
|
-
|
|
195
|
-
expect(files).toEqual([]);
|
|
196
|
-
expect(dirs).toEqual([]);
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
test("should handle invalid glob patterns gracefully", () => {
|
|
200
|
-
const result = getPaths(testDir, "[invalid", "yes");
|
|
201
|
-
|
|
202
|
-
expect(Array.isArray(result)).toBe(true);
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
test("all functions should return absolute paths by default", () => {
|
|
206
|
-
const files = getFilePaths(testDir, "**/*");
|
|
207
|
-
const dirs = getDirectoryPaths(testDir, "**/*");
|
|
208
|
-
const all = getPaths(testDir, "**/*", "yes");
|
|
209
|
-
|
|
210
|
-
files.forEach(path => {
|
|
211
|
-
expect(path).toMatch(/^[\/\\]|^[a-zA-Z]:[\/\\]/);
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
dirs.forEach(path => {
|
|
215
|
-
expect(path).toMatch(/^[\/\\]|^[a-zA-Z]:[\/\\]/);
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
all.forEach(path => {
|
|
219
|
-
expect(path).toMatch(/^[\/\\]|^[a-zA-Z]:[\/\\]/);
|
|
220
|
-
});
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
test("all functions should return relative paths when absolute is false", () => {
|
|
224
|
-
const files = getFilePaths(testDir, "**/*", false);
|
|
225
|
-
const dirs = getDirectoryPaths(testDir, "**/*", false);
|
|
226
|
-
const all = getPaths(testDir, "**/*", "yes", false);
|
|
227
|
-
|
|
228
|
-
files.forEach(path => {
|
|
229
|
-
expect(path).not.toMatch(/^[\/\\]|^[a-zA-Z]:[\/\\]/);
|
|
230
|
-
expect(path.length).toBeGreaterThan(0);
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
dirs.forEach(path => {
|
|
234
|
-
expect(path).not.toMatch(/^[\/\\]|^[a-zA-Z]:[\/\\]/);
|
|
235
|
-
expect(path.length).toBeGreaterThan(0);
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
all.forEach(path => {
|
|
239
|
-
expect(path).not.toMatch(/^[\/\\]|^[a-zA-Z]:[\/\\]/);
|
|
240
|
-
expect(path.length).toBeGreaterThan(0);
|
|
241
|
-
});
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
test("relative paths should contain expected file and directory names", () => {
|
|
245
|
-
const files = getFilePaths(testDir, "**/*", false);
|
|
246
|
-
const dirs = getDirectoryPaths(testDir, "**/*", false);
|
|
247
|
-
|
|
248
|
-
expect(files.some(path => path === "file1.txt")).toBe(true);
|
|
249
|
-
expect(files.some(path => path === ".env")).toBe(true);
|
|
250
|
-
expect(files.some(path => path === "src/index.ts")).toBe(true);
|
|
251
|
-
expect(files.some(path => path === "src/components/Button.tsx")).toBe(true);
|
|
252
|
-
|
|
253
|
-
const nestedFiles = files.filter(path => path.includes("/"));
|
|
254
|
-
expect(nestedFiles.length).toBeGreaterThan(0);
|
|
255
|
-
|
|
256
|
-
expect(dirs.some(path => path === "src")).toBe(true);
|
|
257
|
-
expect(dirs.some(path => path === ".git")).toBe(true);
|
|
258
|
-
|
|
259
|
-
expect(dirs.length).toBeGreaterThan(0);
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
test("absolute parameter should work consistently across all function variants", () => {
|
|
263
|
-
const pattern = "src/**";
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
const absoluteFiles = getFilePaths(testDir, pattern, true);
|
|
267
|
-
const absoluteDirs = getDirectoryPaths(testDir, pattern, true);
|
|
268
|
-
const absoluteAll = getPaths(testDir, pattern, "yes", true);
|
|
269
|
-
|
|
270
|
-
const relativeFiles = getFilePaths(testDir, pattern, false);
|
|
271
|
-
const relativeDirs = getDirectoryPaths(testDir, pattern, false);
|
|
272
|
-
const relativeAll = getPaths(testDir, pattern, "yes", false);
|
|
273
|
-
|
|
274
|
-
expect(absoluteFiles.length).toBe(relativeFiles.length);
|
|
275
|
-
expect(absoluteAll.length).toBe(relativeAll.length);
|
|
276
|
-
|
|
277
|
-
expect(Array.isArray(absoluteDirs)).toBe(true);
|
|
278
|
-
expect(Array.isArray(relativeDirs)).toBe(true);
|
|
279
|
-
|
|
280
|
-
absoluteFiles.forEach(path => {
|
|
281
|
-
expect(path).toMatch(/^[\/\\]|^[a-zA-Z]:[\/\\]/);
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
relativeFiles.forEach(path => {
|
|
285
|
-
expect(path).not.toMatch(/^[\/\\]|^[a-zA-Z]:[\/\\]/);
|
|
286
|
-
});
|
|
287
|
-
});
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
describe("Advanced Glob Patterns", () => {
|
|
291
|
-
test("should work with multiple extension patterns", () => {
|
|
292
|
-
const result = getFilePaths(testDir, "*.{js,ts,json}");
|
|
293
|
-
|
|
294
|
-
expect(result.some(path => path.includes("file2.js"))).toBe(true);
|
|
295
|
-
expect(result.some(path => path.includes("config.json"))).toBe(true);
|
|
296
|
-
expect(result.some(path => path.includes("números-ñ-ü.js"))).toBe(true);
|
|
297
|
-
expect(result.some(path => path.includes("file1.txt"))).toBe(false);
|
|
298
|
-
expect(result.some(path => path.includes("styles.css"))).toBe(false);
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
test("should work with exclusion patterns", () => {
|
|
302
|
-
const allFiles = getFilePaths(testDir, "**/*");
|
|
303
|
-
expect(allFiles.some(path => path.includes("node_modules"))).toBe(true);
|
|
304
|
-
expect(allFiles.some(path => path.includes("build"))).toBe(true);
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
test("should work with specific directory depth patterns", () => {
|
|
308
|
-
const topLevel = getFilePaths(testDir, "*");
|
|
309
|
-
expect(topLevel.some(path => path.includes("file1.txt"))).toBe(true);
|
|
310
|
-
expect(topLevel.some(path => path.includes("index.ts"))).toBe(false);
|
|
311
|
-
|
|
312
|
-
const srcFiles = getFilePaths(testDir, "src/*");
|
|
313
|
-
expect(srcFiles.some(path => path.includes("index.ts"))).toBe(true);
|
|
314
|
-
expect(srcFiles.some(path => path.includes("Button.tsx"))).toBe(false);
|
|
315
|
-
});
|
|
316
|
-
|
|
317
|
-
test("should work with character class patterns", () => {
|
|
318
|
-
const result = getFilePaths(testDir, "*[Ee]*");
|
|
319
|
-
|
|
320
|
-
expect(result.some(path => path.includes("README.md"))).toBe(true);
|
|
321
|
-
expect(result.some(path => path.includes(".env"))).toBe(true);
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
test("should work with case sensitive patterns", () => {
|
|
325
|
-
const upperFiles = getFilePaths(testDir, "*.TXT");
|
|
326
|
-
const lowerFiles = getFilePaths(testDir, "*.txt");
|
|
327
|
-
|
|
328
|
-
expect(upperFiles.some(path => path.includes("UPPERCASE.TXT"))).toBe(true);
|
|
329
|
-
expect(lowerFiles.some(path => path.includes("file1.txt"))).toBe(true);
|
|
330
|
-
|
|
331
|
-
expect(upperFiles).not.toEqual(lowerFiles);
|
|
332
|
-
});
|
|
333
|
-
|
|
334
|
-
test("should handle patterns that match nothing", () => {
|
|
335
|
-
const result = getFilePaths(testDir, "*.nonexistent");
|
|
336
|
-
expect(result).toEqual([]);
|
|
337
|
-
|
|
338
|
-
const dirs = getDirectoryPaths(testDir, "nonexistent-*");
|
|
339
|
-
expect(dirs).toEqual([]);
|
|
340
|
-
});
|
|
341
|
-
|
|
342
|
-
test("should work with deep nested patterns", () => {
|
|
343
|
-
const deepFiles = getFilePaths(testDir, "**/very/**/*.txt");
|
|
344
|
-
expect(deepFiles.some(path => path.includes("deep-file.txt"))).toBe(true);
|
|
345
|
-
|
|
346
|
-
const deepDirs = getDirectoryPaths(testDir, "**/very/**");
|
|
347
|
-
expect(deepDirs.some(path => path.endsWith("nested"))).toBe(true);
|
|
348
|
-
expect(deepDirs.some(path => path.endsWith("structure"))).toBe(true);
|
|
349
|
-
});
|
|
350
|
-
});
|
|
351
|
-
|
|
352
|
-
describe("Function Consistency", () => {
|
|
353
|
-
test("getPaths('yes') should equal getFilePaths() + getDirectoryPaths()", () => {
|
|
354
|
-
const pattern = "**/*";
|
|
355
|
-
|
|
356
|
-
const allPaths = getPaths(testDir, pattern, "yes");
|
|
357
|
-
const files = getFilePaths(testDir, pattern);
|
|
358
|
-
const dirs = getDirectoryPaths(testDir, pattern);
|
|
359
|
-
|
|
360
|
-
const combined = [...files, ...dirs].sort();
|
|
361
|
-
const allSorted = allPaths.sort();
|
|
362
|
-
|
|
363
|
-
expect(allSorted).toEqual(combined);
|
|
364
|
-
});
|
|
365
|
-
|
|
366
|
-
test("should not have duplicates in any function", () => {
|
|
367
|
-
const files = getFilePaths(testDir, "**/*");
|
|
368
|
-
const dirs = getDirectoryPaths(testDir, "**/*");
|
|
369
|
-
const all = getPaths(testDir, "**/*", "yes");
|
|
370
|
-
|
|
371
|
-
expect(files.length).toBe(new Set(files).size);
|
|
372
|
-
expect(dirs.length).toBe(new Set(dirs).size);
|
|
373
|
-
expect(all.length).toBe(new Set(all).size);
|
|
374
|
-
});
|
|
375
|
-
|
|
376
|
-
test("files and directories should be mutually exclusive", () => {
|
|
377
|
-
const files = getFilePaths(testDir, "**/*");
|
|
378
|
-
const dirs = getDirectoryPaths(testDir, "**/*");
|
|
379
|
-
|
|
380
|
-
const intersection = files.filter(file => dirs.includes(file));
|
|
381
|
-
expect(intersection).toEqual([]);
|
|
382
|
-
});
|
|
383
|
-
|
|
384
|
-
test("different patterns should be consistent across functions", () => {
|
|
385
|
-
const patterns = ["*.js", "src/**", "**/*.md", "**/components/*"];
|
|
386
|
-
|
|
387
|
-
patterns.forEach(pattern => {
|
|
388
|
-
const allPaths = getPaths(testDir, pattern, "yes");
|
|
389
|
-
const files = getFilePaths(testDir, pattern);
|
|
390
|
-
const dirs = getDirectoryPaths(testDir, pattern);
|
|
391
|
-
|
|
392
|
-
files.forEach(file => {
|
|
393
|
-
expect(allPaths).toContain(file);
|
|
394
|
-
});
|
|
395
|
-
|
|
396
|
-
dirs.forEach(dir => {
|
|
397
|
-
expect(allPaths).toContain(dir);
|
|
398
|
-
});
|
|
399
|
-
});
|
|
400
|
-
});
|
|
401
|
-
|
|
402
|
-
test("should maintain consistent behavior with default parameters", () => {
|
|
403
|
-
const result1 = getPaths(testDir);
|
|
404
|
-
const result2 = getPaths(testDir, "**/*");
|
|
405
|
-
const result3 = getPaths(testDir, "**/*", "no");
|
|
406
|
-
const result4 = getFilePaths(testDir);
|
|
407
|
-
const result5 = getFilePaths(testDir, "**/*");
|
|
408
|
-
|
|
409
|
-
expect(result1).toEqual(result2);
|
|
410
|
-
expect(result2).toEqual(result3);
|
|
411
|
-
expect(result3).toEqual(result4);
|
|
412
|
-
expect(result4).toEqual(result5);
|
|
413
|
-
});
|
|
414
|
-
});
|
|
415
|
-
|
|
416
|
-
describe("Special File Names", () => {
|
|
417
|
-
test("should handle files with spaces", () => {
|
|
418
|
-
const files = getFilePaths(testDir, "**/*");
|
|
419
|
-
expect(files.some(path => path.includes("file with spaces.txt"))).toBe(true);
|
|
420
|
-
|
|
421
|
-
const specific = getFilePaths(testDir, "*with*");
|
|
422
|
-
expect(specific.some(path => path.includes("file with spaces.txt"))).toBe(true);
|
|
423
|
-
});
|
|
424
|
-
|
|
425
|
-
test("should handle files without extensions", () => {
|
|
426
|
-
const files = getFilePaths(testDir, "**/*");
|
|
427
|
-
expect(files.some(path => path.includes("file-no-extension"))).toBe(true);
|
|
428
|
-
|
|
429
|
-
const withExt = getFilePaths(testDir, "*.txt");
|
|
430
|
-
expect(withExt.some(path => path.includes("file-no-extension"))).toBe(false);
|
|
431
|
-
});
|
|
432
|
-
|
|
433
|
-
test("should handle files with unicode characters", () => {
|
|
434
|
-
const files = getFilePaths(testDir, "**/*");
|
|
435
|
-
expect(files.some(path => path.includes("números-ñ-ü.js"))).toBe(true);
|
|
436
|
-
|
|
437
|
-
const jsFiles = getFilePaths(testDir, "*.js");
|
|
438
|
-
expect(jsFiles.some(path => path.includes("números-ñ-ü.js"))).toBe(true);
|
|
439
|
-
});
|
|
440
|
-
|
|
441
|
-
test("should handle uppercase/lowercase variations", () => {
|
|
442
|
-
const files = getFilePaths(testDir, "**/*");
|
|
443
|
-
expect(files.some(path => path.includes("UPPERCASE.TXT"))).toBe(true);
|
|
444
|
-
expect(files.some(path => path.includes("file1.txt"))).toBe(true);
|
|
445
|
-
|
|
446
|
-
const upper = getFilePaths(testDir, "*UPPER*");
|
|
447
|
-
const lower = getFilePaths(testDir, "*upper*");
|
|
448
|
-
expect(upper.length).toBeGreaterThan(0);
|
|
449
|
-
expect(lower).toEqual([]);
|
|
450
|
-
});
|
|
451
|
-
|
|
452
|
-
test("should handle various file extensions", () => {
|
|
453
|
-
const extensions = ["js", "ts", "tsx", "json", "css", "jsx", "md", "txt"];
|
|
454
|
-
|
|
455
|
-
extensions.forEach(ext => {
|
|
456
|
-
const files = getFilePaths(testDir, `*.${ext}`);
|
|
457
|
-
expect(Array.isArray(files)).toBe(true);
|
|
458
|
-
});
|
|
459
|
-
|
|
460
|
-
expect(getFilePaths(testDir, "*.css").some(path => path.includes("styles.css"))).toBe(true);
|
|
461
|
-
expect(getFilePaths(testDir, "*.jsx").some(path => path.includes("script.jsx"))).toBe(true);
|
|
462
|
-
});
|
|
463
|
-
|
|
464
|
-
test("should handle deeply nested paths correctly", () => {
|
|
465
|
-
const deepFiles = getFilePaths(testDir, "**/structure/*");
|
|
466
|
-
expect(deepFiles.some(path => path.includes("deep-file.txt"))).toBe(true);
|
|
467
|
-
|
|
468
|
-
const deepDirs = getDirectoryPaths(testDir, "**/very/*");
|
|
469
|
-
expect(deepDirs.some(path => path.endsWith("nested"))).toBe(true);
|
|
470
|
-
|
|
471
|
-
const allDeep = getPaths(testDir, "deep/**", "yes");
|
|
472
|
-
expect(allDeep.length).toBeGreaterThanOrEqual(4);
|
|
473
|
-
});
|
|
474
|
-
|
|
475
|
-
test("should normalize paths consistently", () => {
|
|
476
|
-
const files = getFilePaths(testDir, "**/*");
|
|
477
|
-
const dirs = getDirectoryPaths(testDir, "**/*");
|
|
478
|
-
|
|
479
|
-
files.forEach(file => {
|
|
480
|
-
expect(file).toMatch(/^[\/\\]|^[a-zA-Z]:[\/\\]/);
|
|
481
|
-
expect(file).not.toMatch(/[\/\\]$/);
|
|
482
|
-
});
|
|
483
|
-
|
|
484
|
-
dirs.forEach(dir => {
|
|
485
|
-
expect(dir).toMatch(/^[\/\\]|^[a-zA-Z]:[\/\\]/);
|
|
486
|
-
});
|
|
487
|
-
});
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
test("should return the same number of paths with absolute false or true", () => {
|
|
492
|
-
|
|
493
|
-
const absolutes = getDirectoryPaths(testDir, "build/qwerty_*", true);
|
|
494
|
-
const notAbsolutes = getDirectoryPaths(testDir, "build/qwerty_*", false);
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
console.log(JSON.stringify({ absolutes, notAbsolutes }, null, 2));
|
|
498
|
-
|
|
499
|
-
expect(absolutes).toHaveLength(7);
|
|
500
|
-
expect(notAbsolutes).toHaveLength(7);
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
});
|
|
504
|
-
|
|
505
|
-
});
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
})
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|