TheLuckyLoki
TheLuckyLoki
DDeno
Created by TheLuckyLoki on 2/5/2024 in #help
Errors with mocking & testing in supabase edge function running on deno.
I'm gonna have to do some more thinking & research, thank you for your time and input.
5 replies
DDeno
Created by TheLuckyLoki on 2/5/2024 in #help
Errors with mocking & testing in supabase edge function running on deno.
so - the main issue is that the supabaseClientJS is a more complicated package that does not allow us to listen in? The solution is therefore to "swap" the entire package we're running on. this is what I tried doing with import_maps, https://stackoverflow.com/questions/69677679/deno-mock-out-named-import-in-unit-test, and would've been ok with this. However, setting up the import_map in the test env, and calling the tests with a custom map, did not swap the import_map in the code I was testing. Though having learned more since that test I might realize the mistake. in order to simplify my test-suite I created a main.ts for my tests, that looks like this: import testClientCreation from "./client_creation/index.ts" import testCollectInvoices from "./collect_invoices/index.ts" // Register and run the tests Deno.test('Client_Creation Test', testClientCreation) Deno.test('collect_invoices Test', testCollectInvoices) and I would run the test with the following command. deno test --allow-all functions/tests/main.ts --env=.env.local --import-map=functions/tests/index.importmap.json is it possible that the Deno.test(description, testFile) weren't receiving the replaced import_map ? in this solution I created a supabase.mock.ts file that had a sinon solution similar to the provided stack overflow link; the goal being to replace supabase entirely while the testing was happening.
5 replies