Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

test setup

Aashish-Upadhyay-10146f2b7a3f8e7
diff --git a/backend/jest.config.ts b/backend/jest.config.ts
new file mode 100644
index 0000000000..b7ca988db8
--- /dev/null
+++ b/backend/jest.config.ts
@@ -0,0 +1,9 @@
+export default {
+ preset: 'ts-jest',
+ testEnvironment: 'node',
+ collectCoverageFrom: ['src/*.{js,ts}', '!**/node_modules/**'],
+ modulePaths: ['<rootDir>/src'],
+ testMatch: ['<rootDir>/tests/**/*.test.ts'],
+ setupFiles: ['<rootDir>/test-resources/env-vars.js'],
+ setupFilesAfterEnv: ['<rootDir>/setupTests.ts']
+};
diff --git a/backend/package.json b/backend/package.json
index cd6cd214ac..f24ef80fa3 100644
--- a/backend/package.json
+++ b/backend/package.json
@@ -101,17 +101,6 @@
"ts-jest": "^29.0.3",
"ts-node": "^10.9.1"
},
- "jest": {
- "preset": "ts-jest",
- "testEnvironment": "node",
- "collectCoverageFrom": [
- "src/*.{js,ts}",
- "!**/node_modules/**"
- ],
- "setupFiles": [
- "<rootDir>/test-resources/env-vars.js"
- ]
- },
"jest-junit": {
"outputDirectory": "reports",
"outputName": "jest-junit.xml",
diff --git a/backend/setupTests.ts b/backend/setupTests.ts
new file mode 100644
index 0000000000..c98a366f9d
--- /dev/null
+++ b/backend/setupTests.ts
@@ -0,0 +1,11 @@
+import { beforeAll, afterAll } from '@jest/globals';
+import { DatabaseService } from './src/services';
+
+beforeAll(async () => {
+ const mongoURL = process.env.MONGO_URL!;
+ await DatabaseService.initDatabase(mongoURL);
+});
+
+afterAll(async () => {
+ await DatabaseService.closeDatabase();
+});
diff --git a/backend/__tests__/healthcheck.test.ts b/backend/tests/healthcheck.test.ts
similarity index 100%
rename from backend/__tests__/healthcheck.test.ts
rename to backend/tests/healthcheck.test.ts