Skip to content

Commit

Permalink
[TM-1452] Sync the schema before any test suites run.
Browse files Browse the repository at this point in the history
  • Loading branch information
roguenet committed Nov 20, 2024
1 parent 7c07768 commit 5b19c20
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
4 changes: 2 additions & 2 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getJestProjectsAsync } from '@nx/jest';
import { getJestProjectsAsync } from "@nx/jest";

export default async () => ({
projects: await getJestProjectsAsync(),
projects: await getJestProjectsAsync()
});
9 changes: 5 additions & 4 deletions jest.preset.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const nxPreset = require('@nx/jest/preset').default;
const nxPreset = require("@nx/jest/preset").default;

module.exports = {
...nxPreset,
Expand All @@ -8,9 +8,10 @@ module.exports = {
branches: 85,
functions: 95,
lines: 95,
statements: 95,
statements: 95
}
},

setupFilesAfterEnv: ['./setup-jest.ts'],
}
globalSetup: "./jest/setup-jest-global.ts",
setupFilesAfterEnv: ["./jest/setup-jest.ts"]
};
19 changes: 19 additions & 0 deletions jest/setup-jest-global.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const { Sequelize } = require("sequelize-typescript");
const Entities = require("../libs/database/src/lib/entities");

module.exports = async () => {
// To create this database, run the ./setup-test-database.sh script.
const sequelize = new Sequelize({
dialect: "mariadb",
host: "localhost",
port: 3360,
username: "wri",
password: "wri",
database: "terramatch_microservices_test",
models: Object.values(Entities),
logging: false
});

await sequelize.sync();
await sequelize.close();
};
4 changes: 1 addition & 3 deletions setup-jest.ts → jest/setup-jest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ beforeAll(async () => {
password: "wri",
database: "terramatch_microservices_test",
models: Object.values(Entities),
logging: false,
sync: { alter: true }
logging: false
});

await sequelize.sync();
FactoryGirl.setAdapter(new SequelizeAdapter());
});

Expand Down

0 comments on commit 5b19c20

Please sign in to comment.