Open ghost opened 1 year ago
Ugly workaround to make my tests pass ...
Deno.test("Test something", async () => {
try {
await testSomething();
} catch (error) {
console.error(error);
} finally {
const resources = Deno.resources();
for (const rid in resources) {
if (resources[rid] === "fetchResponse") {
Deno.close(parseInt(rid));
}
}
}
});}
Also running into this when running tests with supabase-js, it seems to only happen on tests that are testing for an error response
Any news on this?
This worked for us:
const { data, error } = await supabaseUser.functions.invoke('some-function', {
body: {
userId: 'invalid-id'
}
})
assertEquals(data, null)
await assertError(error, 'expected error message')
And:
export async function assertError(
error: FunctionsHttpError | FunctionsRelayError | FunctionsFetchError,
expectedErrorMessage: string,
) {
assertEquals(error.name, 'FunctionsHttpError')
const { message: actualErrorMessage }: { message: string } = await error.context.json()
assertEquals(
actualErrorMessage,
expectedErrorMessage,
)
}
Because we always return a message with an error response:
const responseData = { message, data }
return new Response(JSON.stringify(responseData), {
headers: { ...corsHeaders, 'Content-Type': 'application/json' },
status: httpStatusCode,
})
Which we can assert in the edge function test.
Bug report
Describe the bug
I am trying to write some negative tests for my edge functions, for example:
But when running
deno test
, the test fails with:But I cannot access the response to consume/close/cancel/... it.
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
deno test
Expected behavior
I expect the test to pass, without any leaking resources.
System information