feat: Add global hooks for jest

This commit is contained in:
Faruk AYDIN
2023-10-01 17:20:07 +02:00
parent 4d454ec932
commit 0e5529b4ca
3 changed files with 25 additions and 1 deletions

View File

@@ -2,4 +2,6 @@
module.exports = { module.exports = {
preset: 'ts-jest', preset: 'ts-jest',
testEnvironment: 'node', testEnvironment: 'node',
setupFilesAfterEnv: ['./test/setup/global-hooks.ts'],
globalTeardown: './test/setup/global-teardown.ts',
}; };

View File

@@ -0,0 +1,17 @@
import { client as knex } from '../../src/config/database';
global.beforeAll(async () => {
global.knex = knex;
});
global.beforeEach(async function () {
this.transaction = await global.knex.transaction();
});
global.afterEach(async function () {
await this.transaction.rollback();
});
global.afterAll(async () => {
global.knex.destroy();
});

View File

@@ -0,0 +1,5 @@
const exitProcess = (): void => {
process.exit(0);
};
export default exitProcess;