.Literfieber
.Literfieber•16mo ago

Deno test Leaking resources

Hi i currently try to get used to deno.test but Deno.readTextFile makes the test end in the following error:
error: Leaking resources:
- A file (rid 3) was opened during the test, but not closed during the test. Close the file handle by calling `file.close()`.
error: Leaking resources:
- A file (rid 3) was opened during the test, but not closed during the test. Close the file handle by calling `file.close()`.
My function looks like this:
export async function test() {
try {
const test = await Deno.readTextFile("./test.txt");
return true
}
catch (err) {
log(err);
return false;
}
}
export async function test() {
try {
const test = await Deno.readTextFile("./test.txt");
return true
}
catch (err) {
log(err);
return false;
}
}
Is there a way to close the file so that i don't get the error ?
4 Replies
ioB
ioB•16mo ago
could you share the actual test code you're using, it doesn't look like there's an error in this
.Literfieber
.LiterfieberOP•16mo ago
Deno.test(async function t() {
const res = await collection.test()
assertEquals(res, true)
}
)
Deno.test(async function t() {
const res = await collection.test()
assertEquals(res, true)
}
)
ioB
ioB•16mo ago
I cannot reproduce this on my end this is the code I'm using (derived from yours):
import { assertEquals } from "https://deno.land/std@0.196.0/assert/assert_equals.ts"

export async function test() {
try {
const test = await Deno.readTextFile("./test.txt");
return true
}
catch (err) {
return false;
}
}

Deno.test(async function t() {
const res = await test()
assertEquals(res, true)
})
import { assertEquals } from "https://deno.land/std@0.196.0/assert/assert_equals.ts"

export async function test() {
try {
const test = await Deno.readTextFile("./test.txt");
return true
}
catch (err) {
return false;
}
}

Deno.test(async function t() {
const res = await test()
assertEquals(res, true)
})
what version of deno are you using
.Literfieber
.LiterfieberOP•16mo ago
i found it it was a different function for sqlite where i forogt to close the db 😭 Thank you for your help anyways