piral-core 1.3.3-beta.6190 → 1.3.3-beta.6204
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/app.codegen +2 -1
- package/esm/utils/routes.js +1 -3
- package/esm/utils/routes.js.map +1 -1
- package/lib/Piral.js +2 -1
- package/lib/Piral.js.map +1 -1
- package/lib/PiralContext.js +2 -1
- package/lib/PiralContext.js.map +1 -1
- package/lib/RootListener.js +2 -1
- package/lib/RootListener.js.map +1 -1
- package/lib/components/ErrorBoundary.js +1 -1
- package/lib/components/ErrorBoundary.js.map +1 -1
- package/lib/components/ExtensionSlot.js +2 -1
- package/lib/components/ExtensionSlot.js.map +1 -1
- package/lib/components/ForeignComponentContainer.js +2 -1
- package/lib/components/ForeignComponentContainer.js.map +1 -1
- package/lib/components/Mediator.js +2 -1
- package/lib/components/Mediator.js.map +1 -1
- package/lib/components/PiralGlobals.js +2 -1
- package/lib/components/PiralGlobals.js.map +1 -1
- package/lib/components/PiralRoutes.js +1 -1
- package/lib/components/PiralRoutes.js.map +1 -1
- package/lib/components/PiralSuspense.js +2 -1
- package/lib/components/PiralSuspense.js.map +1 -1
- package/lib/components/PiralView.js +2 -1
- package/lib/components/PiralView.js.map +1 -1
- package/lib/components/ResponsiveLayout.js +2 -1
- package/lib/components/ResponsiveLayout.js.map +1 -1
- package/lib/components/SwitchErrorInfo.js +2 -1
- package/lib/components/SwitchErrorInfo.js.map +1 -1
- package/lib/components/components.js +2 -1
- package/lib/components/components.js.map +1 -1
- package/lib/components/wrapComponent.js +2 -1
- package/lib/components/wrapComponent.js.map +1 -1
- package/lib/defaults/DefaultErrorInfo.js +2 -1
- package/lib/defaults/DefaultErrorInfo.js.map +1 -1
- package/lib/defaults/DefaultLoadingIndicator.js +2 -1
- package/lib/defaults/DefaultLoadingIndicator.js.map +1 -1
- package/lib/defaults/DefaultRouteSwitch_v5.js +1 -1
- package/lib/defaults/DefaultRouteSwitch_v5.js.map +1 -1
- package/lib/defaults/DefaultRouteSwitch_v6.js +1 -1
- package/lib/defaults/DefaultRouteSwitch_v6.js.map +1 -1
- package/lib/defaults/DefaultRouter_v5.js +2 -1
- package/lib/defaults/DefaultRouter_v5.js.map +1 -1
- package/lib/defaults/DefaultRouter_v6.js +2 -1
- package/lib/defaults/DefaultRouter_v6.js.map +1 -1
- package/lib/defaults/navigator_v5.js +2 -1
- package/lib/defaults/navigator_v5.js.map +1 -1
- package/lib/defaults/navigator_v6.js +2 -1
- package/lib/defaults/navigator_v6.js.map +1 -1
- package/lib/setters/SetErrors.js +2 -1
- package/lib/setters/SetErrors.js.map +1 -1
- package/lib/setters/SetLayout.js +2 -1
- package/lib/setters/SetLayout.js.map +1 -1
- package/lib/state/createActions.js +2 -1
- package/lib/state/createActions.js.map +1 -1
- package/lib/state/createGlobalState.js +2 -1
- package/lib/state/createGlobalState.js.map +1 -1
- package/lib/state/stateContext.js +2 -1
- package/lib/state/stateContext.js.map +1 -1
- package/lib/state/withApi.js +2 -1
- package/lib/state/withApi.js.map +1 -1
- package/lib/utils/extension.js +2 -1
- package/lib/utils/extension.js.map +1 -1
- package/lib/utils/react.js +2 -1
- package/lib/utils/react.js.map +1 -1
- package/lib/utils/routes.js +3 -4
- package/lib/utils/routes.js.map +1 -1
- package/package.json +4 -4
- package/src/Piral.test.tsx +48 -0
- package/src/RootListener.test.tsx +7 -3
- package/src/actions/app.test.ts +12 -0
- package/src/actions/components.test.ts +11 -0
- package/src/actions/data.test.ts +4 -0
- package/src/actions/define.test.ts +4 -3
- package/src/actions/portal.test.ts +1 -0
- package/src/actions/state.test.ts +4 -3
- package/src/components/ExtensionSlot.test.tsx +19 -4
- package/src/components/ForeignComponentContainer.test.tsx +12 -8
- package/src/components/Mediator.test.tsx +8 -4
- package/src/components/PiralRoutes.test.tsx +16 -2
- package/src/components/PiralView-server.test.tsx +4 -3
- package/src/components/PiralView.test.tsx +11 -3
- package/src/components/ResponsiveLayout.test.tsx +9 -5
- package/src/components/SwitchErrorInfo.test.tsx +15 -4
- package/src/createInstance.test.tsx +14 -0
- package/src/defaults/DefaultErrorInfo.test.tsx +5 -1
- package/src/defaults/DefaultLayout.test.tsx +4 -0
- package/src/defaults/DefaultLoadingIndicator.test.tsx +4 -0
- package/src/helpers.test.tsx +47 -27
- package/src/hooks/action.test.ts +4 -3
- package/src/hooks/actions.test.ts +4 -3
- package/src/hooks/media.test.ts +31 -23
- package/src/hooks/setter-server.test.ts +3 -2
- package/src/hooks/setter.test.ts +5 -1
- package/src/hooks/sharedData.test.ts +11 -8
- package/src/modules/api.test.ts +19 -18
- package/src/modules/core.test.ts +19 -18
- package/src/modules/dependencies.test.ts +1 -0
- package/src/modules/element-server.test.ts +9 -1
- package/src/modules/element.test.ts +11 -0
- package/src/setters/SetComponent.test.tsx +7 -3
- package/src/setters/SetError.test.tsx +7 -3
- package/src/setters/SetErrors.test.tsx +7 -3
- package/src/setters/SetLayout.test.tsx +7 -3
- package/src/setters/SetProvider.test.tsx +7 -3
- package/src/setters/SetRedirect.test.tsx +13 -3
- package/src/setters/SetRoute.test.tsx +7 -3
- package/src/state/createActions.test.ts +12 -1
- package/src/state/createGlobalState.test.ts +35 -59
- package/src/state/withApi.test.tsx +12 -8
- package/src/utils/compare.test.ts +1 -0
- package/src/utils/data.test.ts +5 -0
- package/src/utils/extension.test.tsx +5 -1
- package/src/utils/foreign.test.ts +9 -8
- package/src/utils/guid.test.ts +1 -0
- package/src/utils/helpers.test.ts +14 -13
- package/src/utils/media-server.test.ts +2 -1
- package/src/utils/media.test.ts +19 -11
- package/src/utils/routes.test.ts +1 -0
- package/src/utils/routes.ts +1 -3
- package/src/utils/state.test.ts +7 -6
- package/src/utils/storage.test.ts +9 -4
package/src/helpers.test.tsx
CHANGED
|
@@ -1,14 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
1
4
|
import create from 'zustand';
|
|
5
|
+
import { describe, it, expect, vitest } from 'vitest';
|
|
2
6
|
import { createPiletOptions, PiletOptionsConfig } from './helpers';
|
|
3
7
|
import { globalDependencies } from './modules';
|
|
4
8
|
import { PiletMetadata } from 'piral-base';
|
|
5
9
|
|
|
10
|
+
vitest.mock('../app.codegen', () => ({
|
|
11
|
+
createNavigation: vitest.fn(() => ({
|
|
12
|
+
publicPath: '/',
|
|
13
|
+
})),
|
|
14
|
+
fillDependencies: vitest.fn(),
|
|
15
|
+
integrateDebugger: vitest.fn(),
|
|
16
|
+
integrateEmulator: vitest.fn(),
|
|
17
|
+
publicPath: '/',
|
|
18
|
+
useRouteFilter(routes) {
|
|
19
|
+
return routes;
|
|
20
|
+
},
|
|
21
|
+
createDefaultState() {
|
|
22
|
+
return {};
|
|
23
|
+
},
|
|
24
|
+
}));
|
|
25
|
+
|
|
6
26
|
function createMockApi(meta: PiletMetadata) {
|
|
7
27
|
return {
|
|
8
28
|
meta,
|
|
9
|
-
emit:
|
|
10
|
-
off:
|
|
11
|
-
on:
|
|
29
|
+
emit: vitest.fn(),
|
|
30
|
+
off: vitest.fn(),
|
|
31
|
+
on: vitest.fn(),
|
|
12
32
|
} as any;
|
|
13
33
|
}
|
|
14
34
|
|
|
@@ -25,9 +45,9 @@ function createMockContainer() {
|
|
|
25
45
|
}));
|
|
26
46
|
return {
|
|
27
47
|
context: {
|
|
28
|
-
on:
|
|
29
|
-
off:
|
|
30
|
-
emit:
|
|
48
|
+
on: vitest.fn(),
|
|
49
|
+
off: vitest.fn(),
|
|
50
|
+
emit: vitest.fn(),
|
|
31
51
|
state,
|
|
32
52
|
dispatch(cb) {
|
|
33
53
|
state.setState(cb(state.getState()));
|
|
@@ -56,7 +76,7 @@ describe('Piral-Core helpers module', () => {
|
|
|
56
76
|
process.env.DEBUG_PIRAL = 'true';
|
|
57
77
|
|
|
58
78
|
// Arrange
|
|
59
|
-
const setupMock =
|
|
79
|
+
const setupMock = vitest.fn();
|
|
60
80
|
const globalContext = createMockContainer().context;
|
|
61
81
|
const providedPilets: Array<any> = [
|
|
62
82
|
{
|
|
@@ -75,11 +95,11 @@ describe('Piral-Core helpers module', () => {
|
|
|
75
95
|
const optionsConfig: PiletOptionsConfig = {
|
|
76
96
|
createApi: createMockApi,
|
|
77
97
|
availablePilets: providedPilets,
|
|
78
|
-
shareDependencies:
|
|
98
|
+
shareDependencies: vitest.fn((deps) => deps),
|
|
79
99
|
context: globalContext,
|
|
80
|
-
loadPilet:
|
|
81
|
-
requestPilets:
|
|
82
|
-
strategy:
|
|
100
|
+
loadPilet: vitest.fn(),
|
|
101
|
+
requestPilets: vitest.fn(() => Promise.resolve(providedPilets)),
|
|
102
|
+
strategy: vitest.fn(),
|
|
83
103
|
};
|
|
84
104
|
|
|
85
105
|
// Act
|
|
@@ -95,7 +115,7 @@ describe('Piral-Core helpers module', () => {
|
|
|
95
115
|
|
|
96
116
|
it('createPiletOptions creates the options exposing the global dependencies', () => {
|
|
97
117
|
// Arrange
|
|
98
|
-
const setupMock =
|
|
118
|
+
const setupMock = vitest.fn();
|
|
99
119
|
const globalContext = createMockContainer().context;
|
|
100
120
|
const providedPilets: Array<any> = [
|
|
101
121
|
{
|
|
@@ -115,10 +135,10 @@ describe('Piral-Core helpers module', () => {
|
|
|
115
135
|
createApi: createMockApi,
|
|
116
136
|
availablePilets: providedPilets,
|
|
117
137
|
context: globalContext,
|
|
118
|
-
shareDependencies:
|
|
119
|
-
loadPilet:
|
|
120
|
-
requestPilets:
|
|
121
|
-
strategy:
|
|
138
|
+
shareDependencies: vitest.fn((deps) => deps),
|
|
139
|
+
loadPilet: vitest.fn(),
|
|
140
|
+
requestPilets: vitest.fn(() => Promise.resolve(providedPilets)),
|
|
141
|
+
strategy: vitest.fn(),
|
|
122
142
|
};
|
|
123
143
|
|
|
124
144
|
// Act
|
|
@@ -133,8 +153,8 @@ describe('Piral-Core helpers module', () => {
|
|
|
133
153
|
|
|
134
154
|
// Arrange
|
|
135
155
|
process.env.DEBUG_PIRAL = 'true';
|
|
136
|
-
const setupMock =
|
|
137
|
-
const requestPilets =
|
|
156
|
+
const setupMock = vitest.fn();
|
|
157
|
+
const requestPilets = vitest.fn(() => Promise.resolve(providedPilets));
|
|
138
158
|
const globalContext = createMockContainer().context;
|
|
139
159
|
const providedPilets: Array<any> = [
|
|
140
160
|
{
|
|
@@ -154,10 +174,10 @@ describe('Piral-Core helpers module', () => {
|
|
|
154
174
|
createApi: createMockApi,
|
|
155
175
|
availablePilets: providedPilets,
|
|
156
176
|
context: globalContext,
|
|
157
|
-
shareDependencies:
|
|
158
|
-
loadPilet:
|
|
177
|
+
shareDependencies: vitest.fn((deps) => deps),
|
|
178
|
+
loadPilet: vitest.fn(),
|
|
159
179
|
requestPilets: requestPilets,
|
|
160
|
-
strategy:
|
|
180
|
+
strategy: vitest.fn(),
|
|
161
181
|
};
|
|
162
182
|
|
|
163
183
|
// Act
|
|
@@ -177,8 +197,8 @@ describe('Piral-Core helpers module', () => {
|
|
|
177
197
|
|
|
178
198
|
// Arrange
|
|
179
199
|
process.env.DEBUG_PILET = 'on';
|
|
180
|
-
const setupMock =
|
|
181
|
-
window.fetch =
|
|
200
|
+
const setupMock = vitest.fn();
|
|
201
|
+
window.fetch = vitest.fn((_, options) =>
|
|
182
202
|
Promise.resolve({
|
|
183
203
|
text() {
|
|
184
204
|
return Promise.resolve('This is an example response');
|
|
@@ -188,7 +208,7 @@ describe('Piral-Core helpers module', () => {
|
|
|
188
208
|
},
|
|
189
209
|
}),
|
|
190
210
|
) as any;
|
|
191
|
-
const requestPilets =
|
|
211
|
+
const requestPilets = vitest.fn(() => Promise.resolve(providedPilets));
|
|
192
212
|
const globalContext = createMockContainer().context;
|
|
193
213
|
const providedPilets: Array<any> = [
|
|
194
214
|
{
|
|
@@ -208,10 +228,10 @@ describe('Piral-Core helpers module', () => {
|
|
|
208
228
|
createApi: createMockApi,
|
|
209
229
|
availablePilets: providedPilets,
|
|
210
230
|
context: globalContext,
|
|
211
|
-
shareDependencies:
|
|
212
|
-
loadPilet:
|
|
231
|
+
shareDependencies: vitest.fn((deps) => deps),
|
|
232
|
+
loadPilet: vitest.fn(),
|
|
213
233
|
requestPilets: requestPilets,
|
|
214
|
-
strategy:
|
|
234
|
+
strategy: vitest.fn(),
|
|
215
235
|
};
|
|
216
236
|
|
|
217
237
|
let hasFailed = false;
|
package/src/hooks/action.test.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { describe, it, expect, vitest } from 'vitest';
|
|
1
2
|
import { useAction } from './action';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
vitest.mock('react', () => {
|
|
4
5
|
return {
|
|
5
|
-
createContext:
|
|
6
|
-
useContext: () => ({ foo:
|
|
6
|
+
createContext: vitest.fn(),
|
|
7
|
+
useContext: () => ({ foo: vitest.fn(), bar: vitest.fn() }),
|
|
7
8
|
};
|
|
8
9
|
});
|
|
9
10
|
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { describe, it, expect, vitest } from 'vitest';
|
|
1
2
|
import { useActions } from './actions';
|
|
2
3
|
|
|
3
|
-
const fn =
|
|
4
|
+
const fn = vitest.fn();
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
vitest.mock('react', () => {
|
|
6
7
|
return {
|
|
7
|
-
createContext:
|
|
8
|
+
createContext: vitest.fn(),
|
|
8
9
|
useContext: () => ({ foo: fn, bar: fn, state: {} }),
|
|
9
10
|
};
|
|
10
11
|
});
|
package/src/hooks/media.test.ts
CHANGED
|
@@ -1,39 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
1
4
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
5
|
+
import { describe, it, expect, vitest } from 'vitest';
|
|
3
6
|
|
|
4
|
-
|
|
7
|
+
vitest.mock('react');
|
|
5
8
|
|
|
6
|
-
(React as any).useState = (v) => [v(),
|
|
9
|
+
(React as any).useState = (v) => [v(), vitest.fn()];
|
|
7
10
|
|
|
8
11
|
describe('Media Hook Module', () => {
|
|
9
|
-
it('picks default mode if nothing else if given', () => {
|
|
10
|
-
const usedEffect =
|
|
12
|
+
it('picks default mode if nothing else if given', async () => {
|
|
13
|
+
const usedEffect = vitest.fn();
|
|
11
14
|
(React as any).useEffect = usedEffect;
|
|
12
|
-
window.matchMedia =
|
|
15
|
+
window.matchMedia = vitest.fn((q) => ({ matches: false })) as any;
|
|
16
|
+
const { useMedia } = await import('./media');
|
|
13
17
|
const layout = useMedia(['a', 'b', 'c'], ['mobile', 'tablet', 'desktop'], 'desktop');
|
|
14
18
|
const cleanup = usedEffect.mock.calls[0][0]();
|
|
15
19
|
expect(layout).toBe('desktop');
|
|
16
20
|
cleanup();
|
|
17
21
|
});
|
|
18
22
|
|
|
19
|
-
it('picks first role if already matches', () => {
|
|
20
|
-
const usedEffect =
|
|
23
|
+
it('picks first role if already matches', async () => {
|
|
24
|
+
const usedEffect = vitest.fn();
|
|
21
25
|
(React as any).useEffect = usedEffect;
|
|
22
|
-
window.matchMedia =
|
|
26
|
+
window.matchMedia = vitest.fn((q) => ({ matches: true })) as any;
|
|
27
|
+
const { useMedia } = await import('./media');
|
|
23
28
|
const layout = useMedia(['a', 'b', 'c'], ['mobile', 'tablet', 'desktop'], 'desktop');
|
|
24
29
|
const cleanup = usedEffect.mock.calls[0][0]();
|
|
25
30
|
expect(layout).toBe('mobile');
|
|
26
31
|
cleanup();
|
|
27
32
|
});
|
|
28
33
|
|
|
29
|
-
it('adds up a resize event handler on init', () => {
|
|
30
|
-
const usedEffect =
|
|
34
|
+
it('adds up a resize event handler on init', async () => {
|
|
35
|
+
const usedEffect = vitest.fn();
|
|
31
36
|
const originalAdd = window.addEventListener;
|
|
32
37
|
const originalRemove = window.addEventListener;
|
|
33
38
|
(React as any).useEffect = usedEffect;
|
|
34
|
-
window.addEventListener =
|
|
35
|
-
window.removeEventListener =
|
|
36
|
-
window.matchMedia =
|
|
39
|
+
window.addEventListener = vitest.fn();
|
|
40
|
+
window.removeEventListener = vitest.fn();
|
|
41
|
+
window.matchMedia = vitest.fn((q) => ({ matches: true })) as any;
|
|
42
|
+
const { useMedia } = await import('./media');
|
|
37
43
|
useMedia(['a', 'b', 'c'], ['mobile', 'tablet', 'desktop'], 'desktop');
|
|
38
44
|
expect(window.addEventListener).toHaveBeenCalledTimes(0);
|
|
39
45
|
const cleanup = usedEffect.mock.calls[0][0]();
|
|
@@ -43,14 +49,15 @@ describe('Media Hook Module', () => {
|
|
|
43
49
|
window.removeEventListener = originalRemove;
|
|
44
50
|
});
|
|
45
51
|
|
|
46
|
-
it('cleans up a resize event handler on done', () => {
|
|
47
|
-
const usedEffect =
|
|
52
|
+
it('cleans up a resize event handler on done', async () => {
|
|
53
|
+
const usedEffect = vitest.fn();
|
|
48
54
|
const originalAdd = window.addEventListener;
|
|
49
55
|
const originalRemove = window.addEventListener;
|
|
50
56
|
(React as any).useEffect = usedEffect;
|
|
51
|
-
window.addEventListener =
|
|
52
|
-
window.removeEventListener =
|
|
53
|
-
window.matchMedia =
|
|
57
|
+
window.addEventListener = vitest.fn();
|
|
58
|
+
window.removeEventListener = vitest.fn();
|
|
59
|
+
window.matchMedia = vitest.fn((q) => ({ matches: true })) as any;
|
|
60
|
+
const { useMedia } = await import('./media');
|
|
54
61
|
useMedia(['a', 'b', 'c'], ['mobile', 'tablet', 'desktop'], 'desktop');
|
|
55
62
|
const cleanup = usedEffect.mock.calls[0][0]();
|
|
56
63
|
expect(window.removeEventListener).toHaveBeenCalledTimes(0);
|
|
@@ -60,13 +67,14 @@ describe('Media Hook Module', () => {
|
|
|
60
67
|
window.removeEventListener = originalRemove;
|
|
61
68
|
});
|
|
62
69
|
|
|
63
|
-
it('resize fires the handler', () => {
|
|
64
|
-
const usedEffect =
|
|
65
|
-
const update =
|
|
70
|
+
it('resize fires the handler', async () => {
|
|
71
|
+
const usedEffect = vitest.fn();
|
|
72
|
+
const update = vitest.fn();
|
|
66
73
|
(React as any).useState = (v) => [v(), (k) => update(k())];
|
|
67
74
|
(React as any).useEffect = usedEffect;
|
|
68
75
|
let matcher = (q) => ({ matches: true });
|
|
69
|
-
window.matchMedia =
|
|
76
|
+
window.matchMedia = vitest.fn((q) => matcher(q)) as any;
|
|
77
|
+
const { useMedia } = await import('./media');
|
|
70
78
|
const layout = useMedia(['a', 'b', 'c'], ['mobile', 'tablet', 'desktop'], 'desktop');
|
|
71
79
|
const cleanup = usedEffect.mock.calls[0][0]();
|
|
72
80
|
const event = new Event('resize', { bubbles: true });
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
2
|
+
* @vitest-environment node
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import * as React from 'react';
|
|
6
6
|
import { renderToString } from 'react-dom/server';
|
|
7
|
+
import { describe, it, expect, vitest } from 'vitest';
|
|
7
8
|
import { useSetter } from './setter';
|
|
8
9
|
|
|
9
10
|
describe('UseSetter Hook Module', () => {
|
|
10
11
|
it('UseSetter', () => {
|
|
11
|
-
const cb =
|
|
12
|
+
const cb = vitest.fn();
|
|
12
13
|
|
|
13
14
|
const MyComponent = () => {
|
|
14
15
|
useSetter(cb);
|
package/src/hooks/setter.test.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
1
4
|
import * as React from 'react';
|
|
5
|
+
import { describe, it, expect, vitest } from 'vitest';
|
|
2
6
|
import { render, act } from '@testing-library/react';
|
|
3
7
|
import { useSetter } from './setter';
|
|
4
8
|
|
|
5
9
|
describe('UseSetter Hook Module', () => {
|
|
6
10
|
it('UseSetter', async () => {
|
|
7
|
-
const cb =
|
|
11
|
+
const cb = vitest.fn();
|
|
8
12
|
|
|
9
13
|
const MyComponent = () => {
|
|
10
14
|
useSetter(cb);
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { describe, it, expect, vitest } from 'vitest';
|
|
2
2
|
import { useSharedData } from './sharedData';
|
|
3
3
|
|
|
4
|
-
(globalState
|
|
5
|
-
select
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
vitest.mock('./globalState', () => ({
|
|
5
|
+
useGlobalState(select) {
|
|
6
|
+
return select({
|
|
7
|
+
data: {
|
|
8
|
+
a: 'foo',
|
|
9
|
+
b: 'bar',
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
}));
|
|
11
14
|
|
|
12
15
|
describe('SharedData Module', () => {
|
|
13
16
|
it('selects the corresponding value', () => {
|
package/src/modules/api.test.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { describe, it, expect, vitest } from 'vitest';
|
|
1
2
|
import { createElement, FC } from 'react';
|
|
2
3
|
import { defaultApiFactory } from './api';
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
vitest.mock('../hooks');
|
|
5
6
|
|
|
6
7
|
const StubComponent: FC = (props) => createElement('div', props);
|
|
7
8
|
StubComponent.displayName = 'StubComponent';
|
|
@@ -17,9 +18,9 @@ const moduleMetadata = {
|
|
|
17
18
|
function createMockContainer() {
|
|
18
19
|
return {
|
|
19
20
|
context: {
|
|
20
|
-
on:
|
|
21
|
-
off:
|
|
22
|
-
emit:
|
|
21
|
+
on: vitest.fn(),
|
|
22
|
+
off: vitest.fn(),
|
|
23
|
+
emit: vitest.fn(),
|
|
23
24
|
converters: {},
|
|
24
25
|
apis: {},
|
|
25
26
|
readState() {
|
|
@@ -37,8 +38,8 @@ function createApi(container, apis = []) {
|
|
|
37
38
|
describe('API Module', () => {
|
|
38
39
|
it('defaultApiFactory can register and unregister a page', () => {
|
|
39
40
|
const container = createMockContainer();
|
|
40
|
-
container.context.registerPage =
|
|
41
|
-
container.context.unregisterPage =
|
|
41
|
+
container.context.registerPage = vitest.fn();
|
|
42
|
+
container.context.unregisterPage = vitest.fn();
|
|
42
43
|
const api = createApi(container);
|
|
43
44
|
api.registerPage('/route', StubComponent);
|
|
44
45
|
expect(container.context.registerPage).toHaveBeenCalledTimes(1);
|
|
@@ -50,8 +51,8 @@ describe('API Module', () => {
|
|
|
50
51
|
|
|
51
52
|
it('defaultApiFactory can dispose a registered page', () => {
|
|
52
53
|
const container = createMockContainer();
|
|
53
|
-
container.context.registerPage =
|
|
54
|
-
container.context.unregisterPage =
|
|
54
|
+
container.context.registerPage = vitest.fn();
|
|
55
|
+
container.context.unregisterPage = vitest.fn();
|
|
55
56
|
const api = createApi(container);
|
|
56
57
|
const dispose = api.registerPage('/route', StubComponent);
|
|
57
58
|
expect(container.context.registerPage).toHaveBeenCalledTimes(1);
|
|
@@ -63,8 +64,8 @@ describe('API Module', () => {
|
|
|
63
64
|
|
|
64
65
|
it('defaultApiFactory can register and unregister an extension', () => {
|
|
65
66
|
const container = createMockContainer();
|
|
66
|
-
container.context.registerExtension =
|
|
67
|
-
container.context.unregisterExtension =
|
|
67
|
+
container.context.registerExtension = vitest.fn();
|
|
68
|
+
container.context.unregisterExtension = vitest.fn();
|
|
68
69
|
const api = createApi(container);
|
|
69
70
|
api.registerExtension('ext', StubComponent);
|
|
70
71
|
expect(container.context.registerExtension).toHaveBeenCalledTimes(1);
|
|
@@ -78,8 +79,8 @@ describe('API Module', () => {
|
|
|
78
79
|
|
|
79
80
|
it('defaultApiFactory can dispose an registered extension', () => {
|
|
80
81
|
const container = createMockContainer();
|
|
81
|
-
container.context.registerExtension =
|
|
82
|
-
container.context.unregisterExtension =
|
|
82
|
+
container.context.registerExtension = vitest.fn();
|
|
83
|
+
container.context.unregisterExtension = vitest.fn();
|
|
83
84
|
const api = createApi(container);
|
|
84
85
|
const dispose = api.registerExtension('ext', StubComponent);
|
|
85
86
|
expect(container.context.registerExtension).toHaveBeenCalledTimes(1);
|
|
@@ -93,7 +94,7 @@ describe('API Module', () => {
|
|
|
93
94
|
|
|
94
95
|
it('defaultApiFactory read data by its name', () => {
|
|
95
96
|
const container = createMockContainer();
|
|
96
|
-
container.context.readDataValue =
|
|
97
|
+
container.context.readDataValue = vitest.fn((name) => name);
|
|
97
98
|
const api = createApi(container);
|
|
98
99
|
const result = api.getData('foo');
|
|
99
100
|
expect(result).toBe('foo');
|
|
@@ -102,7 +103,7 @@ describe('API Module', () => {
|
|
|
102
103
|
|
|
103
104
|
it('defaultApiFactory write data without options shall pass, but memory should not emit events', () => {
|
|
104
105
|
const container = createMockContainer();
|
|
105
|
-
container.context.tryWriteDataItem =
|
|
106
|
+
container.context.tryWriteDataItem = vitest.fn(() => true);
|
|
106
107
|
const api = createApi(container);
|
|
107
108
|
api.setData('foo', 5);
|
|
108
109
|
expect(container.context.tryWriteDataItem).toHaveBeenCalled();
|
|
@@ -111,7 +112,7 @@ describe('API Module', () => {
|
|
|
111
112
|
|
|
112
113
|
it('defaultApiFactory write data with empty options shall pass, but memory should not emit events', () => {
|
|
113
114
|
const container = createMockContainer();
|
|
114
|
-
container.context.tryWriteDataItem =
|
|
115
|
+
container.context.tryWriteDataItem = vitest.fn(() => true);
|
|
115
116
|
const api = createApi(container);
|
|
116
117
|
api.setData('foo', 5, {});
|
|
117
118
|
expect(container.context.tryWriteDataItem).toHaveBeenCalled();
|
|
@@ -120,7 +121,7 @@ describe('API Module', () => {
|
|
|
120
121
|
|
|
121
122
|
it('defaultApiFactory write data by the simple option should not pass, never emitting events', () => {
|
|
122
123
|
const container = createMockContainer();
|
|
123
|
-
container.context.tryWriteDataItem =
|
|
124
|
+
container.context.tryWriteDataItem = vitest.fn(() => false);
|
|
124
125
|
const api = createApi(container);
|
|
125
126
|
api.setData('foo', 5, 'remote');
|
|
126
127
|
expect(container.context.tryWriteDataItem).toHaveBeenCalled();
|
|
@@ -129,7 +130,7 @@ describe('API Module', () => {
|
|
|
129
130
|
|
|
130
131
|
it('defaultApiFactory write data by the simple option shall pass with remote', () => {
|
|
131
132
|
const container = createMockContainer();
|
|
132
|
-
container.context.tryWriteDataItem =
|
|
133
|
+
container.context.tryWriteDataItem = vitest.fn(() => true);
|
|
133
134
|
const api = createApi(container);
|
|
134
135
|
api.setData('foo', 5, 'remote');
|
|
135
136
|
expect(container.context.tryWriteDataItem).toHaveBeenCalled();
|
|
@@ -137,7 +138,7 @@ describe('API Module', () => {
|
|
|
137
138
|
|
|
138
139
|
it('defaultApiFactory write data by the object options shall pass with remote', () => {
|
|
139
140
|
const container = createMockContainer();
|
|
140
|
-
container.context.tryWriteDataItem =
|
|
141
|
+
container.context.tryWriteDataItem = vitest.fn(() => true);
|
|
141
142
|
const api = createApi(container);
|
|
142
143
|
api.setData('foo', 15, {
|
|
143
144
|
expires: 10,
|
package/src/modules/core.test.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { describe, it, expect, vitest } from 'vitest';
|
|
1
2
|
import { createElement, FC } from 'react';
|
|
2
3
|
import { createCoreApi } from './core';
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
vitest.mock('../hooks');
|
|
5
6
|
|
|
6
7
|
const StubComponent: FC = (props) => createElement('div', props);
|
|
7
8
|
StubComponent.displayName = 'StubComponent';
|
|
@@ -17,9 +18,9 @@ const moduleMetadata = {
|
|
|
17
18
|
function createMockContainer() {
|
|
18
19
|
return {
|
|
19
20
|
context: {
|
|
20
|
-
on:
|
|
21
|
-
off:
|
|
22
|
-
emit:
|
|
21
|
+
on: vitest.fn(),
|
|
22
|
+
off: vitest.fn(),
|
|
23
|
+
emit: vitest.fn(),
|
|
23
24
|
converters: {},
|
|
24
25
|
readState() {
|
|
25
26
|
return undefined;
|
|
@@ -37,8 +38,8 @@ function createApi(container) {
|
|
|
37
38
|
describe('Core API Module', () => {
|
|
38
39
|
it('createCoreApi can register and unregister a page', () => {
|
|
39
40
|
const container = createMockContainer();
|
|
40
|
-
container.context.registerPage =
|
|
41
|
-
container.context.unregisterPage =
|
|
41
|
+
container.context.registerPage = vitest.fn();
|
|
42
|
+
container.context.unregisterPage = vitest.fn();
|
|
42
43
|
const api = createApi(container);
|
|
43
44
|
api.registerPage('/route', StubComponent);
|
|
44
45
|
expect(container.context.registerPage).toHaveBeenCalledTimes(1);
|
|
@@ -50,8 +51,8 @@ describe('Core API Module', () => {
|
|
|
50
51
|
|
|
51
52
|
it('createCoreApi can dispose a registered page', () => {
|
|
52
53
|
const container = createMockContainer();
|
|
53
|
-
container.context.registerPage =
|
|
54
|
-
container.context.unregisterPage =
|
|
54
|
+
container.context.registerPage = vitest.fn();
|
|
55
|
+
container.context.unregisterPage = vitest.fn();
|
|
55
56
|
const api = createApi(container);
|
|
56
57
|
const dispose = api.registerPage('/route', StubComponent);
|
|
57
58
|
expect(container.context.registerPage).toHaveBeenCalledTimes(1);
|
|
@@ -63,8 +64,8 @@ describe('Core API Module', () => {
|
|
|
63
64
|
|
|
64
65
|
it('createCoreApi can register and unregister an extension', () => {
|
|
65
66
|
const container = createMockContainer();
|
|
66
|
-
container.context.registerExtension =
|
|
67
|
-
container.context.unregisterExtension =
|
|
67
|
+
container.context.registerExtension = vitest.fn();
|
|
68
|
+
container.context.unregisterExtension = vitest.fn();
|
|
68
69
|
const api = createApi(container);
|
|
69
70
|
api.registerExtension('ext', StubComponent);
|
|
70
71
|
expect(container.context.registerExtension).toHaveBeenCalledTimes(1);
|
|
@@ -78,8 +79,8 @@ describe('Core API Module', () => {
|
|
|
78
79
|
|
|
79
80
|
it('createCoreApi can dispose an registered extension', () => {
|
|
80
81
|
const container = createMockContainer();
|
|
81
|
-
container.context.registerExtension =
|
|
82
|
-
container.context.unregisterExtension =
|
|
82
|
+
container.context.registerExtension = vitest.fn();
|
|
83
|
+
container.context.unregisterExtension = vitest.fn();
|
|
83
84
|
const api = createApi(container);
|
|
84
85
|
const dispose = api.registerExtension('ext', StubComponent);
|
|
85
86
|
expect(container.context.registerExtension).toHaveBeenCalledTimes(1);
|
|
@@ -93,7 +94,7 @@ describe('Core API Module', () => {
|
|
|
93
94
|
|
|
94
95
|
it('createCoreApi read data by its name', () => {
|
|
95
96
|
const container = createMockContainer();
|
|
96
|
-
container.context.readDataValue =
|
|
97
|
+
container.context.readDataValue = vitest.fn((name) => name);
|
|
97
98
|
const api = createApi(container);
|
|
98
99
|
const result = api.getData('foo');
|
|
99
100
|
expect(result).toBe('foo');
|
|
@@ -102,7 +103,7 @@ describe('Core API Module', () => {
|
|
|
102
103
|
|
|
103
104
|
it('createCoreApi write data without options shall pass, but memory should not emit events', () => {
|
|
104
105
|
const container = createMockContainer();
|
|
105
|
-
container.context.tryWriteDataItem =
|
|
106
|
+
container.context.tryWriteDataItem = vitest.fn(() => true);
|
|
106
107
|
const api = createApi(container);
|
|
107
108
|
api.setData('foo', 5);
|
|
108
109
|
expect(container.context.tryWriteDataItem).toHaveBeenCalled();
|
|
@@ -111,7 +112,7 @@ describe('Core API Module', () => {
|
|
|
111
112
|
|
|
112
113
|
it('createCoreApi write data with empty options shall pass, but memory should not emit events', () => {
|
|
113
114
|
const container = createMockContainer();
|
|
114
|
-
container.context.tryWriteDataItem =
|
|
115
|
+
container.context.tryWriteDataItem = vitest.fn(() => true);
|
|
115
116
|
const api = createApi(container);
|
|
116
117
|
api.setData('foo', 5, {});
|
|
117
118
|
expect(container.context.tryWriteDataItem).toHaveBeenCalled();
|
|
@@ -120,7 +121,7 @@ describe('Core API Module', () => {
|
|
|
120
121
|
|
|
121
122
|
it('createCoreApi write data by the simple option should not pass, never emitting events', () => {
|
|
122
123
|
const container = createMockContainer();
|
|
123
|
-
container.context.tryWriteDataItem =
|
|
124
|
+
container.context.tryWriteDataItem = vitest.fn(() => false);
|
|
124
125
|
const api = createApi(container);
|
|
125
126
|
api.setData('foo', 5, 'remote');
|
|
126
127
|
expect(container.context.tryWriteDataItem).toHaveBeenCalled();
|
|
@@ -129,7 +130,7 @@ describe('Core API Module', () => {
|
|
|
129
130
|
|
|
130
131
|
it('createCoreApi write data by the simple option shall pass with remote', () => {
|
|
131
132
|
const container = createMockContainer();
|
|
132
|
-
container.context.tryWriteDataItem =
|
|
133
|
+
container.context.tryWriteDataItem = vitest.fn(() => true);
|
|
133
134
|
const api = createApi(container);
|
|
134
135
|
api.setData('foo', 5, 'remote');
|
|
135
136
|
expect(container.context.tryWriteDataItem).toHaveBeenCalled();
|
|
@@ -137,7 +138,7 @@ describe('Core API Module', () => {
|
|
|
137
138
|
|
|
138
139
|
it('createCoreApi write data by the object options shall pass with remote', () => {
|
|
139
140
|
const container = createMockContainer();
|
|
140
|
-
container.context.tryWriteDataItem =
|
|
141
|
+
container.context.tryWriteDataItem = vitest.fn(() => true);
|
|
141
142
|
const api = createApi(container);
|
|
142
143
|
api.setData('foo', 15, {
|
|
143
144
|
expires: 10,
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
2
|
+
* @vitest-environment node
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import create from 'zustand';
|
|
6
|
+
import { describe, it, expect, vitest } from 'vitest';
|
|
6
7
|
import { createListener } from 'piral-base';
|
|
7
8
|
import { createActions } from '../state';
|
|
8
9
|
import { renderElement } from './element';
|
|
9
10
|
|
|
11
|
+
vitest.mock('../../app.codegen', () => ({
|
|
12
|
+
createNavigation: vitest.fn(publicPath => ({
|
|
13
|
+
publicPath,
|
|
14
|
+
})),
|
|
15
|
+
publicPath: '/',
|
|
16
|
+
}));
|
|
17
|
+
|
|
10
18
|
function createMockContext(): [any, any] {
|
|
11
19
|
const state: any = create(() => ({
|
|
12
20
|
portals: {
|
|
@@ -1,8 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
1
4
|
import create from 'zustand';
|
|
5
|
+
import { describe, it, expect, vitest } from 'vitest';
|
|
2
6
|
import { createListener } from 'piral-base';
|
|
3
7
|
import { createActions } from '../state';
|
|
4
8
|
import { renderElement } from './element';
|
|
5
9
|
|
|
10
|
+
vitest.mock('../../app.codegen', () => ({
|
|
11
|
+
createNavigation: vitest.fn(publicPath => ({
|
|
12
|
+
publicPath,
|
|
13
|
+
})),
|
|
14
|
+
publicPath: '/',
|
|
15
|
+
}));
|
|
16
|
+
|
|
6
17
|
function createMockContext(): [any, any] {
|
|
7
18
|
const state: any = create(() => ({
|
|
8
19
|
portals: {},
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
1
4
|
import * as React from 'react';
|
|
2
5
|
import create from 'zustand';
|
|
6
|
+
import { describe, it, expect, vitest } from 'vitest';
|
|
3
7
|
import { render } from '@testing-library/react';
|
|
4
8
|
import { SetComponent } from './SetComponent';
|
|
5
9
|
import { StateContext } from '../state';
|
|
@@ -13,9 +17,9 @@ function createMockContainer() {
|
|
|
13
17
|
}));
|
|
14
18
|
return {
|
|
15
19
|
context: {
|
|
16
|
-
on:
|
|
17
|
-
off:
|
|
18
|
-
emit:
|
|
20
|
+
on: vitest.fn(),
|
|
21
|
+
off: vitest.fn(),
|
|
22
|
+
emit: vitest.fn(),
|
|
19
23
|
state,
|
|
20
24
|
setComponent(name, comp) {
|
|
21
25
|
const s = state.getState();
|