We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hi,
I'm new with supabase and supabase-js.
I'm trying to validate my polices working with supabase-js testings.
I would like to use "import" instead of "require" but I have an error: SyntaxError: Cannot use import statement outside a module
How to enable "import"?
Here is the packages.json:
{ "name": "supabase-tests", "version": "1.0.0", "type": "module", "scripts": { "supabase:env": "npx supabase status -o env > .env", "supabase:start": "npx supabase start", "test": "jest", "test:watch": "jest --watch" }, "dependencies": { "@supabase/supabase-js": "^2.0.0", "dotenv": "^16.4.7" }, "devDependencies": { "@types/jest": "^29.0.0", "jest": "^29.0.0", "ts-jest": "^29.0.0" } }
supabaseClient.ts
import { createClient } from "@supabase/supabase-js"; require('dotenv/config'); const { SERVICE_ROLE_KEY, API_URL } = process.env; if (!SERVICE_ROLE_KEY || !API_URL) { throw new Error('Missing environment variables. Verify supabase is started and environment variables are set.'); } // Connect to the local Supabase instance const supabaseUrl = process.env.SUPABASE_URL || API_URL; const supabaseKey = process.env.SUPABASE_ANON_KEY || SERVICE_ROLE_KEY; export const supabase = createClient(supabaseUrl, supabaseKey);
api.test.ts:
import { supabase } from "./supabaseClient"; test('Fetch users from local Supabase instance', async () => { const { data, error } = await supabase.from('users').select('*'); expect(error).toBeNull(); expect(data).toBeInstanceOf(Array); });
The text was updated successfully, but these errors were encountered:
You need to preconfigure jest in order for it to understand typescript compilation. See: https://jestjs.io/docs/getting-started#using-typescript and https://jestjs.io/docs/ecmascript-modules
Or better yet use https://vitest.dev/guide/ which supports both typescript and esm out of the box :)
Sorry, something went wrong.
vitest was the solution! Thanks @kamilogorek !
No branches or pull requests
Hi,
I'm new with supabase and supabase-js.
I'm trying to validate my polices working with supabase-js testings.
I would like to use "import" instead of "require" but I have an error:
SyntaxError: Cannot use import statement outside a module
How to enable "import"?
Here is the packages.json:
supabaseClient.ts
api.test.ts:
The text was updated successfully, but these errors were encountered: