From d7263bea1b963bf6a7fa2766056f5db768385002 Mon Sep 17 00:00:00 2001 From: rinsuki <428rinsuki+git@gmail.com> Date: Fri, 25 Oct 2019 23:34:29 +0900 Subject: [PATCH] fix --- src/db/postgre.ts | 12 +++++++----- test/chart.ts | 13 +++++++++---- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/db/postgre.ts b/src/db/postgre.ts index 00476b8774..f65953ff3f 100644 --- a/src/db/postgre.ts +++ b/src/db/postgre.ts @@ -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', diff --git a/test/chart.ts b/test/chart.ts index 931a5b2f0b..075e6cb46f 100644 --- a/test/chart.ts +++ b/test/chart.ts @@ -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();