Skip to content

A full-featured CRM built with React, shadcn/ui, and Supabase.

separate app unit test from supabase function one to avoid race condition issue

ThieryMicheld4cfc835c9d9
diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml
index 4d4e6853..e63bf3ce 100644
--- a/.github/workflows/check.yml
+++ b/.github/workflows/check.yml
@@ -45,7 +45,7 @@ jobs:
prettier: true
prettier_args: "--config ./.prettierrc.json \"**/*.{js,json,ts,tsx,css,md,html}\""
- test:
+ test-app:
name: πŸ”Ž Test
runs-on: ubuntu-latest
timeout-minutes: 10
@@ -66,8 +66,10 @@ jobs:
- name: 🎭 Install Playwright browsers
run: npx playwright install chromium chromium-headless-shell
- - name: πŸ”Ž Unit Tests
- run: CI=1 npm test -- --run
+ - name: πŸ”Ž Unit Tests on App
+ run: CI=1 npm run test:unit:app -- --run
+ - name: πŸ”Ž Unit Tests on Supabase functions
+ run: CI=1 npm run test:unit:functions -- --run
- name: πŸ”Ž Integration Tests
run: CI=1 npm run test:integration -- --run
diff --git a/package.json b/package.json
index cd49f681..3e121ec8 100644
--- a/package.json
+++ b/package.json
@@ -4,7 +4,8 @@
"type": "module",
"scripts": {
"test": "npm run test:unit",
- "test:unit": "vitest --config vitest.config.ts",
+ "test:unit:app": "vitest --config vitest.config.ts",
+ "test:unit:functions": "vitest --config vitest.functions.config.ts",
"test:integration": "vitest --config vitest.integration.config.ts",
"dev": "vite --force",
"dev:demo": "vite --config vite.demo.config --force",
diff --git a/src/components/atomic-crm/deals/dealUtils.spec.ts b/src/components/atomic-crm/deals/dealUtils.spec.ts
index aaad7cbc..53f9e194 100644
--- a/src/components/atomic-crm/deals/dealUtils.spec.ts
+++ b/src/components/atomic-crm/deals/dealUtils.spec.ts
@@ -1,4 +1,4 @@
-import { commands } from "@vitest/browser/context";
+import { commands } from "vitest/browser";
import { formatISODateString } from "./dealUtils";
diff --git a/vitest.config.ts b/vitest.config.ts
index 611379c6..89d20485 100644
--- a/vitest.config.ts
+++ b/vitest.config.ts
@@ -25,6 +25,7 @@ export default defineConfig({
"**/node_modules/**",
"doc/**",
"src/**/*.integration.test.{ts,tsx}",
+ "supabase/**",
],
},
resolve: {
diff --git a/vitest.functions.config.ts b/vitest.functions.config.ts
new file mode 100644
index 00000000..283d90b5
--- /dev/null
+++ b/vitest.functions.config.ts
@@ -0,0 +1,24 @@
+import path from "node:path";
+import { defineConfig } from "vitest/config";
+
+// Separate config for Supabase Edge Function tests.
+// These files are written for Deno and use JSR imports (jsr:@supabase/supabase-js@2)
+// that Vite cannot resolve. We alias jsr: imports to their npm equivalents so
+// Vitest can run the tests in a Node environment without a Deno runtime.
+export default defineConfig({
+ test: {
+ globals: true,
+ environment: "node",
+ include: ["supabase/functions/**/*.test.ts"],
+ exclude: ["**/node_modules/**"],
+ },
+ resolve: {
+ alias: {
+ // Map the Deno JSR import to the installed npm package
+ "jsr:@supabase/supabase-js@2": path.resolve(
+ __dirname,
+ "node_modules/@supabase/supabase-js",
+ ),
+ },
+ },
+});