@tanstack/query-async-storage-persister 5.4.3 → 5.8.1
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/query-async-storage-persister",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.8.1",
|
|
4
4
|
"description": "A persister for asynchronous storages, to be used with TanStack/Query",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"src"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@tanstack/query-persist-client-core": "5.
|
|
40
|
+
"@tanstack/query-persist-client-core": "5.8.1"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
43
|
"clean": "rimraf ./build && rimraf ./coverage",
|
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
import { describe, expect, test, vi } from 'vitest'
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
|
|
2
2
|
import { asyncThrottle } from '../asyncThrottle'
|
|
3
3
|
import { sleep as delay } from './utils'
|
|
4
4
|
|
|
5
5
|
describe('asyncThrottle', () => {
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
vi.useFakeTimers()
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
afterEach(() => {
|
|
11
|
+
vi.useRealTimers()
|
|
12
|
+
})
|
|
13
|
+
|
|
6
14
|
test('basic', async () => {
|
|
7
15
|
const interval = 10
|
|
8
16
|
const execTimeStamps: Array<number> = []
|
|
@@ -18,10 +26,15 @@ describe('asyncThrottle', () => {
|
|
|
18
26
|
const testFunc = asyncThrottle(mockFunc, { interval })
|
|
19
27
|
|
|
20
28
|
testFunc(1)
|
|
21
|
-
await
|
|
29
|
+
await vi.advanceTimersByTimeAsync(1)
|
|
30
|
+
|
|
22
31
|
testFunc(2)
|
|
23
|
-
await
|
|
24
|
-
|
|
32
|
+
await vi.advanceTimersByTimeAsync(1)
|
|
33
|
+
|
|
34
|
+
new Promise((resolve) => testFunc(3, resolve))
|
|
35
|
+
|
|
36
|
+
await vi.advanceTimersToNextTimerAsync()
|
|
37
|
+
await vi.advanceTimersByTimeAsync(interval)
|
|
25
38
|
|
|
26
39
|
expect(mockFunc).toBeCalledTimes(2)
|
|
27
40
|
expect(mockFunc.mock.calls[1]?.[0]).toBe(3)
|
|
@@ -47,10 +60,13 @@ describe('asyncThrottle', () => {
|
|
|
47
60
|
|
|
48
61
|
testFunc(1)
|
|
49
62
|
testFunc(2)
|
|
50
|
-
await
|
|
63
|
+
await vi.advanceTimersByTimeAsync(35)
|
|
51
64
|
testFunc(3)
|
|
52
|
-
await
|
|
53
|
-
|
|
65
|
+
await vi.advanceTimersByTimeAsync(35)
|
|
66
|
+
new Promise((resolve) => testFunc(4, resolve))
|
|
67
|
+
|
|
68
|
+
await vi.advanceTimersToNextTimerAsync()
|
|
69
|
+
await vi.advanceTimersByTimeAsync(interval)
|
|
54
70
|
|
|
55
71
|
expect(mockFunc).toBeCalledTimes(2)
|
|
56
72
|
expect(mockFunc.mock.calls[1]?.[0]).toBe(4)
|
|
@@ -76,7 +92,11 @@ describe('asyncThrottle', () => {
|
|
|
76
92
|
|
|
77
93
|
testFunc(1)
|
|
78
94
|
testFunc(2)
|
|
79
|
-
|
|
95
|
+
new Promise((resolve) => testFunc(3, resolve))
|
|
96
|
+
|
|
97
|
+
await vi.advanceTimersToNextTimerAsync()
|
|
98
|
+
await vi.advanceTimersByTimeAsync(interval + 10)
|
|
99
|
+
await vi.advanceTimersByTimeAsync(interval + 10)
|
|
80
100
|
|
|
81
101
|
expect(mockFunc).toBeCalledTimes(2)
|
|
82
102
|
expect(mockFunc.mock.calls[1]?.[0]).toBe(3)
|
|
@@ -87,6 +107,8 @@ describe('asyncThrottle', () => {
|
|
|
87
107
|
})
|
|
88
108
|
|
|
89
109
|
test('"func" throw error not break next invoke', async () => {
|
|
110
|
+
const interval = 10
|
|
111
|
+
|
|
90
112
|
const mockFunc = vi.fn(
|
|
91
113
|
async (id: number, complete?: (value?: unknown) => void) => {
|
|
92
114
|
if (id === 1) throw new Error('error')
|
|
@@ -96,11 +118,13 @@ describe('asyncThrottle', () => {
|
|
|
96
118
|
}
|
|
97
119
|
},
|
|
98
120
|
)
|
|
99
|
-
const testFunc = asyncThrottle(mockFunc, { interval
|
|
121
|
+
const testFunc = asyncThrottle(mockFunc, { interval })
|
|
100
122
|
|
|
101
123
|
testFunc(1)
|
|
102
|
-
await
|
|
103
|
-
|
|
124
|
+
await vi.advanceTimersByTimeAsync(1)
|
|
125
|
+
|
|
126
|
+
new Promise((resolve) => testFunc(2, resolve))
|
|
127
|
+
await vi.advanceTimersByTimeAsync(interval)
|
|
104
128
|
|
|
105
129
|
expect(mockFunc).toBeCalledTimes(2)
|
|
106
130
|
expect(mockFunc.mock.calls[1]?.[0]).toBe(2)
|