@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/preferences-persistence",
3
- "version": "2.54.1-next.v.202608281122.0",
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.202608281122.0"
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": "de479d415171765f7b573c81aeec5334ff506a12"
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
- // See https://stackoverflow.com/questions/52177631/jest-timer-and-promise-dont-work-well-settimeout-and-async-function.
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( jest.requireActual( 'timers' ).setImmediate );
7
+ return new Promise( setImmediateCallback );
9
8
  }
10
9
 
11
- // Promisify a timeout for use with jest.fn.
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 = jest.fn( async () => {} );
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
- jest.useFakeTimers();
26
- const fn = jest.fn( async () => {} );
27
- const debounced = debounceAsync( fn, 20 );
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
- expect( fn ).toHaveBeenCalledTimes( 1 );
29
+ debounced( 'A' );
32
30
 
33
- debounced( 'B' );
34
- debounced( 'C' );
35
- debounced( 'D' );
31
+ expect( fn ).toHaveBeenCalledTimes( 1 );
36
32
 
37
- await flushPromises();
38
- jest.runAllTimers();
33
+ debounced( 'B' );
34
+ debounced( 'C' );
35
+ debounced( 'D' );
39
36
 
40
- expect( fn ).toHaveBeenCalledTimes( 2 );
41
- expect( fn ).toHaveBeenCalledWith( 'A' );
42
- expect( fn ).toHaveBeenCalledWith( 'D' );
37
+ await flushPromises();
38
+ vi.runAllTimers();
43
39
 
44
- jest.runOnlyPendingTimers();
45
- jest.useRealTimers();
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
- jest.useFakeTimers();
50
- const fn = jest.fn( async () => timeout( 10 ) );
51
- const debounced = debounceAsync( fn, 20 );
52
-
53
- // The first call has been triggered, but will take 10ms to resolve.
54
- debounced();
55
- debounced();
56
- debounced();
57
- debounced();
58
- expect( fn ).toHaveBeenCalledTimes( 1 );
59
-
60
- // The first call has resolved. The delay period has started but has yet to finish.
61
- await flushPromises();
62
- jest.advanceTimersByTime( 11 );
63
- expect( fn ).toHaveBeenCalledTimes( 1 );
64
-
65
- // The second call is about to commence, but hasn't yet.
66
- await flushPromises();
67
- jest.advanceTimersByTime( 18 );
68
- expect( fn ).toHaveBeenCalledTimes( 1 );
69
-
70
- // The second call has now commenced.
71
- await flushPromises();
72
- jest.advanceTimersByTime( 2 );
73
- expect( fn ).toHaveBeenCalledTimes( 2 );
74
-
75
- // No more calls happen.
76
- await flushPromises();
77
- jest.runAllTimers();
78
- expect( fn ).toHaveBeenCalledTimes( 2 );
79
-
80
- jest.runOnlyPendingTimers();
81
- jest.useRealTimers();
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 traditional try/catch.
109
- try {
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
  } );
@@ -1,3 +1,4 @@
1
+ import { describe, expect, it } from 'vitest';
1
2
  import convertEditPostPanels from '../convert-edit-post-panels';
2
3
 
3
4
  describe( 'convertEditPostPanels', () => {
@@ -1,3 +1,4 @@
1
+ import { describe, expect, it } from 'vitest';
1
2
  import { convertLegacyData } from '..';
2
3
 
3
4
  const legacyData = {
@@ -1,3 +1,4 @@
1
+ import { describe, expect, it } from 'vitest';
1
2
  import moveFeaturePreferences from '../move-feature-preferences';
2
3
 
3
4
  describe( 'moveFeaturePreferences', () => {
@@ -1,3 +1,4 @@
1
+ import { describe, expect, it } from 'vitest';
1
2
  import moveIndividualPreference from '../move-individual-preference';
2
3
 
3
4
  describe( 'moveIndividualPreference', () => {
@@ -1,3 +1,4 @@
1
+ import { describe, expect, it } from 'vitest';
1
2
  import moveInterfaceEnableItems from '../move-interface-enable-items';
2
3
 
3
4
  describe( 'moveInterfaceEnableItems', () => {
@@ -1,3 +1,4 @@
1
+ import { describe, expect, it } from 'vitest';
1
2
  import moveThirdPartyFeaturePreferences from '../move-third-party-feature-preferences';
2
3
 
3
4
  describe( 'moveThirdPartyFeaturePreferences', () => {
@@ -1,3 +1,4 @@
1
+ import { describe, expect, it } from 'vitest';
1
2
  import convertComplementaryAreas from '../convert-complementary-areas';
2
3
 
3
4
  describe( 'convertComplementaryAreas', () => {
@@ -1,3 +1,4 @@
1
+ import { describe, expect, it } from 'vitest';
1
2
  import convertEditorSettings from '../convert-editor-settings';
2
3
 
3
4
  describe( 'convertEditorSettings', () => {
@@ -1,3 +1,4 @@
1
+ import { describe, expect, it } from 'vitest';
1
2
  import convertPreferencesPackageData from '../';
2
3
 
3
4
  const input = {