Skip to content

Commit

Permalink
fix: add missing events
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Nov 14, 2024
1 parent 6aa21ad commit c60cc6a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { type ConnectionPoolClient } from '../factories/createConnectionPool';
import { createPool } from '../factories/createPool';
import { type ClientConfigurationInput } from '../types';
import EventEmitter from 'node:events';
import * as sinon from 'sinon';

export const createPoolWithMockedQuery = async (
Expand Down Expand Up @@ -28,7 +29,12 @@ export const createPoolWithMockedQuery = async (
// We are re-using the same connection for all queries
// as it makes it easier to spy on the connection.
// eslint-disable-next-line require-atomic-updates
connection = await driver.createClient();
connection = await driver.createClient().then((nextConnection) => {
return {
...nextConnection,
events: new EventEmitter(),
};
});

// eslint-disable-next-line require-atomic-updates
connection.query = query;
Expand Down
8 changes: 7 additions & 1 deletion packages/slonik/src/helpers.test/createPoolWithSpy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { type ConnectionPoolClient } from '../factories/createConnectionPool';
import { createPool } from '../factories/createPool';
import { type ClientConfigurationInput } from '../types';
import EventEmitter from 'node:events';
import * as sinon from 'sinon';

export const createPoolWithSpy = async (
Expand Down Expand Up @@ -33,7 +34,12 @@ export const createPoolWithSpy = async (
// We are re-using the same connection for all queries
// as it makes it easier to spy on the connection.
// eslint-disable-next-line require-atomic-updates
connection = await driver.createClient();
connection = await driver.createClient().then((nextConnection) => {
return {
...nextConnection,
events: new EventEmitter(),
};
});

spy.acquire = sinon.spy(connection, 'acquire');
spy.destroy = sinon.spy(connection, 'destroy');
Expand Down

0 comments on commit c60cc6a

Please sign in to comment.