diff --git a/jest.config.ts b/jest.config.ts index 6b3f2d6..7d35575 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -1,5 +1,5 @@ -import { getJestProjectsAsync } from '@nx/jest'; +import { getJestProjectsAsync } from "@nx/jest"; export default async () => ({ - projects: await getJestProjectsAsync(), + projects: await getJestProjectsAsync() }); diff --git a/jest.preset.js b/jest.preset.js index ee18844..6ee150a 100644 --- a/jest.preset.js +++ b/jest.preset.js @@ -1,4 +1,4 @@ -const nxPreset = require('@nx/jest/preset').default; +const nxPreset = require("@nx/jest/preset").default; module.exports = { ...nxPreset, @@ -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"] +}; diff --git a/jest/setup-jest-global.ts b/jest/setup-jest-global.ts new file mode 100644 index 0000000..2c1c599 --- /dev/null +++ b/jest/setup-jest-global.ts @@ -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(); +}; diff --git a/setup-jest.ts b/jest/setup-jest.ts similarity index 89% rename from setup-jest.ts rename to jest/setup-jest.ts index 173c0ea..a672300 100644 --- a/setup-jest.ts +++ b/jest/setup-jest.ts @@ -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()); });