-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathcore.test.ts
More file actions
68 lines (62 loc) · 1.79 KB
/
core.test.ts
File metadata and controls
68 lines (62 loc) · 1.79 KB
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
import { readdir, readFile } from "fs/promises";
import { join, resolve } from "path";
const testAllFiles = async (
assertion: (content: string, filename: string) => void,
) => {
const baseDir = resolve(__dirname, "./core");
const files = await readdir(baseDir);
for (const file of files.filter(
(f) => f.endsWith(".ts") && !f.endsWith(".test.ts"),
)) {
const content = await readFile(join(baseDir, file), {
encoding: "utf8",
});
assertion(content, file);
}
};
/**
* These tests are used to ensure that everything in the ./core directory
* can be included from React. Please be careful when modifying them!
*/
describe("./core directory", () => {
it("should not contain any imports from base directory (../)", async () => {
testAllFiles((content, file) =>
content.should.not.match(
/import .+ from "\.\./gi,
`${file} contains an import from the base directory`,
),
);
});
it('should not contain any imports from "os"', async () => {
await testAllFiles((content, file) =>
content.should.not.match(
/import .+ from "os";/gi,
`${file} contains an import from "os"`,
),
);
});
it('should not contain any imports from "fs"', async () => {
await testAllFiles((content, file) =>
content.should.not.match(
/import .+ from "fs";/gi,
`${file} contains an import from "fs"`,
),
);
});
it('should not contain any imports from "fs-extra"', async () => {
await testAllFiles((content, file) =>
content.should.not.match(
/import .+ from "fs-extra";/gi,
`${file} contains an import from "fs-extra"`,
),
);
});
it('should not contain any imports from "path"', async () => {
await testAllFiles((content, file) =>
content.should.not.match(
/import .+ from "path";/gi,
`${file} contains an import from "path"`,
),
);
});
});