Skip to content

Commit 9d7518a

Browse files
committed
fix: test failing to exit
1 parent cc344a8 commit 9d7518a

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

src/tests/faucet-btc-tests.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from '../btc-faucet';
1111
import { ApiServer, startApiServer } from '../api/init';
1212
import { ChainID } from '@stacks/transactions';
13-
import { cycleMigrations, PgDataStore } from '../datastore/postgres-store';
13+
import { cycleMigrations, PgDataStore, runMigrations } from '../datastore/postgres-store';
1414

1515
async function getBalanceWithWalletImport(address: string): Promise<number> {
1616
const client = getRpcClient();
@@ -102,11 +102,11 @@ describe('btc faucet', () => {
102102

103103
describe('faucet http API', () => {
104104
let apiServer: ApiServer;
105-
105+
let db: PgDataStore;
106106
beforeAll(async () => {
107107
process.env.PG_DATABASE = 'postgres';
108108
await cycleMigrations();
109-
const db = await PgDataStore.connect();
109+
db = await PgDataStore.connect();
110110
apiServer = await startApiServer({
111111
datastore: db,
112112
chainId: ChainID.Testnet,
@@ -144,6 +144,8 @@ describe('btc faucet', () => {
144144

145145
afterAll(async () => {
146146
await apiServer.terminate();
147+
await db?.close();
148+
await runMigrations(undefined, 'down');
147149
});
148150
});
149151
});

src/tests/setup.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default async (): Promise<void> => {
2828
},
2929
httpLogLevel: 'silly',
3030
});
31-
Object.assign(global, { server: server });
31+
Object.assign(global, { server: server, db: db });
3232
console.log('Waiting for RPC connection to core node..');
3333
await new StacksCoreRpcClient().waitForConnection(60000);
3434
console.log('Jest - setup done');

src/tests/teardown.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import * as isCI from 'is-ci';
2+
import { PgDataStore } from '../datastore/postgres-store';
23

34
// ts-unused-exports:disable-next-line
45
export default async (): Promise<void> => {
56
console.log('Jest - teardown..');
67
const eventSocketServer: import('net').Server = (global as any).server;
7-
await new Promise<void>(resolve => {
8-
eventSocketServer.close(() => {
9-
console.log('Jest - teardown done');
10-
resolve();
11-
});
8+
const database: PgDataStore = (global as any).db;
9+
await new Promise<void>(async resolve => {
10+
eventSocketServer.close();
11+
await database.close();
12+
console.log('Jest - teardown done');
13+
resolve();
1214
});
1315

1416
// If running in CI setup the "why am I still running?" log to detect stuck Jest tests

0 commit comments

Comments
 (0)