Skip to content

Commit

Permalink
fix(logging): silence react-query logger by default
Browse files Browse the repository at this point in the history
  • Loading branch information
ismay committed Aug 9, 2021
1 parent db00a91 commit aa3dc1c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 31 deletions.
15 changes: 0 additions & 15 deletions services/data/src/__tests__/integration.test.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@
import { render, waitFor } from '@testing-library/react'
import React, { ReactNode } from 'react'
import { setLogger } from 'react-query'
import { CustomDataProvider, DataQuery } from '../react'
import { QueryRenderInput } from '../types'

beforeAll(() => {
// Prevent the react-query logger from logging to the console
setLogger({
log: jest.fn(),
warn: jest.fn(),
error: jest.fn(),
})
})

afterAll(() => {
// Restore the original react-query logger
setLogger(console)
})

describe('Testing custom data provider and useQuery hook', () => {
it('Should render without failing', async () => {
const data = {
Expand Down
15 changes: 0 additions & 15 deletions services/data/src/react/hooks/useDataQuery.test.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@
import { renderHook, act } from '@testing-library/react-hooks'
import React from 'react'
import { setLogger } from 'react-query'
import { CustomDataProvider } from '../components/CustomDataProvider'
import { useDataQuery } from './useDataQuery'

beforeAll(() => {
// Prevent the react-query logger from logging to the console
setLogger({
log: jest.fn(),
warn: jest.fn(),
error: jest.fn(),
})
})

afterAll(() => {
// Restore the original react-query logger
setLogger(console)
})

describe('useDataQuery', () => {
describe('parameters: onComplete', () => {
it('Should call onComplete with the data after a successful fetch', async () => {
Expand Down
16 changes: 15 additions & 1 deletion services/data/src/react/hooks/useDataQuery.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
import { useState, useRef } from 'react'
import { useQuery } from 'react-query'
import { useQuery, setLogger } from 'react-query'
import { Query, QueryOptions } from '../../engine'
import { FetchError } from '../../engine/types/FetchError'
import { QueryRenderInput, QueryRefetchFunction } from '../../types'
import { useDataEngine } from './useDataEngine'
import { useStaticInput } from './useStaticInput'

const noop = () => {
/**
* Used to silence the default react-query logger. Eventually we
* could expose the setLogger functionality and remove the call
* to setLogger here.
*/
}

setLogger({
log: noop,
warn: noop,
error: noop,
})

export const useDataQuery = (
query: Query,
{
Expand Down

0 comments on commit aa3dc1c

Please sign in to comment.