Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(test): stop integration test hook and case timeouts

justin71dfe19669ee
diff --git a/apps/api/vitest.integration.config.ts b/apps/api/vitest.integration.config.ts
index 91bc1742e..db07870e5 100644
--- a/apps/api/vitest.integration.config.ts
+++ b/apps/api/vitest.integration.config.ts
@@ -9,6 +9,8 @@ export default defineConfig({
fileParallelism: false,
maxWorkers: 1,
minWorkers: 1,
+ hookTimeout: 60_000,
+ testTimeout: 60_000,
coverage: {
enabled: false,
},
diff --git a/tests/api-integration/helpers/database.ts b/tests/api-integration/helpers/database.ts
index 5fdaaf6d4..acd784629 100644
--- a/tests/api-integration/helpers/database.ts
+++ b/tests/api-integration/helpers/database.ts
@@ -3,11 +3,39 @@ import { fileURLToPath } from "node:url";
import { sql } from "drizzle-orm";
import { migrate } from "drizzle-orm/node-postgres/migrator";
import { Client } from "pg";
-import db from "../../../apps/api/src/database";
+import db, { schema } from "../../../apps/api/src/database";
const currentDir = dirname(fileURLToPath(import.meta.url));
const migrationsFolder = resolve(currentDir, "../../../apps/api/drizzle");
+const drizzleNameSymbol = Object.getOwnPropertySymbols(
+ Object.values(schema).find((value) => value && typeof value === "object") ??
+ {},
+).find((sym) => sym.toString() === "Symbol(drizzle:Name)");
+
+if (!drizzleNameSymbol) {
+ throw new Error(
+ "Could not locate Drizzle table name symbol; schema introspection changed",
+ );
+}
+
+function getTruncateTableNames() {
+ return Object.entries(schema)
+ .filter(
+ ([key, value]) =>
+ key.endsWith("Table") &&
+ !key.endsWith("TableRelations") &&
+ value &&
+ typeof value === "object" &&
+ drizzleNameSymbol in value,
+ )
+ .map(
+ ([, value]) =>
+ (value as Record<symbol, unknown>)[drizzleNameSymbol] as string,
+ )
+ .sort();
+}
+
let migrationPromise: Promise<void> | null = null;
function getDatabaseName(connectionString: string) {
@@ -82,36 +110,10 @@ export async function ensureTestDatabaseMigrated() {
export async function resetTestDatabase() {
await ensureTestDatabaseMigrated();
+ const tableNames = getTruncateTableNames();
+ const formattedTableNames = tableNames.map((name) => `"${name}"`).join(", ");
+
await db.execute(
- sql.raw(`
- TRUNCATE TABLE
- "activity",
- "account",
- "apikey",
- "asset",
- "billing_event",
- "column",
- "comment",
- "external_link",
- "github_integration",
- "integration",
- "invitation",
- "label",
- "mcp_oauth_state",
- "notification",
- "project",
- "session",
- "task",
- "task_relation",
- "team",
- "team_member",
- "time_entry",
- "verification",
- "workflow_rule",
- "workspace",
- "workspace_member",
- "user"
- RESTART IDENTITY CASCADE
- `),
+ sql.raw(`TRUNCATE TABLE ${formattedTableNames} RESTART IDENTITY CASCADE`),
);
}