test setup

This commit is contained in:
Aashish-Upadhyay-101
2023-03-16 17:34:11 +05:45
parent 3d818f953d
commit 46f2b7a3f8
4 changed files with 20 additions and 11 deletions

9
backend/jest.config.ts Normal file
View File

@@ -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']
};

View File

@@ -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",

11
backend/setupTests.ts Normal file
View File

@@ -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();
});