Skip to content

Commit de684cf

Browse files
committed
test: add global jest setup/teardown for db/redis
1 parent 31baebc commit de684cf

3 files changed

Lines changed: 23 additions & 21 deletions

File tree

backend/jest.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@ export default {
1515
"^(\\.{1,2}/.*)\\.js$": "$1",
1616
},
1717
testMatch: ["**/*.test.ts", "**/*.spec.ts"],
18+
19+
// 👇 Point to the actual location of setup.ts
20+
setupFilesAfterEnv: ["<rootDir>/src/__tests__/setup.ts"],
1821
};

backend/package-lock.json

Lines changed: 0 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/src/__tests__/setup.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { db } from "../src/db/connection";
2+
import Redis from "ioredis";
3+
4+
let redis: Redis;
5+
6+
beforeAll(async () => {
7+
redis = new Redis(process.env.REDIS_URL);
8+
if (db.connect) {
9+
await db.connect();
10+
}
11+
});
12+
13+
afterAll(async () => {
14+
if (redis) {
15+
await redis.quit();
16+
}
17+
if (db.end) {
18+
await db.end();
19+
}
20+
});

0 commit comments

Comments
 (0)