@tanstack/react-query-devtools 5.0.0-alpha.2 → 5.0.0-alpha.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/lib/CachePanel/ActiveQuery.d.ts +18 -0
- package/build/lib/CachePanel/ActiveQuery.esm.js +271 -0
- package/build/lib/CachePanel/ActiveQuery.esm.js.map +1 -0
- package/build/lib/CachePanel/ActiveQuery.js +275 -0
- package/build/lib/CachePanel/ActiveQuery.js.map +1 -0
- package/build/lib/CachePanel/ActiveQuery.mjs +257 -0
- package/build/lib/CachePanel/ActiveQuery.mjs.map +1 -0
- package/build/lib/CachePanel/CachePanel.d.ts +57 -0
- package/build/lib/CachePanel/CachePanel.esm.js +310 -0
- package/build/lib/CachePanel/CachePanel.esm.js.map +1 -0
- package/build/lib/CachePanel/CachePanel.js +315 -0
- package/build/lib/CachePanel/CachePanel.js.map +1 -0
- package/build/lib/CachePanel/CachePanel.mjs +310 -0
- package/build/lib/CachePanel/CachePanel.mjs.map +1 -0
- package/build/lib/CachePanel/Header/QueryStatusCount.d.ts +7 -0
- package/build/lib/CachePanel/Header/QueryStatusCount.esm.js +49 -0
- package/build/lib/CachePanel/Header/QueryStatusCount.esm.js.map +1 -0
- package/build/lib/CachePanel/Header/QueryStatusCount.js +53 -0
- package/build/lib/CachePanel/Header/QueryStatusCount.js.map +1 -0
- package/build/lib/CachePanel/Header/QueryStatusCount.mjs +49 -0
- package/build/lib/CachePanel/Header/QueryStatusCount.mjs.map +1 -0
- package/build/lib/CachePanel/QueryRow.d.ts +13 -0
- package/build/lib/CachePanel/QueryRow.esm.js +98 -0
- package/build/lib/CachePanel/QueryRow.esm.js.map +1 -0
- package/build/lib/CachePanel/QueryRow.js +102 -0
- package/build/lib/CachePanel/QueryRow.js.map +1 -0
- package/build/lib/CachePanel/QueryRow.mjs +82 -0
- package/build/lib/CachePanel/QueryRow.mjs.map +1 -0
- package/build/lib/Explorer.esm.js +2 -1
- package/build/lib/Explorer.esm.js.map +1 -1
- package/build/lib/Explorer.js +2 -1
- package/build/lib/Explorer.js.map +1 -1
- package/build/lib/Explorer.mjs +1 -0
- package/build/lib/Explorer.mjs.map +1 -1
- package/build/lib/devtools.d.ts +5 -48
- package/build/lib/devtools.esm.js +11 -550
- package/build/lib/devtools.esm.js.map +1 -1
- package/build/lib/devtools.js +12 -551
- package/build/lib/devtools.js.map +1 -1
- package/build/lib/devtools.mjs +7 -547
- package/build/lib/devtools.mjs.map +1 -1
- package/build/lib/index.esm.js +3 -1
- package/build/lib/index.esm.js.map +1 -1
- package/build/lib/index.js +3 -1
- package/build/lib/index.js.map +1 -1
- package/build/lib/index.mjs +3 -1
- package/build/lib/index.mjs.map +1 -1
- package/build/lib/index.prod.esm.js +821 -651
- package/build/lib/index.prod.esm.js.map +1 -1
- package/build/lib/index.prod.js +819 -650
- package/build/lib/index.prod.js.map +1 -1
- package/build/lib/index.prod.mjs +764 -625
- package/build/lib/index.prod.mjs.map +1 -1
- package/build/lib/styledComponents.d.ts +0 -1
- package/build/lib/styledComponents.esm.js +11 -1
- package/build/lib/styledComponents.esm.js.map +1 -1
- package/build/lib/styledComponents.js +11 -1
- package/build/lib/styledComponents.js.map +1 -1
- package/build/lib/styledComponents.mjs +11 -1
- package/build/lib/styledComponents.mjs.map +1 -1
- package/build/lib/theme.esm.js +1 -0
- package/build/lib/theme.esm.js.map +1 -1
- package/build/lib/theme.js +1 -0
- package/build/lib/theme.js.map +1 -1
- package/build/lib/theme.mjs +1 -0
- package/build/lib/theme.mjs.map +1 -1
- package/build/lib/types.d.ts +11 -0
- package/build/lib/useSubscribeToQueryCache.d.ts +3 -0
- package/build/lib/useSubscribeToQueryCache.esm.js +15 -0
- package/build/lib/useSubscribeToQueryCache.esm.js.map +1 -0
- package/build/lib/useSubscribeToQueryCache.js +19 -0
- package/build/lib/useSubscribeToQueryCache.js.map +1 -0
- package/build/lib/useSubscribeToQueryCache.mjs +15 -0
- package/build/lib/useSubscribeToQueryCache.mjs.map +1 -0
- package/build/umd/index.development.js +1667 -1529
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +4 -4
- package/src/CachePanel/ActiveQuery.tsx +380 -0
- package/src/CachePanel/CachePanel.tsx +439 -0
- package/src/CachePanel/Header/QueryStatusCount.tsx +93 -0
- package/src/CachePanel/QueryRow.tsx +125 -0
- package/src/__tests__/Explorer.test.tsx +3 -2
- package/src/__tests__/devtools.test.tsx +229 -9
- package/src/devtools.tsx +10 -865
- package/src/styledComponents.ts +19 -1
- package/src/types.ts +12 -0
- package/src/useSubscribeToQueryCache.ts +26 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from 'react'
|
|
2
2
|
import { fireEvent, screen, waitFor, act } from '@testing-library/react'
|
|
3
3
|
import '@testing-library/jest-dom'
|
|
4
|
-
import { useQuery } from '@tanstack/react-query'
|
|
4
|
+
import { useQuery, onlineManager } from '@tanstack/react-query'
|
|
5
5
|
import { defaultPanelSize, sortFns } from '../utils'
|
|
6
6
|
import {
|
|
7
7
|
getByTextContent,
|
|
@@ -9,18 +9,27 @@ import {
|
|
|
9
9
|
sleep,
|
|
10
10
|
createQueryClient,
|
|
11
11
|
} from './utils'
|
|
12
|
+
import { vi } from 'vitest'
|
|
13
|
+
import UserEvent from '@testing-library/user-event'
|
|
14
|
+
|
|
15
|
+
class CustomError extends Error {
|
|
16
|
+
constructor(message: string) {
|
|
17
|
+
super(message)
|
|
18
|
+
this.name = 'CustomError'
|
|
19
|
+
}
|
|
20
|
+
}
|
|
12
21
|
|
|
13
22
|
Object.defineProperty(window, 'matchMedia', {
|
|
14
23
|
writable: true,
|
|
15
|
-
value:
|
|
24
|
+
value: vi.fn().mockImplementation((query: string) => ({
|
|
16
25
|
matches: false,
|
|
17
26
|
media: query,
|
|
18
27
|
onchange: null,
|
|
19
|
-
addListener:
|
|
20
|
-
removeListener:
|
|
21
|
-
addEventListener:
|
|
22
|
-
removeEventListener:
|
|
23
|
-
dispatchEvent:
|
|
28
|
+
addListener: vi.fn(), // deprecated
|
|
29
|
+
removeListener: vi.fn(), // deprecated
|
|
30
|
+
addEventListener: vi.fn(),
|
|
31
|
+
removeEventListener: vi.fn(),
|
|
32
|
+
dispatchEvent: vi.fn(),
|
|
24
33
|
})),
|
|
25
34
|
})
|
|
26
35
|
|
|
@@ -31,8 +40,8 @@ describe('ReactQueryDevtools', () => {
|
|
|
31
40
|
})
|
|
32
41
|
it('should be able to open and close devtools', async () => {
|
|
33
42
|
const { queryClient } = createQueryClient()
|
|
34
|
-
const onCloseClick =
|
|
35
|
-
const onToggleClick =
|
|
43
|
+
const onCloseClick = vi.fn()
|
|
44
|
+
const onToggleClick = vi.fn()
|
|
36
45
|
|
|
37
46
|
function Page() {
|
|
38
47
|
const { data = 'default' } = useQuery({
|
|
@@ -469,6 +478,31 @@ describe('ReactQueryDevtools', () => {
|
|
|
469
478
|
expect(count).toBe(2)
|
|
470
479
|
})
|
|
471
480
|
|
|
481
|
+
it('should inform onlineManager when offline mode is simulated', () => {
|
|
482
|
+
const { queryClient } = createQueryClient()
|
|
483
|
+
const online: Array<boolean> = []
|
|
484
|
+
|
|
485
|
+
const unsubscribe = onlineManager.subscribe(() => {
|
|
486
|
+
online.push(onlineManager.isOnline())
|
|
487
|
+
})
|
|
488
|
+
|
|
489
|
+
renderWithClient(queryClient, <div />, {
|
|
490
|
+
initialIsOpen: true,
|
|
491
|
+
})
|
|
492
|
+
|
|
493
|
+
fireEvent.click(
|
|
494
|
+
screen.getByRole('button', { name: /mock offline behavior/i }),
|
|
495
|
+
)
|
|
496
|
+
|
|
497
|
+
fireEvent.click(
|
|
498
|
+
screen.getByRole('button', { name: /restore offline mock/i }),
|
|
499
|
+
)
|
|
500
|
+
|
|
501
|
+
expect(online).toStrictEqual([false, true])
|
|
502
|
+
|
|
503
|
+
unsubscribe()
|
|
504
|
+
})
|
|
505
|
+
|
|
472
506
|
it('should sort the queries according to the sorting filter', async () => {
|
|
473
507
|
const { queryClient, queryCache } = createQueryClient()
|
|
474
508
|
|
|
@@ -683,6 +717,52 @@ describe('ReactQueryDevtools', () => {
|
|
|
683
717
|
expect(filterInput.value).toEqual('posts')
|
|
684
718
|
})
|
|
685
719
|
|
|
720
|
+
it('should not show queries after clear', async () => {
|
|
721
|
+
const { queryClient, queryCache } = createQueryClient()
|
|
722
|
+
|
|
723
|
+
function Page() {
|
|
724
|
+
const query1Result = useQuery({
|
|
725
|
+
queryKey: ['query-1'],
|
|
726
|
+
queryFn: async () => {
|
|
727
|
+
return 'query-1-result'
|
|
728
|
+
},
|
|
729
|
+
})
|
|
730
|
+
const query2Result = useQuery({
|
|
731
|
+
queryKey: ['query-2'],
|
|
732
|
+
queryFn: async () => {
|
|
733
|
+
return 'query-2-result'
|
|
734
|
+
},
|
|
735
|
+
})
|
|
736
|
+
const query3Result = useQuery({
|
|
737
|
+
queryKey: ['query-3'],
|
|
738
|
+
queryFn: async () => {
|
|
739
|
+
return 'query-3-result'
|
|
740
|
+
},
|
|
741
|
+
})
|
|
742
|
+
|
|
743
|
+
return (
|
|
744
|
+
<div>
|
|
745
|
+
<h1>
|
|
746
|
+
{query1Result.data} {query2Result.data} {query3Result.data}{' '}
|
|
747
|
+
</h1>
|
|
748
|
+
</div>
|
|
749
|
+
)
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
renderWithClient(queryClient, <Page />)
|
|
753
|
+
|
|
754
|
+
fireEvent.click(
|
|
755
|
+
screen.getByRole('button', { name: /open react query devtools/i }),
|
|
756
|
+
)
|
|
757
|
+
|
|
758
|
+
expect(queryCache.getAll()).toHaveLength(3)
|
|
759
|
+
|
|
760
|
+
const clearButton = screen.getByLabelText(/clear/i)
|
|
761
|
+
fireEvent.click(clearButton)
|
|
762
|
+
|
|
763
|
+
expect(queryCache.getAll()).toHaveLength(0)
|
|
764
|
+
})
|
|
765
|
+
|
|
686
766
|
it('style should have a nonce', async () => {
|
|
687
767
|
const { queryClient } = createQueryClient()
|
|
688
768
|
|
|
@@ -861,4 +941,144 @@ describe('ReactQueryDevtools', () => {
|
|
|
861
941
|
fireEvent.click(screen.getByRole('button', { name: /^close$/i }))
|
|
862
942
|
expect(parentElement).toHaveStyle(parentPaddings)
|
|
863
943
|
})
|
|
944
|
+
|
|
945
|
+
it('should simulate loading state', async () => {
|
|
946
|
+
const { queryClient } = createQueryClient()
|
|
947
|
+
let count = 0
|
|
948
|
+
function App() {
|
|
949
|
+
const { data, fetchStatus } = useQuery({
|
|
950
|
+
queryKey: ['key'],
|
|
951
|
+
queryFn: () => {
|
|
952
|
+
count++
|
|
953
|
+
return Promise.resolve('test')
|
|
954
|
+
},
|
|
955
|
+
})
|
|
956
|
+
|
|
957
|
+
return (
|
|
958
|
+
<div>
|
|
959
|
+
<h1>
|
|
960
|
+
{data ?? 'No data'}, {fetchStatus}
|
|
961
|
+
</h1>
|
|
962
|
+
</div>
|
|
963
|
+
)
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
renderWithClient(queryClient, <App />, {
|
|
967
|
+
initialIsOpen: true,
|
|
968
|
+
})
|
|
969
|
+
|
|
970
|
+
await screen.findByRole('heading', { name: /test/i })
|
|
971
|
+
|
|
972
|
+
const loadingButton = await screen.findByRole('button', {
|
|
973
|
+
name: 'Trigger loading',
|
|
974
|
+
})
|
|
975
|
+
fireEvent.click(loadingButton)
|
|
976
|
+
|
|
977
|
+
await waitFor(() => {
|
|
978
|
+
expect(screen.getByText('Restore loading')).toBeInTheDocument()
|
|
979
|
+
})
|
|
980
|
+
|
|
981
|
+
await waitFor(() => {
|
|
982
|
+
expect(screen.getByText('No data, fetching')).toBeInTheDocument()
|
|
983
|
+
})
|
|
984
|
+
|
|
985
|
+
fireEvent.click(screen.getByRole('button', { name: /restore loading/i }))
|
|
986
|
+
|
|
987
|
+
await waitFor(() => {
|
|
988
|
+
expect(screen.getByText('test, idle')).toBeInTheDocument()
|
|
989
|
+
})
|
|
990
|
+
|
|
991
|
+
expect(count).toBe(2)
|
|
992
|
+
})
|
|
993
|
+
|
|
994
|
+
it('should simulate error state', async () => {
|
|
995
|
+
const { queryClient } = createQueryClient()
|
|
996
|
+
function App() {
|
|
997
|
+
const { status, error } = useQuery({
|
|
998
|
+
queryKey: ['key'],
|
|
999
|
+
queryFn: () => {
|
|
1000
|
+
return Promise.resolve('test')
|
|
1001
|
+
},
|
|
1002
|
+
})
|
|
1003
|
+
|
|
1004
|
+
return (
|
|
1005
|
+
<div>
|
|
1006
|
+
<h1>
|
|
1007
|
+
{!!error ? 'Some error' : 'No error'}, {status}
|
|
1008
|
+
</h1>
|
|
1009
|
+
</div>
|
|
1010
|
+
)
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
renderWithClient(queryClient, <App />, {
|
|
1014
|
+
initialIsOpen: true,
|
|
1015
|
+
})
|
|
1016
|
+
|
|
1017
|
+
const errorButton = await screen.findByRole('button', {
|
|
1018
|
+
name: 'Trigger error',
|
|
1019
|
+
})
|
|
1020
|
+
fireEvent.click(errorButton)
|
|
1021
|
+
|
|
1022
|
+
await waitFor(() => {
|
|
1023
|
+
expect(screen.getByText('Restore error')).toBeInTheDocument()
|
|
1024
|
+
})
|
|
1025
|
+
|
|
1026
|
+
await waitFor(() => {
|
|
1027
|
+
expect(screen.getByText('Some error, error')).toBeInTheDocument()
|
|
1028
|
+
})
|
|
1029
|
+
|
|
1030
|
+
fireEvent.click(screen.getByRole('button', { name: /Restore error/i }))
|
|
1031
|
+
|
|
1032
|
+
await waitFor(() => {
|
|
1033
|
+
expect(screen.getByText('No error, success')).toBeInTheDocument()
|
|
1034
|
+
})
|
|
1035
|
+
})
|
|
1036
|
+
|
|
1037
|
+
it('should can simulate a specific error', async () => {
|
|
1038
|
+
const { queryClient } = createQueryClient()
|
|
1039
|
+
|
|
1040
|
+
function App() {
|
|
1041
|
+
const { status, error } = useQuery({
|
|
1042
|
+
queryKey: ['key'],
|
|
1043
|
+
queryFn: () => {
|
|
1044
|
+
return Promise.resolve('test')
|
|
1045
|
+
},
|
|
1046
|
+
})
|
|
1047
|
+
|
|
1048
|
+
return (
|
|
1049
|
+
<div data-testid="test">
|
|
1050
|
+
<h1>
|
|
1051
|
+
{error instanceof CustomError
|
|
1052
|
+
? error.message.toString()
|
|
1053
|
+
: 'No error'}
|
|
1054
|
+
, {status}
|
|
1055
|
+
</h1>
|
|
1056
|
+
</div>
|
|
1057
|
+
)
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
renderWithClient(queryClient, <App />, {
|
|
1061
|
+
initialIsOpen: true,
|
|
1062
|
+
errorTypes: [
|
|
1063
|
+
{
|
|
1064
|
+
name: 'error1',
|
|
1065
|
+
initializer: () => new CustomError('error1'),
|
|
1066
|
+
},
|
|
1067
|
+
],
|
|
1068
|
+
})
|
|
1069
|
+
|
|
1070
|
+
const errorOption = await screen.findByLabelText('Trigger error:')
|
|
1071
|
+
|
|
1072
|
+
UserEvent.selectOptions(errorOption, 'error1')
|
|
1073
|
+
|
|
1074
|
+
await waitFor(() => {
|
|
1075
|
+
expect(screen.getByText('error1, error')).toBeInTheDocument()
|
|
1076
|
+
})
|
|
1077
|
+
|
|
1078
|
+
fireEvent.click(screen.getByRole('button', { name: /Restore error/i }))
|
|
1079
|
+
|
|
1080
|
+
await waitFor(() => {
|
|
1081
|
+
expect(screen.getByText('No error, success')).toBeInTheDocument()
|
|
1082
|
+
})
|
|
1083
|
+
})
|
|
864
1084
|
})
|