This commit is contained in:
rinsuki 2019-10-25 23:34:29 +09:00
parent c49dfd45e6
commit d7263bea1b
2 changed files with 16 additions and 9 deletions

View File

@ -133,11 +133,13 @@ export const entities = [
...charts as any
];
export function initDb(justBorrow = false, sync = false, log = false) {
try {
const conn = getConnection();
return Promise.resolve(conn);
} catch (e) {}
export function initDb(justBorrow = false, sync = false, log = false, forceRecreate = false) {
if (!forceRecreate) {
try {
const conn = getConnection();
return Promise.resolve(conn);
} catch (e) {}
}
return createConnection({
type: 'postgres',

View File

@ -26,15 +26,15 @@ import * as _TestUniqueChart from '../src/services/chart/charts/schemas/test-uni
import { Connection, getConnection, createConnection } from 'typeorm';
import config from '../src/config';
import Chart from '../src/services/chart/core';
import { initDb } from '../src/db/postgre';
function initDb() {
function initChartDb() {
try {
const conn = getConnection('__for_chart_testing');
const conn = getConnection();
return Promise.resolve(conn);
} catch (e) {}
return createConnection({
name: '__for_chart_testing',
type: 'postgres',
host: config.db.host,
port: config.db.port,
@ -59,12 +59,17 @@ describe('Chart', () => {
let connection: Connection;
before(done => {
initDb().then(c => {
initChartDb().then(c => {
connection = c;
done();
});
});
after(async(async () => {
await connection.close();
await initDb(true, undefined, undefined, true);
}));
beforeEach(done => {
testChart = new TestChart();
testGroupedChart = new TestGroupedChart();