@we-debug/core 0.49.2 → 0.51.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/CHANGELOG.md +30 -0
- package/dist/api/apiview.d.ts +7 -0
- package/dist/api/apiview.js +47 -0
- package/dist/api/cache.js +2 -1
- package/dist/api/init.js +4 -0
- package/dist/api/launcher.d.ts +7 -0
- package/dist/api/launcher.js +55 -0
- package/dist/api/network.js +15 -0
- package/dist/api/networkview.d.ts +7 -0
- package/dist/api/networkview.js +47 -0
- package/dist/api/ui.d.ts +24 -0
- package/dist/api/ui.js +196 -0
- package/dist/base/cache.js +10 -7
- package/dist/index.d.ts +46 -5
- package/dist/index.js +72 -1
- package/dist/model/apiview.d.ts +9 -0
- package/dist/model/apiview.js +44 -0
- package/dist/model/badge.d.ts +2 -1
- package/dist/model/badge.js +1 -0
- package/dist/model/index.d.ts +4 -0
- package/dist/model/index.js +4 -0
- package/dist/model/networkview.d.ts +9 -0
- package/dist/model/networkview.js +44 -0
- package/dist/model/overlay.d.ts +10 -0
- package/dist/model/overlay.js +45 -0
- package/dist/model/panelview.d.ts +13 -0
- package/dist/model/panelview.js +48 -0
- package/dist/store/index.d.ts +4 -1
- package/dist/store/index.js +3 -0
- package/dist/store/sys.js +2 -1
- package/dist/types.d.ts +85 -0
- package/dist/utils/silent.d.ts +2 -0
- package/dist/utils/silent.js +18 -0
- package/dist/version.js +1 -1
- package/package.json +17 -10
- package/test/ui.test.ts +151 -0
package/dist/types.d.ts
CHANGED
|
@@ -42,6 +42,10 @@ export interface IBadgeManageConstructorOption extends IBaseManageConstructorOpt
|
|
|
42
42
|
position?: IPosition;
|
|
43
43
|
styles?: string;
|
|
44
44
|
textOnly?: boolean;
|
|
45
|
+
type?: 'default' | 'launcher';
|
|
46
|
+
}
|
|
47
|
+
export interface ILauncherDotOption {
|
|
48
|
+
group?: string;
|
|
45
49
|
}
|
|
46
50
|
export type FormRuleType = 'button' | 'arrow' | 'switch';
|
|
47
51
|
export interface IFormRuleManageConstructorOption extends IBaseManageConstructorOption {
|
|
@@ -59,6 +63,40 @@ export interface IJsonViewManagerConstructorOption extends IBaseManageConstructo
|
|
|
59
63
|
export interface ITableViewManagerConstructorOption extends IBaseManageConstructorOption {
|
|
60
64
|
data?: IAnyObject;
|
|
61
65
|
}
|
|
66
|
+
export interface INetworkViewHandler extends IBaseModelHandler {
|
|
67
|
+
getRecords?: () => IAnyObject[];
|
|
68
|
+
bindClear?: () => any;
|
|
69
|
+
bindRecordChange?: (recording: boolean) => any;
|
|
70
|
+
bindPreserveLogChange?: (preserveLog: boolean) => any;
|
|
71
|
+
getState?: () => {
|
|
72
|
+
recording: boolean;
|
|
73
|
+
preserveLog: boolean;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
export interface INetworkViewManagerConstructorOption extends IBaseManageConstructorOption {
|
|
77
|
+
handler: INetworkViewHandler;
|
|
78
|
+
}
|
|
79
|
+
export type INetworkViewGroup = IGroupOption;
|
|
80
|
+
export interface IAddNetworkViewOption {
|
|
81
|
+
group?: INetworkViewGroup;
|
|
82
|
+
}
|
|
83
|
+
export interface IApiViewHandler extends IBaseModelHandler {
|
|
84
|
+
getRecords?: () => IAnyObject[];
|
|
85
|
+
bindClear?: () => any;
|
|
86
|
+
bindRecordChange?: (recording: boolean) => any;
|
|
87
|
+
bindPreserveLogChange?: (preserveLog: boolean) => any;
|
|
88
|
+
getState?: () => {
|
|
89
|
+
recording: boolean;
|
|
90
|
+
preserveLog: boolean;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
export interface IApiViewManagerConstructorOption extends IBaseManageConstructorOption {
|
|
94
|
+
handler: IApiViewHandler;
|
|
95
|
+
}
|
|
96
|
+
export type IApiViewGroup = IGroupOption;
|
|
97
|
+
export interface IAddApiViewOption {
|
|
98
|
+
group?: IApiViewGroup;
|
|
99
|
+
}
|
|
62
100
|
export type compareFn = (a: string, b: string) => number;
|
|
63
101
|
export type WxKey = keyof WechatMiniprogram.Wx;
|
|
64
102
|
export type GetBridgeInfoFunc = ((key: string, callback: (...args: any[]) => any) => void) & {
|
|
@@ -84,6 +122,7 @@ export interface IWedebugInitOption {
|
|
|
84
122
|
launcher?: IAnyObject;
|
|
85
123
|
plugin?: {
|
|
86
124
|
network?: IAnyObject;
|
|
125
|
+
api?: IAnyObject;
|
|
87
126
|
error?: IAnyObject;
|
|
88
127
|
router?: IAnyObject;
|
|
89
128
|
uiCheck?: IAnyObject;
|
|
@@ -94,3 +133,49 @@ export interface IWedebugInitOption {
|
|
|
94
133
|
export interface IPluginInstance<T extends IAnyObject = IAnyObject> {
|
|
95
134
|
install(weDebug: T, ...args: any[]): void;
|
|
96
135
|
}
|
|
136
|
+
export interface IUIManifest {
|
|
137
|
+
npmDirname: string;
|
|
138
|
+
packages: {
|
|
139
|
+
[pkg: string]: {
|
|
140
|
+
components: {
|
|
141
|
+
[name: string]: string;
|
|
142
|
+
};
|
|
143
|
+
pages: string[];
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
export interface IPanelViewConstructorOption {
|
|
148
|
+
key: string;
|
|
149
|
+
componentId: string;
|
|
150
|
+
title: string;
|
|
151
|
+
props?: IAnyObject;
|
|
152
|
+
}
|
|
153
|
+
export interface IAddPanelViewOption {
|
|
154
|
+
group?: IGroupOption;
|
|
155
|
+
}
|
|
156
|
+
export interface IUpdatePanelViewOption {
|
|
157
|
+
title?: string;
|
|
158
|
+
props?: IAnyObject;
|
|
159
|
+
}
|
|
160
|
+
export interface IOverlayConstructorOption {
|
|
161
|
+
key: string;
|
|
162
|
+
componentId: string;
|
|
163
|
+
props?: IAnyObject;
|
|
164
|
+
}
|
|
165
|
+
export interface IScopePanelOption {
|
|
166
|
+
component: string;
|
|
167
|
+
title: string;
|
|
168
|
+
props?: IAnyObject;
|
|
169
|
+
}
|
|
170
|
+
export interface IScopeOverlayOption {
|
|
171
|
+
component: string;
|
|
172
|
+
props?: IAnyObject;
|
|
173
|
+
}
|
|
174
|
+
export interface IScopeNavigateOption {
|
|
175
|
+
events?: IAnyObject;
|
|
176
|
+
}
|
|
177
|
+
export interface IPageOverlay {
|
|
178
|
+
overlayId: number;
|
|
179
|
+
componentId: string;
|
|
180
|
+
props: IAnyObject;
|
|
181
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isSilent = exports.silent = void 0;
|
|
4
|
+
var depth = 0;
|
|
5
|
+
function silent(fn) {
|
|
6
|
+
depth++;
|
|
7
|
+
try {
|
|
8
|
+
return fn();
|
|
9
|
+
}
|
|
10
|
+
finally {
|
|
11
|
+
depth--;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.silent = silent;
|
|
15
|
+
function isSilent() {
|
|
16
|
+
return depth > 0;
|
|
17
|
+
}
|
|
18
|
+
exports.isSilent = isSilent;
|
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@we-debug/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.51.0",
|
|
4
4
|
"description": "a useful debug tool for weapp",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "dlhandsome"
|
|
@@ -20,17 +20,24 @@
|
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
"preset": "ts-jest",
|
|
23
|
-
"testEnvironment": "node"
|
|
23
|
+
"testEnvironment": "node",
|
|
24
|
+
"moduleNameMapper": {
|
|
25
|
+
"^@we-debug/core$": "<rootDir>/src/index.ts"
|
|
26
|
+
},
|
|
27
|
+
"globals": {
|
|
28
|
+
"__VERSION__": "test"
|
|
29
|
+
}
|
|
24
30
|
},
|
|
25
31
|
"license": "MIT",
|
|
26
32
|
"dependencies": {
|
|
27
|
-
"@we-debug/plugin-
|
|
28
|
-
"@we-debug/plugin-
|
|
29
|
-
"@we-debug/plugin-
|
|
30
|
-
"@we-debug/plugin-
|
|
31
|
-
"@we-debug/plugin-
|
|
32
|
-
"@we-debug/plugin-
|
|
33
|
-
"@we-debug/plugin-
|
|
33
|
+
"@we-debug/plugin-api": "0.51.0",
|
|
34
|
+
"@we-debug/plugin-appdata": "0.51.0",
|
|
35
|
+
"@we-debug/plugin-error": "0.51.0",
|
|
36
|
+
"@we-debug/plugin-launcher": "0.51.0",
|
|
37
|
+
"@we-debug/plugin-network": "0.51.0",
|
|
38
|
+
"@we-debug/plugin-router": "0.51.0",
|
|
39
|
+
"@we-debug/plugin-storage": "0.51.0",
|
|
40
|
+
"@we-debug/plugin-ui-check": "0.51.0",
|
|
34
41
|
"deepmerge": "^4.2.2"
|
|
35
42
|
},
|
|
36
43
|
"readme": "ERROR: No README data found!",
|
|
@@ -40,5 +47,5 @@
|
|
|
40
47
|
"@types/jest": "^29.5.11",
|
|
41
48
|
"ts-jest": "^29.1.1"
|
|
42
49
|
},
|
|
43
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "22641ac4972a154619c6dc8f44b1bfdcbb92c8eb"
|
|
44
51
|
}
|
package/test/ui.test.ts
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import './wx';
|
|
2
|
+
import Debug from '../src/index';
|
|
3
|
+
|
|
4
|
+
const manifest = {
|
|
5
|
+
npmDirname: 'miniprogram_npm',
|
|
6
|
+
packages: {
|
|
7
|
+
'demo-plugin': {
|
|
8
|
+
components: { panel: 'c0', cashier: 'c1' },
|
|
9
|
+
pages: ['pages/feedback/index']
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
let currentPageId = 'pageId:1';
|
|
15
|
+
(global as any).getCurrentPages = () => [{ getPageId: () => currentPageId }];
|
|
16
|
+
|
|
17
|
+
test('warns once when manifest is missing', () => {
|
|
18
|
+
const warn = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
|
19
|
+
const error = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
20
|
+
const ui = Debug.scope('demo-plugin');
|
|
21
|
+
ui.createPanel({ component: 'panel', title: 'A' });
|
|
22
|
+
ui.createOverlay({ component: 'cashier' });
|
|
23
|
+
expect(warn).toHaveBeenCalledTimes(1);
|
|
24
|
+
expect(error).not.toHaveBeenCalled();
|
|
25
|
+
warn.mockRestore();
|
|
26
|
+
error.mockRestore();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe('with manifest', () => {
|
|
30
|
+
let ui: ReturnType<typeof Debug.scope>;
|
|
31
|
+
|
|
32
|
+
beforeAll(() => {
|
|
33
|
+
Debug.registerUIManifest(manifest);
|
|
34
|
+
ui = Debug.scope('demo-plugin');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('unknown component logs declared components and is not added', () => {
|
|
38
|
+
const error = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
39
|
+
const panel = ui.createPanel({ component: 'missing', title: 'X' });
|
|
40
|
+
expect(panel.componentId).toBe('');
|
|
41
|
+
expect(error.mock.calls[0][0]).toContain('panel, cashier');
|
|
42
|
+
ui.addPanel(panel);
|
|
43
|
+
expect(Debug.store.panelviews.get()).not.toContain(panel);
|
|
44
|
+
error.mockRestore();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('panel add, update and remove within its group', () => {
|
|
48
|
+
const updates = jest.fn();
|
|
49
|
+
Debug.event.on('panelview:update', updates);
|
|
50
|
+
const panel = ui.createPanel({ component: 'panel', title: 'Mock', props: { n: 1 } });
|
|
51
|
+
expect(panel.key).toBe('demo-plugin/panel');
|
|
52
|
+
expect(panel.componentId).toBe('c0');
|
|
53
|
+
ui.addPanel(panel);
|
|
54
|
+
expect(Debug.store.group.get('Mock').get()).toContain(panel);
|
|
55
|
+
ui.updatePanel(panel, { props: { n: 2 } });
|
|
56
|
+
expect(panel.props).toEqual({ n: 2 });
|
|
57
|
+
ui.removePanel(panel);
|
|
58
|
+
expect(Debug.store.group.get('Mock').get()).not.toContain(panel);
|
|
59
|
+
expect(updates).toHaveBeenCalledTimes(3);
|
|
60
|
+
Debug.event.off('panelview:update', updates);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('adding the same panel twice does not leave a duplicate', () => {
|
|
64
|
+
const panel = ui.createPanel({ component: 'panel', title: 'Duplicate' });
|
|
65
|
+
ui.addPanel(panel);
|
|
66
|
+
ui.addPanel(panel);
|
|
67
|
+
ui.removePanel(panel);
|
|
68
|
+
expect(Debug.store.panelviews.get()).not.toContain(panel);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('moving a panel between groups removes it from the old group', () => {
|
|
72
|
+
const panel = ui.createPanel({ component: 'panel', title: 'Movable' });
|
|
73
|
+
ui.addPanel(panel, { group: { name: 'A' } });
|
|
74
|
+
ui.addPanel(panel, { group: { name: 'B' } });
|
|
75
|
+
ui.removePanel(panel);
|
|
76
|
+
expect(Debug.store.group.get('A').get()).not.toContain(panel);
|
|
77
|
+
expect(Debug.store.group.get('B').get()).not.toContain(panel);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('overlay is scoped to the page and resolves with close result', async () => {
|
|
81
|
+
currentPageId = 'pageId:1';
|
|
82
|
+
const overlay = ui.createOverlay({ component: 'cashier' });
|
|
83
|
+
const promise = ui.showOverlay(overlay, { amount: 1 });
|
|
84
|
+
expect(Debug.getPageOverlays('pageId:1')).toEqual([{ overlayId: overlay.id, componentId: 'c1', props: { amount: 1 } }]);
|
|
85
|
+
expect(Debug.getPageOverlays('pageId:2')).toEqual([]);
|
|
86
|
+
expect(ui.showOverlay(overlay, { amount: 2 })).toBe(promise);
|
|
87
|
+
expect(Debug.getPageOverlays('pageId:1')[0].props).toEqual({ amount: 2 });
|
|
88
|
+
Debug.closeOverlay('pageId:1', 'c1', { paid: true });
|
|
89
|
+
await expect(promise).resolves.toEqual({ paid: true });
|
|
90
|
+
expect(Debug.getPageOverlays('pageId:1')).toEqual([]);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test('hide, replace and page release resolve undefined', async () => {
|
|
94
|
+
currentPageId = 'pageId:3';
|
|
95
|
+
const a = ui.createOverlay({ component: 'cashier' });
|
|
96
|
+
const b = ui.createOverlay({ component: 'cashier' });
|
|
97
|
+
const pa = ui.showOverlay(a);
|
|
98
|
+
const pb = ui.showOverlay(b);
|
|
99
|
+
await expect(pa).resolves.toBeUndefined();
|
|
100
|
+
ui.hideOverlay(b);
|
|
101
|
+
await expect(pb).resolves.toBeUndefined();
|
|
102
|
+
const pc = ui.showOverlay(a);
|
|
103
|
+
const updates = jest.fn();
|
|
104
|
+
Debug.event.on('overlay:update', updates);
|
|
105
|
+
Debug.releasePageOverlays('pageId:3');
|
|
106
|
+
await expect(pc).resolves.toBeUndefined();
|
|
107
|
+
expect(Debug.getPageOverlays('pageId:3')).toEqual([]);
|
|
108
|
+
expect(updates).toHaveBeenCalledTimes(1);
|
|
109
|
+
Debug.event.off('overlay:update', updates);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test('the same overlay can be shown independently on another page', () => {
|
|
113
|
+
currentPageId = 'pageId:A';
|
|
114
|
+
const overlay = ui.createOverlay({ component: 'cashier' });
|
|
115
|
+
const first = ui.showOverlay(overlay);
|
|
116
|
+
currentPageId = 'pageId:B';
|
|
117
|
+
const second = ui.showOverlay(overlay);
|
|
118
|
+
expect(second).not.toBe(first);
|
|
119
|
+
expect(Debug.getPageOverlays('pageId:B')).toEqual([
|
|
120
|
+
{ overlayId: overlay.id, componentId: 'c1', props: {} }
|
|
121
|
+
]);
|
|
122
|
+
Debug.releasePageOverlays('pageId:A');
|
|
123
|
+
Debug.releasePageOverlays('pageId:B');
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test('navigateTo builds the npm page url and rejects undeclared pages', async () => {
|
|
127
|
+
const navigateTo = jest.fn((opt: any) => opt.success({}));
|
|
128
|
+
(global as any).wx.navigateTo = navigateTo;
|
|
129
|
+
await ui.navigateTo('pages/feedback/index', { from: 'panel', omitted: undefined, n: 1 });
|
|
130
|
+
expect(navigateTo.mock.calls[0][0].url).toBe('/miniprogram_npm/demo-plugin/pages/feedback/index?from=panel&n=1');
|
|
131
|
+
const error = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
132
|
+
await expect(ui.navigateTo('pages/none/index')).resolves.toBeUndefined();
|
|
133
|
+
expect(navigateTo).toHaveBeenCalledTimes(1);
|
|
134
|
+
error.mockRestore();
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test('navigateTo resolves undefined when wx.navigateTo throws', async () => {
|
|
138
|
+
const error = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
139
|
+
(global as any).wx.navigateTo = () => {
|
|
140
|
+
throw new Error('navigate failed');
|
|
141
|
+
};
|
|
142
|
+
await expect(ui.navigateTo('pages/feedback/index')).resolves.toBeUndefined();
|
|
143
|
+
expect(error).toHaveBeenCalled();
|
|
144
|
+
error.mockRestore();
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test('createCache prefixes the package name', () => {
|
|
148
|
+
const cache: any = ui.createCache('config');
|
|
149
|
+
expect(cache.key).toBe('demo-plugin:config');
|
|
150
|
+
});
|
|
151
|
+
});
|