Skip to content

Commit

Permalink
Fix things
Browse files Browse the repository at this point in the history
  • Loading branch information
emmatown committed Oct 27, 2022
1 parent 862c3aa commit 6205e18
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions tests/api-tests/relationships/to-one-query-batching.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,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 @@ -51,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 @@ -64,12 +69,15 @@ test(
author: { name: `User ${i}` },
}))
);
console.error(logs);
// sometimes on ci, there's an COMMIT query that happens.
// it seems harmless and since it inconsistently happens
// we just filter it out rather than expecting it
if (dbProvider === 'postgresql') {
logs = logs.filter(log => !isDeepStrictEqual(['prisma:query', 'COMMIT'], log));

// 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 end with `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')],
Expand Down

0 comments on commit 6205e18

Please sign in to comment.