Skip to content

Commit 00cc671

Browse files
Dilukaclaude
andcommitted
refactor(query-graphql): improve console.log mock implementation in integration tests
- Replace global console.log override with jest.spyOn() for safer mocking - Use mockRestore() instead of manual restoration for better cleanup - Remove unnecessary originalLog variable declaration - Keep optional debug output comment for development flexibility This addresses the code review feedback about avoiding global console.log override which could interfere with test output and debugging while following Jest best practices. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 5888637 commit 00cc671

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

packages/query-graphql/__tests__/integration/federation-n1/federation-n1-integration.spec.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ describe('Federation N+1 Integration Test (Based on User Demo)', () => {
1919
let dataSource: DataSource
2020
let queryCount: number
2121
let executedQueries: string[]
22-
let originalLog: any
2322

2423
beforeAll(async () => {
2524
// Setup query monitoring to track SQL execution
@@ -203,12 +202,11 @@ describe('Federation N+1 Integration Test (Based on User Demo)', () => {
203202

204203
// Capture console output to verify DataLoader logs
205204
const consoleLogs: string[] = []
206-
originalLog = console.log
207-
console.log = jest.fn((...args) => {
205+
const logSpy = jest.spyOn(console, 'log').mockImplementation((...args) => {
208206
const message = args.join(' ')
209207
consoleLogs.push(message)
210-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
211-
originalLog(...args)
208+
// Optionally, call the original implementation if you want logs to still appear:
209+
// jest.requireActual('console').log(...args)
212210
})
213211

214212
const query = `
@@ -223,7 +221,7 @@ describe('Federation N+1 Integration Test (Based on User Demo)', () => {
223221
await request(app.getHttpServer()).post('/graphql').send({ query }).expect(200)
224222

225223
// Restore console.log
226-
console.log = originalLog
224+
logSpy.mockRestore()
227225

228226
// Check for DataLoader debug logs (optional in test environment)
229227
const dataLoaderLogs = consoleLogs.filter((log) => log.includes('DataLoaderFactory') || log.includes('ReferenceLoader'))

0 commit comments

Comments
 (0)