@module-federation/data-prefetch 0.0.0-next-20241230094715 → 0.0.0-next-20250103032148

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.
@@ -1,14 +1,13 @@
1
1
  import { FederationHost } from '@module-federation/runtime';
2
2
  import { ModuleInfo } from '@module-federation/sdk';
3
3
  import { Remote } from '@module-federation/runtime/types';
4
- declare module '@module-federation/runtime' {
5
- interface Federation {
6
- __PREFETCH__: {
7
- entryLoading: Record<string, undefined | Promise<void>>;
8
- instance: Map<string, MFDataPrefetch>;
9
- __PREFETCH_EXPORTS__: Record<string, () => Promise<Record<string, any>>>;
10
- };
11
- }
4
+ import type { Federation } from '@module-federation/runtime';
5
+ interface FederationWithPrefetch extends Federation {
6
+ __PREFETCH__: {
7
+ entryLoading: Record<string, undefined | Promise<void>>;
8
+ instance: Map<string, MFDataPrefetch>;
9
+ __PREFETCH_EXPORTS__: Record<string, () => Promise<Record<string, any>>>;
10
+ };
12
11
  }
13
12
  type PrefetchExports = Record<string, any>;
14
13
  export interface DataPrefetchOptions {
@@ -29,7 +28,7 @@ export declare class MFDataPrefetch {
29
28
  private _exports;
30
29
  private _options;
31
30
  constructor(options: DataPrefetchOptions);
32
- get global(): Record<string, any>;
31
+ get global(): FederationWithPrefetch['__PREFETCH__'];
33
32
  static getInstance(id: string): MFDataPrefetch | undefined;
34
33
  loadEntry(entry: string | undefined): Promise<any>;
35
34
  getProjectExports(): Promise<void> | Record<string, any>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@module-federation/data-prefetch",
3
3
  "description": "Module Federation Data Prefetch",
4
- "version": "0.0.0-next-20241230094715",
4
+ "version": "0.0.0-next-20250103032148",
5
5
  "author": "nieyan <nyqykk@foxmail.com>",
6
6
  "homepage": "https://github.com/module-federation/core",
7
7
  "license": "MIT",
@@ -13,31 +13,36 @@
13
13
  "publishConfig": {
14
14
  "access": "public"
15
15
  },
16
+ "files": [
17
+ "dist",
18
+ "README.md",
19
+ "LICENSE"
20
+ ],
16
21
  "exports": {
17
22
  ".": {
23
+ "types": "./dist/index.cjs.d.ts",
18
24
  "import": "./dist/index.esm.mjs",
19
- "require": "./dist/index.cjs",
20
- "types": "./dist/index.cjs.d.ts"
25
+ "require": "./dist/index.cjs.js"
21
26
  },
22
27
  "./react": {
28
+ "types": "./dist/react.cjs.d.ts",
23
29
  "import": "./dist/react.esm.mjs",
24
- "require": "./dist/react.cjs.js",
25
- "types": "./dist/react.cjs.d.ts"
30
+ "require": "./dist/react.cjs.js"
26
31
  },
27
32
  "./cli": {
33
+ "types": "./dist/cli.cjs.d.ts",
28
34
  "import": "./dist/cli.esm.mjs",
29
- "require": "./dist/cli.cjs.js",
30
- "types": "./dist/cli.cjs.d.ts"
35
+ "require": "./dist/cli.cjs.js"
31
36
  },
32
37
  "./babel-plugin": {
38
+ "types": "./dist/babel.cjs.d.ts",
33
39
  "import": "./dist/babel.esm.mjs",
34
- "require": "./dist/babel.cjs.js",
35
- "types": "./dist/babel.cjs.d.ts"
40
+ "require": "./dist/babel.cjs.js"
36
41
  },
37
42
  "./universal": {
43
+ "types": "./dist/universal.cjs.d.ts",
38
44
  "import": "./dist/universal.esm.mjs",
39
- "require": "./dist/universal.cjs.js",
40
- "types": "./dist/universal.cjs.d.ts"
45
+ "require": "./dist/universal.cjs.js"
41
46
  }
42
47
  },
43
48
  "typesVersions": {
@@ -59,7 +64,7 @@
59
64
  ]
60
65
  }
61
66
  },
62
- "main": "dist/index.cjs",
67
+ "main": "dist/index.cjs.js",
63
68
  "module": "dist/index.esm.mjs",
64
69
  "peerDependencies": {
65
70
  "react": ">=16.9.0",
@@ -83,8 +88,8 @@
83
88
  },
84
89
  "dependencies": {
85
90
  "fs-extra": "9.1.0",
86
- "@module-federation/runtime": "0.0.0-next-20241230094715",
87
- "@module-federation/sdk": "0.0.0-next-20241230094715"
91
+ "@module-federation/runtime": "0.0.0-next-20250103032148",
92
+ "@module-federation/sdk": "0.0.0-next-20250103032148"
88
93
  },
89
94
  "scripts": {
90
95
  "test": "jest"
package/.swcrc DELETED
@@ -1,29 +0,0 @@
1
- {
2
- "jsc": {
3
- "target": "es2017",
4
- "parser": {
5
- "syntax": "typescript",
6
- "decorators": true,
7
- "dynamicImport": true
8
- },
9
- "transform": {
10
- "decoratorMetadata": true,
11
- "legacyDecorator": true
12
- },
13
- "keepClassNames": true,
14
- "externalHelpers": true,
15
- "loose": true
16
- },
17
- "module": {
18
- "type": "es6"
19
- },
20
- "sourceMaps": true,
21
- "exclude": [
22
- "jest.config.ts",
23
- ".*\\.spec.tsx?$",
24
- ".*\\.test.tsx?$",
25
- "./src/jest-setup.ts$",
26
- "./**/jest-setup.ts$",
27
- ".*.js$"
28
- ]
29
- }
package/CHANGELOG.md DELETED
@@ -1,238 +0,0 @@
1
- # @module-federation/data-prefetch
2
-
3
- ## 0.0.0-next-20241230094715
4
-
5
- ### Patch Changes
6
-
7
- - Updated dependencies [835b09c]
8
- - Updated dependencies [336f3d8]
9
- - Updated dependencies [4fd33fb]
10
- - @module-federation/sdk@0.0.0-next-20241230094715
11
- - @module-federation/runtime@0.0.0-next-20241230094715
12
-
13
- ## 0.8.6
14
-
15
- ### Patch Changes
16
-
17
- - @module-federation/runtime@0.8.6
18
- - @module-federation/sdk@0.8.6
19
-
20
- ## 0.8.5
21
-
22
- ### Patch Changes
23
-
24
- - @module-federation/runtime@0.8.5
25
- - @module-federation/sdk@0.8.5
26
-
27
- ## 0.8.4
28
-
29
- ### Patch Changes
30
-
31
- - @module-federation/runtime@0.8.4
32
- - @module-federation/sdk@0.8.4
33
-
34
- ## 0.8.3
35
-
36
- ### Patch Changes
37
-
38
- - 5b637c3: fix(data-prefetch): the prefetch exports type is promise or function
39
- - Updated dependencies [f817674]
40
- - Updated dependencies [8e172c8]
41
- - @module-federation/runtime@0.8.3
42
- - @module-federation/sdk@0.8.3
43
-
44
- ## 0.8.2
45
-
46
- ### Patch Changes
47
-
48
- - Updated dependencies [fa7a0bd]
49
- - @module-federation/runtime@0.8.2
50
- - @module-federation/sdk@0.8.2
51
-
52
- ## 0.8.1
53
-
54
- ### Patch Changes
55
-
56
- - @module-federation/runtime@0.8.1
57
- - @module-federation/sdk@0.8.1
58
-
59
- ## 0.8.0
60
-
61
- ### Patch Changes
62
-
63
- - @module-federation/runtime@0.8.0
64
- - @module-federation/sdk@0.8.0
65
-
66
- ## 0.7.7
67
-
68
- ### Patch Changes
69
-
70
- - Updated dependencies [a960c88]
71
- - Updated dependencies [e26d107]
72
- - @module-federation/runtime@0.7.7
73
- - @module-federation/sdk@0.7.7
74
-
75
- ## 0.7.6
76
-
77
- ### Patch Changes
78
-
79
- - @module-federation/runtime@0.7.6
80
- - @module-federation/sdk@0.7.6
81
-
82
- ## 0.7.5
83
-
84
- ### Patch Changes
85
-
86
- - @module-federation/runtime@0.7.5
87
- - @module-federation/sdk@0.7.5
88
-
89
- ## 0.7.4
90
-
91
- ### Patch Changes
92
-
93
- - Updated dependencies [ff8ce29]
94
- - @module-federation/runtime@0.7.4
95
- - @module-federation/sdk@0.7.4
96
-
97
- ## 0.7.3
98
-
99
- ### Patch Changes
100
-
101
- - 4ab9295: disable package json generation during build
102
- - Updated dependencies [4ab9295]
103
- - Updated dependencies [c2b1efa]
104
- - @module-federation/runtime@0.7.3
105
- - @module-federation/sdk@0.7.3
106
-
107
- ## 0.7.2
108
-
109
- ### Patch Changes
110
-
111
- - @module-federation/runtime@0.7.2
112
- - @module-federation/sdk@0.7.2
113
-
114
- ## 0.7.1
115
-
116
- ### Patch Changes
117
-
118
- - Updated dependencies [66ba7b1]
119
- - Updated dependencies [8712967]
120
- - Updated dependencies [6db4c5f]
121
- - @module-federation/runtime@0.7.1
122
- - @module-federation/sdk@0.7.1
123
-
124
- ## 0.7.0
125
-
126
- ### Minor Changes
127
-
128
- - 206b56d: disable hoistTransitiveImports for better tree shake
129
- - Updated dependencies [752537b]
130
- - Updated dependencies [54bfd1c]
131
- - Updated dependencies [879ad87]
132
- - Updated dependencies [4eb09e7]
133
- - Updated dependencies [206b56d]
134
- - @module-federation/runtime@0.7.0
135
- - @module-federation/sdk@0.7.0
136
-
137
- ## 0.6.16
138
-
139
- ### Patch Changes
140
-
141
- - 024df60: disable hoistTransitiveImports for better tree shake
142
- - Updated dependencies [f779188]
143
- - Updated dependencies [024df60]
144
- - @module-federation/sdk@0.6.16
145
- - @module-federation/runtime@0.6.16
146
-
147
- ## 0.6.15
148
-
149
- ### Patch Changes
150
-
151
- - Updated dependencies [ec31539]
152
- - @module-federation/runtime@0.6.15
153
- - @module-federation/sdk@0.6.15
154
-
155
- ## 0.6.14
156
-
157
- ### Patch Changes
158
-
159
- - ad605d2: chore: unified logger
160
- - Updated dependencies [ad605d2]
161
- - @module-federation/runtime@0.6.14
162
- - @module-federation/sdk@0.6.14
163
-
164
- ## 0.6.13
165
-
166
- ### Patch Changes
167
-
168
- - @module-federation/runtime@0.6.13
169
- - @module-federation/sdk@0.6.13
170
-
171
- ## 0.6.12
172
-
173
- ### Patch Changes
174
-
175
- - @module-federation/runtime@0.6.12
176
- - @module-federation/sdk@0.6.12
177
-
178
- ## 0.6.11
179
-
180
- ### Patch Changes
181
-
182
- - Updated dependencies [ea6d417]
183
- - Updated dependencies [d5a3072]
184
- - @module-federation/runtime@0.6.11
185
- - @module-federation/sdk@0.6.11
186
-
187
- ## 0.6.10
188
-
189
- ### Patch Changes
190
-
191
- - 22a3b83: fix(data-prefetch): apply DataPrefetchPlugin on demand
192
- - 22a3b83: fix(data-prefetch): set sharedStrategy in build options instead of using runtime plugin
193
- - Updated dependencies [b704f30]
194
- - Updated dependencies [22a3b83]
195
- - @module-federation/runtime@0.6.10
196
- - @module-federation/sdk@0.6.10
197
-
198
- ## 0.6.9
199
-
200
- ### Patch Changes
201
-
202
- - @module-federation/runtime@0.6.9
203
- - @module-federation/sdk@0.6.9
204
-
205
- ## 0.6.8
206
-
207
- ### Patch Changes
208
-
209
- - Updated dependencies [32db0ac]
210
- - Updated dependencies [32db0ac]
211
- - Updated dependencies [6c5f444]
212
- - Updated dependencies [fac6ecf]
213
- - @module-federation/sdk@0.6.8
214
- - @module-federation/runtime@0.6.8
215
-
216
- ## 0.6.7
217
-
218
- ### Patch Changes
219
-
220
- - 9e32644: Refactored the way prefetch entries are imported for improved dynamic loading handling.
221
-
222
- - Changed the import of prefetch entries to use a function wrapper for more dynamic control.
223
- - Updated data types to ensure consistency with the new function-based import approach.
224
- - Modified the `injectPrefetch` function structure to incorporate the new import method.
225
- - Modified the `MFDataPrefetch` class to handle the new import function when resolving exports.
226
-
227
- - Updated dependencies [9e32644]
228
- - Updated dependencies [9e32644]
229
- - Updated dependencies [9e32644]
230
- - @module-federation/runtime@0.6.7
231
- - @module-federation/sdk@0.6.7
232
-
233
- ## 0.6.6
234
-
235
- ### Patch Changes
236
-
237
- - @module-federation/runtime@0.6.6
238
- - @module-federation/sdk@0.6.6
@@ -1,75 +0,0 @@
1
- /// <reference types="jest" />
2
-
3
- import path from 'path';
4
- import fs from 'fs';
5
- import { BabelFileResult, transformFileSync } from '@babel/core';
6
- // @ts-ignore no use
7
- import type from '@types/jest';
8
-
9
- import babelPlugin from '../src/cli/babel';
10
-
11
- const emptyRegexp = /\s+/g;
12
- describe('Babel Plugin Test', () => {
13
- const options = {
14
- name: '@mf/test',
15
- exposes: { './expose': path.resolve(__dirname, 'test') },
16
- };
17
-
18
- const testFilePath = path.join(__dirname, './test');
19
-
20
- beforeEach(() => {
21
- fs.mkdirSync(path.dirname(testFilePath), { recursive: true });
22
- fs.closeSync(fs.openSync(testFilePath, 'w'));
23
- });
24
-
25
- afterEach(() => {
26
- fs.unlinkSync(testFilePath);
27
- });
28
-
29
- // Check if the plugin will add the id parameter when it is not present
30
- test('it adds id argument to usePrefetch call when it is absent', () => {
31
- const input = `
32
- import { usePrefetch } from "@module-federation/data-prefetch/react";
33
- usePrefetch({});
34
- `;
35
-
36
- const expected = `
37
- import { usePrefetch } from "@module-federation/data-prefetch/react";
38
- usePrefetch({ id: "@mf/test/expose" });
39
- `;
40
-
41
- fs.writeFileSync(testFilePath, input);
42
- const { code } = transformFileSync(testFilePath, {
43
- plugins: [[babelPlugin, options]],
44
- configFile: false,
45
- }) as BabelFileResult;
46
-
47
- expect(code?.replace(emptyRegexp, '')).toBe(
48
- expected.replace(emptyRegexp, ''),
49
- );
50
- });
51
-
52
- // The plugin should retain the existing id parameter in the usePrefetch call
53
- test('it does not overwrite existing id argument in usePrefetch call', () => {
54
- const input = `
55
- import { usePrefetch } from "@module-federation/data-prefetch/react";
56
- usePrefetch({ id: "existingId" });
57
- `;
58
-
59
- const expected = `
60
- import { usePrefetch } from "@module-federation/data-prefetch/react";
61
- usePrefetch({ id: "existingId" });
62
- `;
63
-
64
- fs.writeFileSync(testFilePath, input);
65
- const { code } = transformFileSync(testFilePath, {
66
- plugins: [[babelPlugin, options]],
67
- configFile: false,
68
- babelrc: false,
69
- }) as BabelFileResult;
70
-
71
- expect(code?.replace(emptyRegexp, '')).toBe(
72
- expected.replace(emptyRegexp, ''),
73
- );
74
- });
75
- });
@@ -1,139 +0,0 @@
1
- // Import the necessary modules and functions
2
- import { MFDataPrefetch } from '../src/prefetch';
3
- import {
4
- loadScript,
5
- MFPrefetchCommon,
6
- encodeName,
7
- } from '@module-federation/sdk';
8
-
9
- // Mock loadScript function from SDK
10
- jest.mock('@module-federation/sdk', () => {
11
- const originalModule = jest.requireActual('@module-federation/sdk');
12
- return {
13
- ...originalModule,
14
- loadScript: jest.fn(() => Promise.resolve()),
15
- };
16
- });
17
-
18
- describe('MF Data Prefetch', () => {
19
- let prefetch: MFDataPrefetch;
20
-
21
- const options = {
22
- name: '@mf/test',
23
- remoteSnapshot: {
24
- buildVersion: '1.0.0',
25
- globalName: 'TestGlobalName',
26
- },
27
- };
28
- const exposeId = `${options.name}/button/${MFPrefetchCommon.identifier}`;
29
-
30
- beforeEach(() => {
31
- globalThis.__FEDERATION__.__PREFETCH__ = {
32
- entryLoading: {},
33
- instance: new Map(),
34
- __PREFETCH_EXPORTS__: {},
35
- };
36
- // @ts-ignore
37
- prefetch = new MFDataPrefetch(options);
38
- });
39
- afterAll(() => {
40
- // @ts-ignore
41
- delete globalThis.__FEDERATION__;
42
- });
43
-
44
- // Instance gets added to global memory on creation
45
- it('adds itself to global instances on creation', () => {
46
- expect(prefetch.global.instance.get(options.name)).toBe(prefetch);
47
- });
48
-
49
- // Loads entry script using loadScript from sdk
50
- it('loads entry script using loadScript from sdk', async () => {
51
- const url = 'testUrl'; // Url of the script to be loaded
52
-
53
- await prefetch.loadEntry(url); // Call `loadEntry` function
54
-
55
- // Expect that the loadScript function is called with the correct url
56
- expect(loadScript).toHaveBeenCalledWith(url, expect.any(Object));
57
- });
58
-
59
- // Retrieves project exports
60
- it('gets project exports', async () => {
61
- const exposeExport = {
62
- nyPrefetch: () => {},
63
- };
64
- const projectExport = {
65
- [encodeName(exposeId)]: exposeExport,
66
- };
67
- globalThis.__FEDERATION__.__PREFETCH__.__PREFETCH_EXPORTS__[options.name] =
68
- () => Promise.resolve(projectExport);
69
-
70
- await prefetch.getProjectExports();
71
- expect(prefetch.getExposeExports(`${options.name}/button`)).toEqual(
72
- exposeExport,
73
- );
74
- });
75
-
76
- // Prefetching with memory and executing prefetch function
77
- it('executes prefetch using prefetch function with and without memory', async () => {
78
- const id = options.name;
79
- const functionId = 'nyPrefetch';
80
- const refetchParams = 'testParams';
81
- const prefetchOptions = { id: `${id}/button`, functionId, refetchParams };
82
-
83
- // Creating a mock prefetch function
84
- const executePrefetch = jest.fn(() => 'Expected Result');
85
- const prefetchExports = { [functionId]: executePrefetch };
86
-
87
- // Mock Project Exports
88
- globalThis.__FEDERATION__.__PREFETCH__.__PREFETCH_EXPORTS__[id] = () =>
89
- Promise.resolve({
90
- [encodeName(exposeId)]: prefetchExports,
91
- });
92
-
93
- await prefetch.getProjectExports();
94
- // Call the prefetch function first time
95
- let result = await prefetch.prefetch(prefetchOptions);
96
-
97
- // Verify that executePrefetch function is correctly executed
98
- expect(executePrefetch).toHaveBeenCalled();
99
-
100
- // Clear mock function calls data
101
- executePrefetch.mockClear();
102
-
103
- // Call the prefetch function again
104
- result = await prefetch.prefetch(prefetchOptions);
105
-
106
- // Verify that executePrefetch function is NOT called this time (since the result should come from memory)
107
- expect(executePrefetch).not.toHaveBeenCalled();
108
-
109
- // Clear mock function calls data
110
- executePrefetch.mockClear();
111
-
112
- prefetch.markOutdate(prefetchOptions, true);
113
-
114
- // Call the prefetch function first time
115
- result = await prefetch.prefetch(prefetchOptions);
116
-
117
- // Verify that executePrefetch function is correctly executed
118
- expect(executePrefetch).toHaveBeenCalled();
119
- });
120
-
121
- // Checking outdate marking
122
- it('checks outdate marking', () => {
123
- const markOptions = { id: 'testId', functionId: 'testFunction' };
124
-
125
- // Mark the function as outdated
126
- prefetch.markOutdate(markOptions, true);
127
-
128
- // Verify that the function is marked as outdated
129
- let isOutdated = prefetch.checkOutdate(markOptions);
130
- expect(isOutdated).toBe(true);
131
-
132
- // Mark the function as up-to-date
133
- prefetch.markOutdate(markOptions, false);
134
-
135
- // Verify that the function is marked as up-to-date
136
- isOutdated = prefetch.checkOutdate(markOptions);
137
- expect(isOutdated).toBe(false);
138
- });
139
- });
@@ -1,119 +0,0 @@
1
- import { FederationHost, init } from '@module-federation/runtime';
2
- import { renderHook, act } from '@testing-library/react-hooks';
3
- import * as ModuleFederationSDK from '@module-federation/sdk';
4
- import { usePrefetch } from '../src/react';
5
- import { MFDataPrefetch } from '../src/prefetch';
6
-
7
- const mockLoadScript = jest.spyOn(ModuleFederationSDK, 'loadScript');
8
- mockLoadScript.mockImplementation(() => Promise.resolve());
9
-
10
- describe('usePrefetch', () => {
11
- // Mock prefetch function
12
- global.fetch = jest.fn(() =>
13
- Promise.resolve({
14
- ok: true,
15
- status: 200,
16
- statusText: 'OK',
17
- redirected: false,
18
- type: 'basic',
19
- url: '',
20
- clone: jest.fn(),
21
- headers: new Headers(),
22
- body: null,
23
- bodyUsed: false,
24
- text: () => Promise.resolve(JSON.stringify({ data: 'testData' })),
25
- json: () => Promise.resolve({ data: 'testData' }),
26
- formData: () => Promise.resolve(new FormData()),
27
- arrayBuffer: () => Promise.resolve(new ArrayBuffer(0)),
28
- blob: () => Promise.resolve(new Blob()),
29
- }),
30
- );
31
-
32
- let prefetch: MFDataPrefetch;
33
-
34
- const options = {
35
- // Options that will be passed to the `MFDataPrefetch` constructor
36
- name: '@mf/test',
37
- remoteSnapshot: {
38
- buildVersion: '1.0.0',
39
- globalName: 'TestGlobalName',
40
- },
41
- };
42
- const testData = 'testData';
43
- const newTestData = 'newTestData';
44
- const functionId = 'testPrefetch';
45
- const executePrefetch = jest.fn((params: string) =>
46
- Promise.resolve(params ? params : testData),
47
- );
48
-
49
- new FederationHost({
50
- name: options.name,
51
- remotes: [],
52
- });
53
- init({
54
- name: options.name,
55
- remotes: [],
56
- });
57
- beforeEach(() => {
58
- globalThis.__FEDERATION__.__PREFETCH__ = {
59
- entryLoading: {},
60
- instance: new Map(),
61
- __PREFETCH_EXPORTS__: {},
62
- };
63
- // @ts-ignore
64
- prefetch = new MFDataPrefetch(options); // Create a new instance of `MFDataPrefetch` class before each test
65
-
66
- const exposeExport = {
67
- [functionId]: executePrefetch,
68
- };
69
- const exposeId = `${options.name}/button/${ModuleFederationSDK.MFPrefetchCommon.identifier}`;
70
- const projectExport = {
71
- [ModuleFederationSDK.encodeName(exposeId)]: exposeExport,
72
- };
73
- globalThis.__FEDERATION__.__PREFETCH__.__PREFETCH_EXPORTS__[options.name] =
74
- () => Promise.resolve(projectExport);
75
- });
76
-
77
- afterEach(() => {
78
- executePrefetch.mockClear();
79
- mockLoadScript.mockRestore();
80
- });
81
-
82
- afterAll(() => {
83
- // @ts-ignore
84
- delete globalThis.__FEDERATION__;
85
- });
86
-
87
- it('should prefetch data on first mount', async () => {
88
- const { result } = renderHook(() =>
89
- usePrefetch({ id: `${options.name}/button`, functionId }),
90
- );
91
- await result.current[0];
92
- expect(executePrefetch).toHaveBeenCalled();
93
- // Verify the prefechState
94
- expect(result.current[0]).resolves.toEqual(testData);
95
- });
96
-
97
- it('should refetch data when refreshExecutor is called', async () => {
98
- const { result } = renderHook(() =>
99
- usePrefetch({ id: `${options.name}/button`, functionId }),
100
- );
101
-
102
- await result.current[0];
103
- expect(executePrefetch).toHaveBeenCalled();
104
- executePrefetch.mockClear();
105
- const { result: newCallResult } = renderHook(() =>
106
- usePrefetch({ id: `${options.name}/button`, functionId }),
107
- );
108
- await newCallResult.current[0];
109
- expect(executePrefetch).not.toHaveBeenCalled();
110
- // Call refreshExecutor
111
- act(() => {
112
- result.current[1](newTestData);
113
- });
114
-
115
- expect(executePrefetch).toHaveBeenCalled();
116
- // // Verify the prefetchState after refetch
117
- expect(result.current[0]).resolves.toEqual(newTestData);
118
- });
119
- });