-
Notifications
You must be signed in to change notification settings - Fork 1
/
jest.setup.ts
44 lines (38 loc) · 1.19 KB
/
jest.setup.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import './src/import-first'
import knex from "@infrastructure/knex/knex"
import mysql from "mysql2";
import { Config } from '@config/config';
import { EnvironmentType } from '@config/types/config';
jest.mock('ioredis', () => require('ioredis-mock'))
const config = new Config()
const executeSql = (sql: string)=>{
return new Promise((resolve, reject)=>{
if(config.get().environment == EnvironmentType.Test) {
const query = mysql.createConnection({
host: config.get().db.host,
user: config.get().db.user,
password: config.get().db.password,
port: config.get().db.port,
});
query.execute(sql, (err, results)=>{
if(err){
reject(err);
query.destroy();
}
query.destroy();
resolve(results);
});
} else {
resolve(null);
}
});
};
beforeAll(async()=>{
await Promise.all([
await executeSql(`CREATE DATABASE IF NOT EXISTS ${config.get().db.database}_test`),
await knex.migrate.latest()
]);
})
afterAll(async()=>{
await knex.destroy()
})