Repository: tannerlinsley/react-query
Pull request #2904 (2021-11-08 20:26:03)

test(core):  100% code coverage
Finally. 

<img width="724" alt="Screenshot 2021-11-08 at 21 22 10" src="https://user-images.githubusercontent.com/20332397/140812417-35285166-762d-403f-835c-a60de8a3a20c.png">
 
Impact on existing code:
- `logger.ts`:  assume that `console` cannot be undefined at runtime

vercel[bot]: This pull request is being automatically deployed with Vercel ([learn more](https://vercel.link/github-learn-more)).  
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: [https://vercel.com/tanstack/react-query/A3z8cQVhmsDjm8fmJkWG1SwSjopL](https://vercel.com/tanstack/react-query/A3z8cQVhmsDjm8fmJkWG1SwSjopL)  
✅ Preview: *In Progress*


codesandbox[bot]: This pull request is automatically built and testable in [CodeSandbox](https://codesandbox.io).

  To see build info of the built libraries, click [here](https://ci.codesandbox.io/status/tannerlinsley/react-query/pr/2904/builds/186431) or the icon next to each commit SHA.

Latest deployment of this branch, based on commit eac9ff9927ca63c646812610e7355047af4039fd:

|Sandbox| Source |
|--|--|
|[tannerlinsley/react-query: basic](https://codesandbox.io/s/tannerlinsley-react-query-basic-xtg4z)| Configuration |
|[tannerlinsley/react-query: basic-typescript](https://codesandbox.io/s/tannerlinsley-react-query-basic-typescript-fkebg)| Configuration |

codecov[bot]: # [Codecov](https://codecov.io/gh/tannerlinsley/react-query/pull/2904?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tanner+Linsley) Report
> Merging [#2904](https://codecov.io/gh/tannerlinsley/react-query/pull/2904?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tanner+Linsley) (eac9ff9) into [master](https://codecov.io/gh/tannerlinsley/react-query/commit/c917ff7210719495fdb00782ebbfb08552ac3b0c?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tanner+Linsley) (c917ff7) will **increase** coverage by `0.13%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/tannerlinsley/react-query/pull/2904/graphs/tree.svg?width=650&height=150&src=pr&token=jqEbswkEDQ&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tanner+Linsley)](https://codecov.io/gh/tannerlinsley/react-query/pull/2904?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tanner+Linsley)

```diff
@@            Coverage Diff             @@
##           master    #2904      +/-   ##
==========================================
+ Coverage   96.27%   96.40%   +0.13%     
==========================================
  Files          45       45              
  Lines        2226     2226              
  Branches      637      636       -1     
==========================================
+ Hits         2143     2146       +3     
+ Misses         80       77       -3     
  Partials        3        3              
```


| [Impacted Files](https://codecov.io/gh/tannerlinsley/react-query/pull/2904?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tanner+Linsley) | Coverage Δ | |
|---|---|---|
| [src/core/logger.ts](https://codecov.io/gh/tannerlinsley/react-query/pull/2904/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tanner+Linsley#diff-c3JjL2NvcmUvbG9nZ2VyLnRz) | `100.00% <100.00%> (ø)` | |
| [src/core/utils.ts](https://codecov.io/gh/tannerlinsley/react-query/pull/2904/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tanner+Linsley#diff-c3JjL2NvcmUvdXRpbHMudHM=) | `100.00% <0.00%> (+1.79%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/tannerlinsley/react-query/pull/2904?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tanner+Linsley).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tanner+Linsley)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/tannerlinsley/react-query/pull/2904?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tanner+Linsley). Last update [c917ff7...eac9ff9](https://codecov.io/gh/tannerlinsley/react-query/pull/2904?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tanner+Linsley). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tanner+Linsley).


Patch:
diff --git a/src/core/logger.ts b/src/core/logger.ts
index 4d459e70e..eb33ebc98 100644
--- a/src/core/logger.ts
+++ b/src/core/logger.ts
@@ -1,5 +1,3 @@
-import { noop } from './utils'
-
 // TYPES
 
 export interface Logger {
@@ -12,11 +10,7 @@ type LogFunction = (...args: any[]) => void
 
 // FUNCTIONS
 
-let logger: Logger = console || {
-  error: noop,
-  warn: noop,
-  log: noop,
-}
+let logger: Logger = console
 
 export function getLogger(): Logger {
   return logger


Test patch:
diff --git a/src/core/tests/utils.test.tsx b/src/core/tests/utils.test.tsx
index 65bc117bd..e23721527 100644
--- a/src/core/tests/utils.test.tsx
+++ b/src/core/tests/utils.test.tsx
@@ -5,10 +5,12 @@ import {
   mapQueryStatusFilter,
   parseMutationArgs,
   matchMutation,
+  scheduleMicrotask,
 } from '../utils'
 import { QueryClient, QueryCache, setLogger, Logger } from '../..'
 import { queryKey } from '../../react/tests/utils'
 import { Mutation } from '../mutation'
+import { waitFor } from '@testing-library/dom'
 
 describe('core/utils', () => {
   it('setLogger should override the default logger', async () => {
@@ -70,6 +72,19 @@ describe('core/utils', () => {
       }
       expect(isPlainObject(new Foo())).toBeFalsy()
     })
+
+    it('should return `false` if the object has a modified prototype', () => {
+      function Graph(this: any) {
+        this.vertices = []
+        this.edges = []
+      }
+
+      Graph.prototype.addVertex = function (v: any) {
+        this.vertices.push(v)
+      }
+
+      expect(isPlainObject(Object.create(Graph))).toBeFalsy()
+    })
   })
 
   describe('partialDeepEqual', () => {
@@ -364,4 +379,35 @@ describe('core/utils', () => {
       expect(matchMutation(filters, mutation)).toBeFalsy()
     })
   })
+
+  describe('scheduleMicrotask', () => {
+    it('should throw an exception if the callback throw an error', async () => {
+      const error = new Error('error')
+      const callback = () => {
+        throw error
+      }
+      const errorSpy = jest.fn().mockImplementation(err => err)
+      jest.useFakeTimers()
+      const setTimeoutSpy = jest
+        .spyOn(globalThis, 'setTimeout')
+        .mockImplementation(function (handler: TimerHandler) {
+          try {
+            if (typeof handler === 'function') {
+              handler(errorSpy(error))
+            }
+          } catch (err: any) {
+            expect(err.message).toEqual('error')
+            // Do no throw an uncaught exception that cannot be tested with
+            // this jest version
+          }
+          return 0
+        })
+      scheduleMicrotask(callback)
+      jest.runAllTimers()
+      await waitFor(() => expect(setTimeoutSpy).toHaveBeenCalled())
+      expect(errorSpy).toHaveBeenCalled()
+      setTimeoutSpy.mockRestore()
+      jest.useRealTimers()
+    })
+  })
 })