Skip to content

Commit 29a9c7d

Browse files
committed
fix(tests): make trash test not fail when other test suites' items are still in trash; undo some thing I thought would fix it
1 parent f9f97ae commit 29a9c7d

4 files changed

Lines changed: 14 additions & 13 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"start": "bun run src/index.ts",
99
"lint": "eslint \"src/**/*.{js,jsx,ts,tsx}\" --ext .js,.jsx,.ts,.tsx",
1010
"lint-ci": "eslint \"src/**/*.{js,jsx,ts,tsx}\" --ext .js,.jsx,.ts,.tsx --format=@microsoft/eslint-formatter-sarif --output-file=eslint-report.sarif",
11-
"test": "bun test --preload ./src/test/setup.ts --timeout 60_000",
11+
"test": "bun test --preload ./src/test/setup.ts --timeout 30_000",
1212
"compile": "bun build --compile --target=bun --minify --sourcemap src/index.ts --outfile filen-cli --define IS_RUNNING_AS_BINARY=true",
1313
"bump-filen-dependencies": "bun i @filen/sdk@latest @filen/sync@latest @filen/webdav@latest @filen/s3@latest @filen/network-drive@latest"
1414
},

src/app/featureInterfaces/fs.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ describe("fs commands", async () => {
177177
})
178178

179179
/**
180-
* Waits for 15s to allow async operations to complete.
180+
* Waits for 10s to allow async operations to complete.
181181
*/
182182
export async function waitForAsyncEndpoint() {
183-
return new Promise(resolve => setTimeout(resolve, 15_000))
183+
return new Promise(resolve => setTimeout(resolve, 10_000))
184184
}

src/app/featureInterfaces/trashInterface.test.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,16 @@ describe("trash", async () => {
1616

1717
beforeAll(async () => {
1818
await filen.cloud().emptyTrash()
19-
root = (await prepareCloudFs([ "file1.txt", "file2.txt" ])).root
20-
await filen.fs().rm({ path: root.navigate("file1.txt").toString(), permanent: false })
21-
await filen.fs().rm({ path: root.navigate("file2.txt").toString(), permanent: false })
19+
root = (await prepareCloudFs([ "trashtest_file1.txt", "trashtest_file2.txt" ])).root
20+
await filen.fs().rm({ path: root.navigate("trashtest_file1.txt").toString(), permanent: false })
21+
await filen.fs().rm({ path: root.navigate("trashtest_file2.txt").toString(), permanent: false })
2222
})
2323

2424
it("should list trash items", async () => {
25-
await waitForAsyncEndpoint()
2625
await waitForAsyncEndpoint()
2726
const { output } = await runMockApp({ cmd: "trash list" })
28-
expect(output()).toContain("file1.txt")
29-
expect(output()).toContain("file2.txt")
27+
expect(output()).toContain("trashtest_file1.txt")
28+
expect(output()).toContain("trashtest_file2.txt")
3029
})
3130

3231
it("should delete trash item", async () => {
@@ -43,7 +42,9 @@ describe("trash", async () => {
4342
it("should list empty trash", async () => {
4443
await waitForAsyncEndpoint()
4544
const { output } = await runMockApp({ cmd: "trash list" })
46-
expect(output()).toContain("empty")
45+
expect(output()).not.toContain("trashtest_file1.txt")
46+
expect(output()).not.toContain("trashtest_file2.txt")
47+
// there might be other test suites running concurrently, so we can't check that it's completely empty
4748
})
4849

4950
})

src/test/tests.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,13 @@ export class ResourceLock {
192192
* We cannot simply use the credentials every time (or even every run) because of rate limiting.
193193
*/
194194
async function readFromDotenvFile(key: string) {
195-
const dotenvFile = Bun.file(".env");
195+
const dotenvFile = Bun.file(".env")
196196
if (!(await dotenvFile.exists())) return undefined
197197

198198
const content = await dotenvFile.text()
199199
let value = ""
200200
for (let i = 0;; i++) {
201-
const chunk = content.match(new RegExp(`^${key}_${i}="([^"]+)"`))
201+
const chunk = content.match(new RegExp(`^${key}_${i}="([^"]+)"`, "gm"))
202202
if (!chunk) break
203203
value += chunk[1]
204204
}
@@ -208,7 +208,7 @@ async function writeAuthConfigToDotenvFile(key: string, str: string) {
208208
const dotenvFile = Bun.file(".env");
209209
if (!(await dotenvFile.exists())) return
210210

211-
const CHUNK_LENGTH = 4096
211+
const CHUNK_LENGTH = 4096 - 100
212212
const chunks: string[] = []
213213
let i = 0
214214
while (i < str.length) {

0 commit comments

Comments
 (0)