Skip to content

Commit

Permalink
Filter out COMMIT query
Browse files Browse the repository at this point in the history
  • Loading branch information
emmatown committed Oct 27, 2022
1 parent 45aefdc commit 956ec8d
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions tests/api-tests/relationships/to-one-query-batching.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isDeepStrictEqual } from 'util';
import { list } from '@keystone-6/core';
import { allowAll } from '@keystone-6/core/access';
import { relationship, text } from '@keystone-6/core/fields';
Expand Down Expand Up @@ -37,10 +38,7 @@ test(
'to-one relationship query batching',
runner(async ({ context }) => {
let prevConsoleLog = console.log;
let logs: unknown[][] = [];
console.log = (...args) => {
logs.push(args.map(x => (typeof x === 'string' ? stripAnsi(x) : x)));
};
console.log = () => {};
try {
await context.query.User.createMany({
data: Array.from({ length: 10 }, (_, i) => ({
Expand All @@ -50,8 +48,16 @@ test(
},
})),
});
logs = [];
} finally {
console.log = prevConsoleLog;
}

let logs: unknown[][] = [];
console.log = (...args) => {
logs.push(args.map(x => (typeof x === 'string' ? stripAnsi(x) : x)));
};

try {
expect(
await context.query.Post.findMany({
query: 'title author { name }',
Expand All @@ -63,6 +69,16 @@ test(
author: { name: `User ${i}` },
}))
);

// the logs from the createMany are sometimes (it only seems to happen on postgres on ci)
// logged after the createMany resolves
// so we just ignore those queries (they always end in with a `COMMIT`)
const indexOfCommitLog = logs.findIndex(value =>
isDeepStrictEqual(value, ['prisma:query', 'COMMIT'])
);
if (indexOfCommitLog !== -1) {
logs = logs.slice(indexOfCommitLog + 1);
}
expect(logs).toEqual([
['prisma:query', expect.stringContaining('SELECT')],
['prisma:query', expect.stringContaining('SELECT')],
Expand Down

0 comments on commit 956ec8d

Please sign in to comment.