From 2a1c40baf1d665cc317c48f83b0d7af022801c33 Mon Sep 17 00:00:00 2001 From: Isaiah Grey Date: Thu, 20 Aug 2020 10:06:26 -0700 Subject: [PATCH] feat: generate the db url based on the .env DATABASE_URL, by manipulating the path + schema param --- template/tests/jest.setup.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/template/tests/jest.setup.js b/template/tests/jest.setup.js index 2f685c36..850d840f 100644 --- a/template/tests/jest.setup.js +++ b/template/tests/jest.setup.js @@ -13,9 +13,14 @@ module.exports = async () => { // isUp = await statusCheck(); // } // console.log(`[jest] server is up...`); + const testDatabaseName = 'testing'; + const testSchema = `test_${nanoid().toLowerCase()}`; + const testDatabaseUrl = new URL(process.env.DATABASE_URL); + testDatabaseUrl.pathname = `/${testDatabaseName}`; + testDatabaseUrl.searchParams.set('schema', testSchema); - global.schema = `test_${nanoid().toLowerCase()}`; - global.databaseUrl = `postgresql://postgres:postgres@localhost:5432/testing?schema=${this.schema}`; + global.schema = testSchema; + global.databaseUrl = testDatabaseUrl; process.env.DATABASE_URL = global.databaseUrl; global.process.env.DATABASE_URL = global.databaseUrl;