Elffuss BraidHub

kikocis/continue public

main · 4.7 KiBRawPermalink
1// Generated by continue
2
3import { testIde } from "../test/fixtures";
4import {
5 TEST_DIR,
6 addToTestDir,
7 setUpTestDir,
8 tearDownTestDir,
9} from "../test/testDir";
10
11import { shouldIgnore } from "./shouldIgnore";
12
13// Test for the shouldIgnore function
14describe("shouldIgnore", () => {
15 beforeEach(() => {
16 setUpTestDir();
17 });
18
19 afterEach(() => {
20 tearDownTestDir();
21 });
22
23 test("should return true if a file is ignored by .gitignore", async () => {
24 addToTestDir([
25 ["ignored-file.txt", "content"],
26 [".gitignore", "ignored-file.txt"],
27 ]);
28 const result = await shouldIgnore(TEST_DIR + "/ignored-file.txt", testIde, [
29 TEST_DIR,
30 ]);
31 expect(result).toBe(true);
32 });
33 test("should return true if a folder is ignored by .continueignore", async () => {
34 addToTestDir([
35 ["ignored-folder/file.txt", "content"],
36 [".continueignore", "ignored-folder/"],
37 ]);
38 const result = await shouldIgnore(
39 TEST_DIR + "/ignored-folder/file.txt",
40 testIde,
41 [TEST_DIR],
42 );
43 expect(result).toBe(true);
44 });
45 test("should return false if a file is not ignored", async () => {
46 addToTestDir([["kept-file.txt", "contents"]]);
47 const result = await shouldIgnore(TEST_DIR + "/kept-file.txt", testIde, [
48 TEST_DIR,
49 ]);
50 expect(result).toBe(false);
51 });
52 test("should return true if a file is ignored by .gitignore with spaces in file name", async () => {
53 addToTestDir([
54 ["ignored file.txt", "content"],
55 [".gitignore", "ignored file.txt"],
56 ]);
57 const result = await shouldIgnore(TEST_DIR + "/ignored file.txt", testIde, [
58 TEST_DIR,
59 ]);
60 expect(result).toBe(true);
61 });
62
63 test("should return true if a .continueignore override ignores file", async () => {
64 addToTestDir([
65 ["override-file.txt", "content"],
66 [".gitignore", "override-file.txt"],
67 [".continueignore", "!override-file.txt"],
68 ]);
69 const result = await shouldIgnore(
70 TEST_DIR + "/override-file.txt",
71 testIde,
72 [TEST_DIR],
73 );
74 expect(result).toBe(false);
75 });
76
77 test("should return true for deeply nested file ignored by ignore files at multiple levels", async () => {
78 addToTestDir([
79 ["level1/level2/level3/ignored-file.txt", "content"],
80 ["level1/.gitignore", "level2/"],
81 ["level1/level2/.continueignore", "level3/"],
82 ]);
83 const result = await shouldIgnore(
84 TEST_DIR + "/level1/level2/level3/ignored-file.txt",
85 testIde,
86 [TEST_DIR],
87 );
88 expect(result).toBe(true);
89 });
90
91 test("should return false if a file with spaces is not ignored", async () => {
92 addToTestDir([["kept file.txt", "contents"]]);
93 const result = await shouldIgnore(TEST_DIR + "/kept file.txt", testIde, [
94 TEST_DIR,
95 ]);
96 expect(result).toBe(false);
97 });
98
99 test("should handle multiple levels of directories with some files ignored", async () => {
100 addToTestDir([
101 ["nested/dir1/.gitignore", "ignored.txt"],
102 ["nested/dir1/ignored.txt", "content"],
103 ["nested/dir2/kept.txt", "content"],
104 ]);
105 const ignoredResult = await shouldIgnore(
106 TEST_DIR + "/nested/dir1/ignored.txt",
107 testIde,
108 [TEST_DIR],
109 );
110 expect(ignoredResult).toBe(true);
111
112 const keptResult = await shouldIgnore(
113 TEST_DIR + "/nested/dir2/kept.txt",
114 testIde,
115 [TEST_DIR],
116 );
117 expect(keptResult).toBe(false);
118 });
119
120 test("should respect default file and folder ignores top level", async () => {
121 addToTestDir([
122 [".env", "contents"],
123 ["go.sum", "contents"],
124 ".idea/",
125 [".idea/test.xml", "contents"],
126 ]);
127 let result = await shouldIgnore(TEST_DIR + "/.env", testIde, [TEST_DIR]);
128 expect(result).toBe(true);
129
130 result = await shouldIgnore(TEST_DIR + "/go.sum", testIde, [TEST_DIR]);
131 expect(result).toBe(true);
132
133 result = await shouldIgnore(TEST_DIR + "/.idea", testIde, [TEST_DIR]);
134 expect(result).toBe(true);
135
136 result = await shouldIgnore(TEST_DIR + "/.idea/test.xml", testIde, [
137 TEST_DIR,
138 ]);
139 expect(result).toBe(true);
140 });
141
142 test("should respect default file and folder ignores at nested level", async () => {
143 addToTestDir([
144 "nested/.idea/test.xml",
145 ["nested/.env", "contents"],
146 ["nested/go.sum", "contents"],
147 ]);
148
149 let result = await shouldIgnore(TEST_DIR + "/nested/.idea", testIde, [
150 TEST_DIR,
151 ]);
152 expect(result).toBe(true);
153
154 result = await shouldIgnore(TEST_DIR + "/nested/.idea/test.xml", testIde, [
155 TEST_DIR,
156 ]);
157 expect(result).toBe(true);
158
159 result = await shouldIgnore(TEST_DIR + "/nested/.env", testIde, [TEST_DIR]);
160 expect(result).toBe(true);
161
162 result = await shouldIgnore(TEST_DIR + "/nested/go.sum", testIde, [
163 TEST_DIR,
164 ]);
165 expect(result).toBe(true);
166 });
167});