-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMODULE_GLOB.test.mjs
79 lines (68 loc) · 2.03 KB
/
MODULE_GLOB.test.mjs
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
// @ts-check
import { deepEqual } from "node:assert";
import { mkdir, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { describe, it } from "node:test";
import disposableDirectory from "disposable-directory";
import { globby } from "globby";
import MODULE_GLOB from "./MODULE_GLOB.mjs";
describe("Constant `MODULE_GLOB`.", { concurrency: true }, () => {
describe("Matching modules.", async () => {
for (const fileExtension of [
"cjs",
"cts",
"js",
"jsx",
"mjs",
"mts",
"ts",
"tsx",
])
it(`File extension \`${fileExtension}\`.`, async () => {
await disposableDirectory(async (tempDirPath) => {
const fileNames = [
`a.${fileExtension}`,
// Test that dotfiles are included.
`.${fileExtension}`,
`.a.${fileExtension}`,
// Test that files with a name ending in `d` aren’t mistakenly
// excluded as a TypeScript declaration file.
`ad.${fileExtension}`,
];
const subdirectoryName = "a";
const expectedPaths = [
...fileNames,
// Test that files in subdirectories are recursively included.
...fileNames.map((fileName) => join(subdirectoryName, fileName)),
].sort();
await mkdir(join(tempDirPath, subdirectoryName));
await Promise.all(
expectedPaths.map((relativePath) =>
writeFile(join(tempDirPath, relativePath), ""),
),
);
deepEqual(
(
await globby(MODULE_GLOB, {
cwd: tempDirPath,
dot: true,
})
).sort(),
expectedPaths,
);
});
});
});
it("Excluded files.", async () => {
deepEqual(
await globby(MODULE_GLOB, {
cwd: new URL(
"./test/fixtures/MODULE_GLOB/excluded-files/",
import.meta.url,
),
dot: true,
}),
[],
);
});
});