Skip to content

Commit

Permalink
Fix: updating test.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
Villarley committed Dec 22, 2024
1 parent f2bfabb commit f74888a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI - Run Tests
name: Run Tests

on:
push:
Expand All @@ -24,8 +24,7 @@ jobs:
- name: Install Dependencies
run: npm ci

- name: Set Environment Variables
run: echo "NODE_ENV=test" >> $GITHUB_ENV

- name: Run Tests
env:
NODE_ENV: test
run: npm test
12 changes: 8 additions & 4 deletions src/tests/setup.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
import AppDataSource from "../config/ormconfig";

beforeAll(async () => {
console.log("Initializing database...");
if (!AppDataSource.isInitialized) {
await AppDataSource.initialize();
}
console.log("Database initialized.");

if (process.env.NODE_ENV === "test") {
console.log("Synchronizing database...");
await AppDataSource.synchronize();

const queryRunner = AppDataSource.createQueryRunner();
const tables = await queryRunner.getTables();
await queryRunner.release();
console.log("Database synchronized.");
}
});

afterEach(async () => {
console.log("Clearing database...");
const entities = AppDataSource.entityMetadatas;
for (const entity of entities) {
const repository = AppDataSource.getRepository(entity.name);
await repository.clear();
}
console.log("Database cleared.");
});

afterAll(async () => {
console.log("Destroying database...");
if (AppDataSource.isInitialized) {
await AppDataSource.destroy();
}
console.log("Database destroyed.");
});

0 comments on commit f74888a

Please sign in to comment.