@data-client/vue 0.18.1 → 0.18.2
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 +371 -0
- package/README.md +86 -41
- package/dist/index.js +223 -158
- package/dist/index.umd.min.js +1 -1
- package/lib/consumers/refetchTriggers.d.ts +12 -0
- package/lib/consumers/refetchTriggers.d.ts.map +1 -0
- package/lib/consumers/refetchTriggers.js +9 -0
- package/lib/consumers/useCache.d.ts +1 -1
- package/lib/consumers/useCache.d.ts.map +1 -1
- package/lib/consumers/useCache.js +3 -53
- package/lib/consumers/useCacheResponse.d.ts +20 -0
- package/lib/consumers/useCacheResponse.d.ts.map +1 -0
- package/lib/consumers/useCacheResponse.js +55 -0
- package/lib/consumers/useCountRef.d.ts +7 -0
- package/lib/consumers/useCountRef.d.ts.map +1 -0
- package/lib/consumers/useCountRef.js +10 -0
- package/lib/consumers/useDLE.d.ts +1 -1
- package/lib/consumers/useDLE.d.ts.map +1 -1
- package/lib/consumers/useDLE.js +16 -62
- package/lib/consumers/useDebounce.d.ts +1 -1
- package/lib/consumers/useDebounce.d.ts.map +1 -1
- package/lib/consumers/useDebounce.js +1 -2
- package/lib/consumers/useExpired.d.ts +12 -0
- package/lib/consumers/useExpired.d.ts.map +1 -0
- package/lib/consumers/useExpired.js +19 -0
- package/lib/consumers/useFetch.d.ts +8 -11
- package/lib/consumers/useFetch.d.ts.map +1 -1
- package/lib/consumers/useFetch.js +13 -24
- package/lib/consumers/useLive.js +1 -1
- package/lib/consumers/useLoading.d.ts +1 -1
- package/lib/consumers/useLoading.d.ts.map +1 -1
- package/lib/consumers/useLoading.js +1 -2
- package/lib/consumers/useQuery.d.ts +1 -1
- package/lib/consumers/useQuery.d.ts.map +1 -1
- package/lib/consumers/useQuery.js +6 -12
- package/lib/consumers/useResponseMeta.d.ts +23 -0
- package/lib/consumers/useResponseMeta.d.ts.map +1 -0
- package/lib/consumers/useResponseMeta.js +36 -0
- package/lib/consumers/useSubscription.js +4 -4
- package/lib/consumers/useSuspense.d.ts +1 -1
- package/lib/consumers/useSuspense.d.ts.map +1 -1
- package/lib/consumers/useSuspense.js +58 -34
- package/lib/context.d.ts +1 -1
- package/lib/context.d.ts.map +1 -1
- package/lib/context.js +3 -3
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +4 -2
- package/lib/internal.d.ts +6 -0
- package/lib/internal.d.ts.map +1 -0
- package/lib/internal.js +6 -0
- package/lib/providers/DataClientPlugin.d.ts +1 -1
- package/lib/providers/DataClientPlugin.d.ts.map +1 -1
- package/lib/providers/DataClientPlugin.js +16 -4
- package/lib/providers/createDataClient.d.ts +10 -4
- package/lib/providers/createDataClient.d.ts.map +1 -1
- package/lib/providers/createDataClient.js +11 -5
- package/lib/providers/getDefaultManagers.d.ts.map +1 -1
- package/lib/providers/getDefaultManagers.js +1 -1
- package/lib/providers/index.d.ts +2 -1
- package/lib/providers/index.d.ts.map +1 -1
- package/lib/providers/index.js +1 -1
- package/lib/test/MockPlugin.d.ts +1 -1
- package/lib/test/MockPlugin.d.ts.map +1 -1
- package/lib/test/MockPlugin.js +1 -1
- package/lib/test/index.d.ts +2 -1
- package/lib/test/index.d.ts.map +1 -1
- package/lib/test/index.js +1 -1
- package/lib/test/mountDataClient.d.ts +5 -3
- package/lib/test/mountDataClient.d.ts.map +1 -1
- package/lib/test/mountDataClient.js +15 -10
- package/lib/test/renderDataCompose.d.ts +10 -4
- package/lib/test/renderDataCompose.d.ts.map +1 -1
- package/lib/test/renderDataCompose.js +2 -3
- package/package.json +20 -5
- package/src/__tests__/__snapshots__/context.test.ts.snap +2 -2
- package/src/__tests__/context.test.ts +1 -1
- package/src/__tests__/integration-garbage-collection.web.ts +80 -4
- package/src/__tests__/useCache.web.ts +160 -93
- package/src/__tests__/useDLE.web.ts +204 -96
- package/src/__tests__/useFetch.web.ts +100 -37
- package/src/__tests__/useQuery.web.ts +60 -50
- package/src/__tests__/useSubscription.web.ts +74 -75
- package/src/__tests__/useSuspense.web.ts +455 -46
- package/src/consumers/refetchTriggers.ts +22 -0
- package/src/consumers/useCache.ts +7 -70
- package/src/consumers/useCacheResponse.ts +56 -0
- package/src/consumers/useCountRef.ts +15 -0
- package/src/consumers/useDLE.ts +24 -83
- package/src/consumers/useDebounce.ts +2 -1
- package/src/consumers/useExpired.ts +26 -0
- package/src/consumers/useFetch.ts +34 -49
- package/src/consumers/useLive.ts +1 -1
- package/src/consumers/useLoading.ts +2 -1
- package/src/consumers/useQuery.ts +10 -13
- package/src/consumers/useResponseMeta.ts +41 -0
- package/src/consumers/useSubscription.ts +3 -3
- package/src/consumers/useSuspense.ts +66 -58
- package/src/context.ts +4 -3
- package/src/index.ts +7 -1
- package/src/internal.ts +12 -0
- package/src/providers/DataClientPlugin.ts +17 -3
- package/src/providers/__tests__/DataClientPlugin.test.ts +40 -1
- package/src/providers/createDataClient.ts +15 -5
- package/src/providers/getDefaultManagers.ts +2 -6
- package/src/providers/index.ts +2 -5
- package/src/test/MockPlugin.ts +3 -3
- package/src/test/README.md +10 -304
- package/src/test/__tests__/mountDataClient.test.ts +38 -0
- package/src/test/index.ts +2 -1
- package/src/test/mountDataClient.ts +22 -17
- package/src/test/renderDataCompose.ts +11 -7
|
@@ -5,19 +5,14 @@ import {
|
|
|
5
5
|
NetworkManager,
|
|
6
6
|
SubscriptionManager,
|
|
7
7
|
PollingSubscription,
|
|
8
|
-
type GCInterface,
|
|
9
8
|
} from '@data-client/core';
|
|
9
|
+
import type { GCInterface } from '@data-client/core';
|
|
10
10
|
import type { Interceptor, Fixture } from '@data-client/core/mock';
|
|
11
11
|
import { MockController } from '@data-client/core/mock';
|
|
12
|
-
import { mount
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
Suspense,
|
|
17
|
-
inject,
|
|
18
|
-
type Reactive,
|
|
19
|
-
reactive,
|
|
20
|
-
} from 'vue';
|
|
12
|
+
import { mount } from '@vue/test-utils';
|
|
13
|
+
import type { VueWrapper } from '@vue/test-utils';
|
|
14
|
+
import { defineComponent, h, Suspense, inject, nextTick, reactive } from 'vue';
|
|
15
|
+
import type { Reactive } from 'vue';
|
|
21
16
|
|
|
22
17
|
import mockInitialState from './mockState.js';
|
|
23
18
|
import { ControllerKey } from '../context.js';
|
|
@@ -45,6 +40,7 @@ export interface RenderDataClientResult {
|
|
|
45
40
|
/**
|
|
46
41
|
* Renders a Vue component with DataClient plugin and fixtures for testing
|
|
47
42
|
*
|
|
43
|
+
* @see https://dataclient.io/vue/guides/unit-testing-components
|
|
48
44
|
* @param component - The Vue component to test
|
|
49
45
|
* @param options - Configuration including optional reactive props ref, fixtures, managers, etc.
|
|
50
46
|
*/
|
|
@@ -77,10 +73,15 @@ export function mountDataClient<P = any>(
|
|
|
77
73
|
);
|
|
78
74
|
|
|
79
75
|
// Create managers
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
76
|
+
const finalManagers = managers ?? [
|
|
77
|
+
new NetworkManager(),
|
|
78
|
+
new SubscriptionManager(PollingSubscription),
|
|
79
|
+
];
|
|
80
|
+
// allSettled() and cleanup() track the NetworkManager actually in use
|
|
81
|
+
const nm =
|
|
82
|
+
finalManagers.find(
|
|
83
|
+
(manager): manager is NetworkManager => manager instanceof NetworkManager,
|
|
84
|
+
) ?? new NetworkManager();
|
|
84
85
|
|
|
85
86
|
// Create initial state
|
|
86
87
|
const mockState = mockInitialState([...initialFixtures]);
|
|
@@ -154,9 +155,13 @@ export function mountDataClient<P = any>(
|
|
|
154
155
|
wrapper_instance.unmount();
|
|
155
156
|
};
|
|
156
157
|
|
|
157
|
-
//
|
|
158
|
-
|
|
159
|
-
|
|
158
|
+
// Ticks before and after so fetches that watchers start on a prop change are included, and
|
|
159
|
+
// the component has re-rendered with their results
|
|
160
|
+
const allSettled = async (): Promise<PromiseSettledResult<unknown>[]> => {
|
|
161
|
+
await nextTick();
|
|
162
|
+
const results = (await nm.allSettled()) ?? [];
|
|
163
|
+
await nextTick();
|
|
164
|
+
return results;
|
|
160
165
|
};
|
|
161
166
|
|
|
162
167
|
return {
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { Controller } from '@data-client/core';
|
|
2
|
+
import type { VueWrapper } from '@vue/test-utils';
|
|
3
3
|
import { defineComponent, h, watch, reactive, nextTick, isRef } from 'vue';
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
type RenderDataClientOptions,
|
|
8
|
-
} from './mountDataClient.js';
|
|
5
|
+
import { mountDataClient } from './mountDataClient.js';
|
|
6
|
+
import type { RenderDataClientOptions } from './mountDataClient.js';
|
|
9
7
|
|
|
10
8
|
/**
|
|
11
9
|
* Renders a Vue composable with DataClient provider for testing
|
|
12
10
|
*
|
|
13
|
-
* @see https://dataclient.io/
|
|
11
|
+
* @see https://dataclient.io/vue/guides/unit-testing-composables
|
|
14
12
|
* @param composable - The composable function to test
|
|
15
13
|
* @param options - Configuration including optional reactive props ref, fixtures, managers, etc.
|
|
16
14
|
*/
|
|
@@ -23,6 +21,12 @@ export async function renderDataCompose<P = any, R = any>(
|
|
|
23
21
|
controller: Controller;
|
|
24
22
|
cleanup: () => void;
|
|
25
23
|
allSettled: () => Promise<PromiseSettledResult<unknown>[]>;
|
|
24
|
+
/**
|
|
25
|
+
* @deprecated Gives up silently after 1 second, so a test can pass while the composable is
|
|
26
|
+
* still suspended. Use `await result` for a Promise result, and `await allSettled()` after changing
|
|
27
|
+
* props or calling the controller.
|
|
28
|
+
* @see https://dataclient.io/vue/guides/unit-testing-composables#renderdatacompose-api
|
|
29
|
+
*/
|
|
26
30
|
waitForNextUpdate: () => Promise<void>;
|
|
27
31
|
}> {
|
|
28
32
|
// Extract props from options, or create empty ref if not provided
|