Skip to content

Commit

Permalink
feat: generate the db url based on the .env DATABASE_URL, by manipula…
Browse files Browse the repository at this point in the history
…ting the path + schema param
  • Loading branch information
isaiahgrey93 committed Aug 20, 2020
1 parent ea6d8fb commit 2a1c40b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions template/tests/jest.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2a1c40b

Please sign in to comment.