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 ...charts as any
]; ];
export function initDb(justBorrow = false, sync = false, log = false) { export function initDb(justBorrow = false, sync = false, log = false, forceRecreate = false) {
try { if (!forceRecreate) {
const conn = getConnection(); try {
return Promise.resolve(conn); const conn = getConnection();
} catch (e) {} return Promise.resolve(conn);
} catch (e) {}
}
return createConnection({ return createConnection({
type: 'postgres', 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 { Connection, getConnection, createConnection } from 'typeorm';
import config from '../src/config'; import config from '../src/config';
import Chart from '../src/services/chart/core'; import Chart from '../src/services/chart/core';
import { initDb } from '../src/db/postgre';
function initDb() { function initChartDb() {
try { try {
const conn = getConnection('__for_chart_testing'); const conn = getConnection();
return Promise.resolve(conn); return Promise.resolve(conn);
} catch (e) {} } catch (e) {}
return createConnection({ return createConnection({
name: '__for_chart_testing',
type: 'postgres', type: 'postgres',
host: config.db.host, host: config.db.host,
port: config.db.port, port: config.db.port,
@ -59,12 +59,17 @@ describe('Chart', () => {
let connection: Connection; let connection: Connection;
before(done => { before(done => {
initDb().then(c => { initChartDb().then(c => {
connection = c; connection = c;
done(); done();
}); });
}); });
after(async(async () => {
await connection.close();
await initDb(true, undefined, undefined, true);
}));
beforeEach(done => { beforeEach(done => {
testChart = new TestChart(); testChart = new TestChart();
testGroupedChart = new TestGroupedChart(); testGroupedChart = new TestGroupedChart();