feat: Add global hooks for jest
This commit is contained in:
@@ -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',
|
||||||
};
|
};
|
17
packages/backend/test/setup/global-hooks.ts
Normal file
17
packages/backend/test/setup/global-hooks.ts
Normal 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();
|
||||||
|
});
|
5
packages/backend/test/setup/global-teardown.ts
Normal file
5
packages/backend/test/setup/global-teardown.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
const exitProcess = (): void => {
|
||||||
|
process.exit(0);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default exitProcess;
|
Reference in New Issue
Block a user