@wordpress/api-fetch 5.2.2-next.5df0cd52b7.0 → 5.2.5
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/CHANGELOG.md +6 -0
- package/README.md +10 -10
- package/build/middlewares/media-upload.js +12 -3
- package/build/middlewares/media-upload.js.map +1 -1
- package/build/middlewares/preloading.js +22 -31
- package/build/middlewares/preloading.js.map +1 -1
- package/build-module/middlewares/media-upload.js +12 -3
- package/build-module/middlewares/media-upload.js.map +1 -1
- package/build-module/middlewares/preloading.js +21 -29
- package/build-module/middlewares/preloading.js.map +1 -1
- package/build-types/index.d.ts +2 -2
- package/build-types/index.d.ts.map +1 -1
- package/build-types/middlewares/media-upload.d.ts.map +1 -1
- package/build-types/middlewares/preloading.d.ts +0 -10
- package/build-types/middlewares/preloading.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/middlewares/media-upload.js +15 -5
- package/src/middlewares/preloading.js +20 -41
- package/src/middlewares/test/media-upload.js +35 -0
- package/src/middlewares/test/preloading.js +29 -24
- package/tsconfig.tsbuildinfo +1 -802
|
@@ -1,32 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
|
-
import createPreloadingMiddleware
|
|
4
|
+
import createPreloadingMiddleware from '../preloading';
|
|
5
5
|
|
|
6
6
|
describe( 'Preloading Middleware', () => {
|
|
7
|
-
describe( 'getStablePath', () => {
|
|
8
|
-
it( 'returns same value if no query parameters', () => {
|
|
9
|
-
const path = '/foo/bar';
|
|
10
|
-
|
|
11
|
-
expect( getStablePath( path ) ).toBe( path );
|
|
12
|
-
} );
|
|
13
|
-
|
|
14
|
-
it( 'returns a stable path', () => {
|
|
15
|
-
const abc = getStablePath( '/foo/bar?a=5&b=1&c=2' );
|
|
16
|
-
const bca = getStablePath( '/foo/bar?b=1&c=2&a=5' );
|
|
17
|
-
const bac = getStablePath( '/foo/bar?b=1&a=5&c=2' );
|
|
18
|
-
const acb = getStablePath( '/foo/bar?a=5&c=2&b=1' );
|
|
19
|
-
const cba = getStablePath( '/foo/bar?c=2&b=1&a=5' );
|
|
20
|
-
const cab = getStablePath( '/foo/bar?c=2&a=5&b=1' );
|
|
21
|
-
|
|
22
|
-
expect( abc ).toBe( bca );
|
|
23
|
-
expect( bca ).toBe( bac );
|
|
24
|
-
expect( bac ).toBe( acb );
|
|
25
|
-
expect( acb ).toBe( cba );
|
|
26
|
-
expect( cba ).toBe( cab );
|
|
27
|
-
} );
|
|
28
|
-
} );
|
|
29
|
-
|
|
30
7
|
describe( 'given preloaded data', () => {
|
|
31
8
|
describe( 'when data is requested from a preloaded endpoint', () => {
|
|
32
9
|
describe( 'and it is requested for the first time', () => {
|
|
@@ -199,6 +176,34 @@ describe( 'Preloading Middleware', () => {
|
|
|
199
176
|
expect( value ).toEqual( body );
|
|
200
177
|
} );
|
|
201
178
|
|
|
179
|
+
it( 'should remove OPTIONS type requests from the cache after the first hit', async () => {
|
|
180
|
+
const body = { content: 'example' };
|
|
181
|
+
const preloadedData = {
|
|
182
|
+
OPTIONS: {
|
|
183
|
+
'wp/v2/demo': { body },
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
const preloadingMiddleware = createPreloadingMiddleware(
|
|
188
|
+
preloadedData
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
const requestOptions = {
|
|
192
|
+
method: 'OPTIONS',
|
|
193
|
+
path: 'wp/v2/demo',
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const firstMiddleware = jest.fn();
|
|
197
|
+
preloadingMiddleware( requestOptions, firstMiddleware );
|
|
198
|
+
expect( firstMiddleware ).not.toHaveBeenCalled();
|
|
199
|
+
|
|
200
|
+
await preloadingMiddleware( requestOptions, firstMiddleware );
|
|
201
|
+
|
|
202
|
+
const secondMiddleware = jest.fn();
|
|
203
|
+
await preloadingMiddleware( requestOptions, secondMiddleware );
|
|
204
|
+
expect( secondMiddleware ).toHaveBeenCalledTimes( 1 );
|
|
205
|
+
} );
|
|
206
|
+
|
|
202
207
|
describe.each( [ [ 'GET' ], [ 'OPTIONS' ] ] )( '%s', ( method ) => {
|
|
203
208
|
describe.each( [
|
|
204
209
|
[ 'all empty', {} ],
|