@wordpress/preferences-persistence 2.54.1-next.v.202608281122.0 → 2.54.1-next.v.202609031004.0
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 +6 -3
- package/src/create/test/debounce-async.js +61 -68
- package/src/migrations/legacy-local-storage-data/test/convert-edit-post-panels.js +1 -0
- package/src/migrations/legacy-local-storage-data/test/index.js +1 -0
- package/src/migrations/legacy-local-storage-data/test/move-feature-preferences.js +1 -0
- package/src/migrations/legacy-local-storage-data/test/move-individual-preference.js +1 -0
- package/src/migrations/legacy-local-storage-data/test/move-interface-enable-items.js +1 -0
- package/src/migrations/legacy-local-storage-data/test/move-third-party-feature-preferences.js +1 -0
- package/src/migrations/preferences-package-data/test/convert-complementary-areas.js +1 -0
- package/src/migrations/preferences-package-data/test/convert-editor-settings.js +1 -0
- package/src/migrations/preferences-package-data/test/index.js +1 -0
- /package/src/create/test/{index.js → index.jsdom.test.js} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/preferences-persistence",
|
|
3
|
-
"version": "2.54.1-next.v.
|
|
3
|
+
"version": "2.54.1-next.v.202609031004.0",
|
|
4
4
|
"description": "Persistence utilities for `wordpress/preferences`.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -43,10 +43,13 @@
|
|
|
43
43
|
"wpScript": true,
|
|
44
44
|
"sideEffects": false,
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@wordpress/api-fetch": "^7.54.1-next.v.
|
|
46
|
+
"@wordpress/api-fetch": "^7.54.1-next.v.202609031004.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"vitest": "^4.1.10"
|
|
47
50
|
},
|
|
48
51
|
"publishConfig": {
|
|
49
52
|
"access": "public"
|
|
50
53
|
},
|
|
51
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "7275d6c6d93b542fca3cd98cdb9c7344ddd11e19"
|
|
52
55
|
}
|
|
@@ -1,84 +1,87 @@
|
|
|
1
|
+
import { setImmediate as setImmediateCallback } from 'node:timers';
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
1
3
|
import debounceAsync from '../debounce-async';
|
|
2
4
|
|
|
3
|
-
//
|
|
4
|
-
// Jest fake timers and async functions don't mix too well, since queued up
|
|
5
|
-
// promises can prevent jest from calling timeouts.
|
|
6
|
-
// This function flushes promises in the queue.
|
|
5
|
+
// Let promise callbacks settle without advancing the faked timeout clock.
|
|
7
6
|
function flushPromises() {
|
|
8
|
-
return new Promise(
|
|
7
|
+
return new Promise( setImmediateCallback );
|
|
9
8
|
}
|
|
10
9
|
|
|
11
|
-
// Promisify a timeout for use with
|
|
10
|
+
// Promisify a timeout for use with vi.fn.
|
|
12
11
|
function timeout( milliseconds ) {
|
|
13
12
|
return new Promise( ( resolve ) => setTimeout( resolve, milliseconds ) );
|
|
14
13
|
}
|
|
15
14
|
|
|
16
15
|
describe( 'debounceAsync', () => {
|
|
17
16
|
it( 'uses a leading debounce, the first call happens immediately', () => {
|
|
18
|
-
const fn =
|
|
17
|
+
const fn = vi.fn( async () => {} );
|
|
19
18
|
const debounced = debounceAsync( fn, 20 );
|
|
20
19
|
debounced();
|
|
21
20
|
expect( fn ).toHaveBeenCalledTimes( 1 );
|
|
22
21
|
} );
|
|
23
22
|
|
|
24
23
|
it( 'calls the function on the leading edge and then once on the trailing edge when there are multiple calls', async () => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
debounced( 'A' );
|
|
24
|
+
vi.useFakeTimers( { toFake: [ 'setTimeout', 'clearTimeout' ] } );
|
|
25
|
+
try {
|
|
26
|
+
const fn = vi.fn( async () => {} );
|
|
27
|
+
const debounced = debounceAsync( fn, 20 );
|
|
30
28
|
|
|
31
|
-
|
|
29
|
+
debounced( 'A' );
|
|
32
30
|
|
|
33
|
-
|
|
34
|
-
debounced( 'C' );
|
|
35
|
-
debounced( 'D' );
|
|
31
|
+
expect( fn ).toHaveBeenCalledTimes( 1 );
|
|
36
32
|
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
debounced( 'B' );
|
|
34
|
+
debounced( 'C' );
|
|
35
|
+
debounced( 'D' );
|
|
39
36
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
expect( fn ).toHaveBeenCalledWith( 'D' );
|
|
37
|
+
await flushPromises();
|
|
38
|
+
vi.runAllTimers();
|
|
43
39
|
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
expect( fn ).toHaveBeenCalledTimes( 2 );
|
|
41
|
+
expect( fn ).toHaveBeenCalledWith( 'A' );
|
|
42
|
+
expect( fn ).toHaveBeenCalledWith( 'D' );
|
|
43
|
+
} finally {
|
|
44
|
+
vi.clearAllTimers();
|
|
45
|
+
vi.useRealTimers();
|
|
46
|
+
}
|
|
46
47
|
} );
|
|
47
48
|
|
|
48
49
|
it( 'ensures the delay has elapsed between calls', async () => {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
50
|
+
vi.useFakeTimers( { toFake: [ 'setTimeout', 'clearTimeout' ] } );
|
|
51
|
+
try {
|
|
52
|
+
const fn = vi.fn( async () => timeout( 10 ) );
|
|
53
|
+
const debounced = debounceAsync( fn, 20 );
|
|
54
|
+
|
|
55
|
+
// The first call has been triggered, but will take 10ms to resolve.
|
|
56
|
+
debounced();
|
|
57
|
+
debounced();
|
|
58
|
+
debounced();
|
|
59
|
+
debounced();
|
|
60
|
+
expect( fn ).toHaveBeenCalledTimes( 1 );
|
|
61
|
+
|
|
62
|
+
// The first call has resolved. The delay period has started but has yet to finish.
|
|
63
|
+
await flushPromises();
|
|
64
|
+
vi.advanceTimersByTime( 11 );
|
|
65
|
+
expect( fn ).toHaveBeenCalledTimes( 1 );
|
|
66
|
+
|
|
67
|
+
// The second call is about to commence, but hasn't yet.
|
|
68
|
+
await flushPromises();
|
|
69
|
+
vi.advanceTimersByTime( 18 );
|
|
70
|
+
expect( fn ).toHaveBeenCalledTimes( 1 );
|
|
71
|
+
|
|
72
|
+
// The second call has now commenced.
|
|
73
|
+
await flushPromises();
|
|
74
|
+
vi.advanceTimersByTime( 2 );
|
|
75
|
+
expect( fn ).toHaveBeenCalledTimes( 2 );
|
|
76
|
+
|
|
77
|
+
// No more calls happen.
|
|
78
|
+
await flushPromises();
|
|
79
|
+
vi.runAllTimers();
|
|
80
|
+
expect( fn ).toHaveBeenCalledTimes( 2 );
|
|
81
|
+
} finally {
|
|
82
|
+
vi.clearAllTimers();
|
|
83
|
+
vi.useRealTimers();
|
|
84
|
+
}
|
|
82
85
|
} );
|
|
83
86
|
|
|
84
87
|
it( 'is thenable, returning any data from promise resolution of the debounced function', async () => {
|
|
@@ -105,21 +108,11 @@ describe( 'debounceAsync', () => {
|
|
|
105
108
|
|
|
106
109
|
const debounced = debounceAsync( fn, 20 );
|
|
107
110
|
|
|
108
|
-
// Test
|
|
109
|
-
|
|
110
|
-
await debounced();
|
|
111
|
-
} catch ( error ) {
|
|
112
|
-
// Disable reason - the test uses `expect.assertions` to ensure
|
|
113
|
-
// conditional assertions are called.
|
|
114
|
-
// eslint-disable-next-line jest/no-conditional-expect
|
|
115
|
-
expect( error ).toBe( expectedError );
|
|
116
|
-
}
|
|
111
|
+
// Test awaiting a rejection.
|
|
112
|
+
await expect( debounced() ).rejects.toBe( expectedError );
|
|
117
113
|
|
|
118
114
|
// Test chained .catch().
|
|
119
115
|
await debounced().catch( ( error ) => {
|
|
120
|
-
// Disable reason - the test uses `expect.assertions` to ensure
|
|
121
|
-
// conditional assertions are called.
|
|
122
|
-
// eslint-disable-next-line jest/no-conditional-expect
|
|
123
116
|
expect( error ).toBe( expectedError );
|
|
124
117
|
} );
|
|
125
118
|
} );
|
|
File without changes
|