Skip to content

Error: Queue is Empty #61

@camfeghali

Description

@camfeghali

I'm running tests using jest, jest-postgres, to spin up a local postgres instance, and using ts-postgres to access that postgres instance.

Tests are failing with the following error:

    Cannot log after tests are done. Did you forget to wait for something async in your test?
    Attempted to log "ts-postgres: Error: Queue is empty".

      at console.warn (../../../node_modules/@jest/console/build/BufferedConsole.js:191:10)
      at log (../../../node_modules/ts-postgres/src/logging.ts:7:16)
      at Object.warn (../../../node_modules/ts-postgres/src/logging.ts:19:13)
      at Socket.<anonymous> (../../../node_modules/ts-postgres/src/client.ts:386:24)

This is the code that executes when making queries:

  async function connection() {
    if (!client || client.closed) {
      client = new Client(config);
      await client.connect();
      return client;
    }
    return client;
  }
  async function query<T>(query: string): Promise<T[]> {
    try {
      const conn = await connection();
      const queryResult = await conn.query(query);
      const { rows, names } = queryResult;
      return rows.map((row) => mapToObj<T>(row, names));
    }
  }

And this is how I use it

export async function get(props) {
    const { schema, tableName } = DB_CONFIG;
    const whereClause = buildWhereClause(props);
    const query = `SELECT * from ${schema}.${tableName} ${whereClause};`;
    const pgClient = postgresClient(DB_CONFIG);

    return await pgClient.query<RecommendableProduct>(query);
}

Am I missing something? Any help would be much appreciated!

Metadata

Metadata

Assignees

Labels

triageNeeds further information and analysis

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions