1+ // @ts -check
12const pg = require ( "pg" ) ;
23const { readFile } = require ( "fs" ) ;
3- const pgConnectionString = require ( "pg-connection-string" ) ;
44
55// This test suite can be flaky. Increase it’s timeout.
66jest . setTimeout ( 1000 * 20 ) ;
@@ -19,7 +19,7 @@ const withPgClient = async (url, fn) => {
1919 fn = url ;
2020 url = process . env . TEST_DATABASE_URL ;
2121 }
22- const pgPool = new pg . Pool ( pgConnectionString . parse ( url ) ) ;
22+ const pgPool = new pg . Pool ( { connectionString : url } ) ;
2323 let client ;
2424 try {
2525 client = await pgPool . connect ( ) ;
@@ -51,7 +51,8 @@ const withDbFromUrl = async (url, fn) => {
5151
5252const withRootDb = ( fn ) => withDbFromUrl ( process . env . TEST_DATABASE_URL , fn ) ;
5353
54- let prepopulatedDBKeepalive ;
54+ /** @type {(Promise<void> & {resolve: () => void, reject: () => void, client: import('pg').PoolClient, vars: any}) | null } */
55+ let prepopulatedDBKeepalive = null ;
5556
5657const populateDatabase = async ( client ) => {
5758 await client . query ( await readFilePromise ( `${ __dirname } /p-data.sql` , "utf8" ) ) ;
@@ -89,14 +90,14 @@ withPrepopulatedDb.setup = (done) => {
8990 }
9091 let res ;
9192 let rej ;
92- prepopulatedDBKeepalive = new Promise ( ( resolve , reject ) => {
93- res = resolve ;
94- rej = reject ;
95- } ) ;
96- prepopulatedDBKeepalive . resolve = res ;
97- prepopulatedDBKeepalive . reject = rej ;
9893 withRootDb ( async ( client ) => {
99- prepopulatedDBKeepalive . client = client ;
94+ prepopulatedDBKeepalive = Object . assign (
95+ new Promise ( ( resolve , reject ) => {
96+ res = resolve ;
97+ rej = reject ;
98+ } ) ,
99+ { resolve : res , reject : rej , client, vars : undefined }
100+ ) ;
100101 try {
101102 prepopulatedDBKeepalive . vars = await populateDatabase ( client ) ;
102103 } catch ( e ) {
0 commit comments