@mpcore/test 1.1.0 → 1.2.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/dist/index.d.mts +0 -20
- package/dist/index.mjs +14 -28
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { HeadlessSession, HeadlessTestingLogicalNode, HeadlessTestingPageHandle, HeadlessTestingPageSnapshot, HeadlessWxActionSheetMockDefinition, HeadlessWxDownloadFileMockDefinition, HeadlessWxModalMockDefinition, HeadlessWxRequestMockDefinition, HeadlessWxUploadFileMockDefinition, PlatformAdapter, RuntimeDiagnosticEntry, wechat } from "@mpcore/simulator";
|
|
2
|
-
//#region src/screen/helpers.d.ts
|
|
3
2
|
type TextMatcher = string | RegExp;
|
|
4
3
|
interface RoleQueryOptions {
|
|
5
4
|
name?: TextMatcher;
|
|
6
5
|
}
|
|
7
|
-
//#endregion
|
|
8
|
-
//#region src/screen/node.d.ts
|
|
9
6
|
export declare class MiniProgramNode {
|
|
10
7
|
private readonly owner;
|
|
11
8
|
readonly nodeId: string;
|
|
@@ -25,8 +22,6 @@ export declare class MiniProgramNode {
|
|
|
25
22
|
/** 返回当前节点的稳定语义树,卸载后的节点不能生成快照。 */
|
|
26
23
|
snapshot(): MiniProgramTreeSnapshot;
|
|
27
24
|
}
|
|
28
|
-
//#endregion
|
|
29
|
-
//#region src/screen/index.d.ts
|
|
30
25
|
export declare class MiniProgramScreen {
|
|
31
26
|
private readonly page;
|
|
32
27
|
private snapshotStore;
|
|
@@ -72,8 +67,6 @@ export declare class MiniProgramScreen {
|
|
|
72
67
|
$(selector: string): Promise<import("@mpcore/simulator").HeadlessTestingNodeHandle | null>;
|
|
73
68
|
$$(selector: string): Promise<import("@mpcore/simulator").HeadlessTestingNodeHandle[]>;
|
|
74
69
|
}
|
|
75
|
-
//#endregion
|
|
76
|
-
//#region src/user.d.ts
|
|
77
70
|
export declare class MiniProgramUser {
|
|
78
71
|
private readonly page;
|
|
79
72
|
private readonly screen;
|
|
@@ -87,8 +80,6 @@ export declare class MiniProgramUser {
|
|
|
87
80
|
blur(node: MiniProgramNode, value?: string, event?: Record<string, any>): Promise<void>;
|
|
88
81
|
trigger(node: MiniProgramNode, eventName: string, event?: Record<string, any>): Promise<void>;
|
|
89
82
|
}
|
|
90
|
-
//#endregion
|
|
91
|
-
//#region src/types.d.ts
|
|
92
83
|
export interface MiniProgramArtifact {
|
|
93
84
|
appConfigPath?: string;
|
|
94
85
|
miniprogramRootPath?: string;
|
|
@@ -151,12 +142,8 @@ export interface MiniProgramMatcherResult {
|
|
|
151
142
|
pass: boolean;
|
|
152
143
|
}
|
|
153
144
|
export type MiniProgramNodeLike = MiniProgramNode;
|
|
154
|
-
//#endregion
|
|
155
|
-
//#region src/host.d.ts
|
|
156
145
|
export declare function createWxMock(definition?: WxHostMock): WxHostMock;
|
|
157
146
|
export declare function applyWxMock(session: HeadlessSession, definition?: WxHostMock): void;
|
|
158
|
-
//#endregion
|
|
159
|
-
//#region src/matchers.d.ts
|
|
160
147
|
export declare function toBeInTheMiniProgram(node: MiniProgramNode): MiniProgramMatcherResult;
|
|
161
148
|
export declare function toHaveTextContent(node: MiniProgramNode, expected: string | RegExp): MiniProgramMatcherResult;
|
|
162
149
|
export declare function toHaveEmitted(source: MiniProgramEmissionSource, eventName: string, expected?: unknown): MiniProgramMatcherResult;
|
|
@@ -169,8 +156,6 @@ export declare const mpcoreMatchers: {
|
|
|
169
156
|
toHaveEmitted: typeof toHaveEmitted;
|
|
170
157
|
toHaveTextContent: typeof toHaveTextContent;
|
|
171
158
|
};
|
|
172
|
-
//#endregion
|
|
173
|
-
//#region src/project.d.ts
|
|
174
159
|
export declare class MiniProgramTestProject {
|
|
175
160
|
private readonly options;
|
|
176
161
|
private readonly baseProject;
|
|
@@ -185,8 +170,6 @@ export declare function artifactFromProject(projectPath: string): {
|
|
|
185
170
|
projectPath: string;
|
|
186
171
|
};
|
|
187
172
|
export declare function createTestProject(options: CreateTestProjectOptions): MiniProgramTestProject;
|
|
188
|
-
//#endregion
|
|
189
|
-
//#region src/snapshot/tree.d.ts
|
|
190
173
|
interface MiniProgramElementSnapshot {
|
|
191
174
|
attributes: Record<string, string>;
|
|
192
175
|
children: MiniProgramTreeSnapshot[];
|
|
@@ -196,8 +179,6 @@ interface MiniProgramTextSnapshot {
|
|
|
196
179
|
text: string;
|
|
197
180
|
}
|
|
198
181
|
type MiniProgramTreeSnapshot = MiniProgramElementSnapshot | MiniProgramTextSnapshot;
|
|
199
|
-
//#endregion
|
|
200
|
-
//#region src/snapshot/index.d.ts
|
|
201
182
|
export type MiniProgramSnapshotSource = MiniProgramScreen | MiniProgramNode | HeadlessTestingPageSnapshot;
|
|
202
183
|
/** 将查询对象或完整诊断快照显式转换为适合稳定断言的语义树。 */
|
|
203
184
|
export declare function toMiniProgramSnapshot(source: MiniProgramSnapshotSource): MiniProgramTreeSnapshot;
|
|
@@ -206,5 +187,4 @@ export declare const mpcoreSnapshotSerializer: {
|
|
|
206
187
|
test(value: unknown): value is MiniProgramScreen | MiniProgramNode;
|
|
207
188
|
serialize(value: MiniProgramScreen | MiniProgramNode): string;
|
|
208
189
|
};
|
|
209
|
-
//#endregion
|
|
210
190
|
export { type MiniProgramElementSnapshot, type MiniProgramTextSnapshot, type MiniProgramTreeSnapshot, type RoleQueryOptions, type TextMatcher, wechat };
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HeadlessTestingPageHandle, createArtifactProject, createHeadlessSession, createMemoryArtifactSource, createOverlayArtifactSource, createProjectDescriptor, loadProject, wechat, wechat as wechat$1 } from "@mpcore/simulator";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
|
|
3
|
+
// src/host.ts
|
|
4
4
|
function asList(value) {
|
|
5
5
|
if (!value) return [];
|
|
6
6
|
return Array.isArray(value) ? value : [value];
|
|
@@ -15,8 +15,7 @@ function applyWxMock(session, definition = {}) {
|
|
|
15
15
|
asList(definition.request).forEach((item) => session.mockRequest(item));
|
|
16
16
|
asList(definition.uploadFile).forEach((item) => session.mockUploadFile(item));
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
//#region src/matchers.ts
|
|
18
|
+
// src/matchers.ts
|
|
20
19
|
function toBeInTheMiniProgram(node) {
|
|
21
20
|
const pass = node?.isConnected === true;
|
|
22
21
|
return {
|
|
@@ -60,8 +59,7 @@ const mpcoreMatchers = {
|
|
|
60
59
|
toHaveEmitted,
|
|
61
60
|
toHaveTextContent
|
|
62
61
|
};
|
|
63
|
-
|
|
64
|
-
//#region src/componentHarness/data.ts
|
|
62
|
+
// src/componentHarness/data.ts
|
|
65
63
|
/** 在测试 API 边界复制 JSON 数据,避免调用方引用进入 runtime。 */
|
|
66
64
|
function serializeComponentData(value, label) {
|
|
67
65
|
try {
|
|
@@ -76,8 +74,7 @@ function serializeComponentData(value, label) {
|
|
|
76
74
|
function cloneComponentData(value, label) {
|
|
77
75
|
return JSON.parse(serializeComponentData(value, label));
|
|
78
76
|
}
|
|
79
|
-
|
|
80
|
-
//#region src/overrides/index.ts
|
|
77
|
+
// src/overrides/index.ts
|
|
81
78
|
function normalizeComponentPath(componentPath) {
|
|
82
79
|
const relativePath = componentPath.trim().replaceAll("\\", "/").replace(/^\/+/, "");
|
|
83
80
|
const normalized = path.posix.normalize(relativePath.replace(/\.(?:js|json|wxml)$/, ""));
|
|
@@ -124,8 +121,7 @@ function createComponentOverrides(project, overrides = {}) {
|
|
|
124
121
|
}
|
|
125
122
|
};
|
|
126
123
|
}
|
|
127
|
-
|
|
128
|
-
//#region src/componentHarness/host.ts
|
|
124
|
+
// src/componentHarness/host.ts
|
|
129
125
|
const COMPONENT_HOST_ROUTE = "mpcore-test/component-host/index";
|
|
130
126
|
const COMPONENT_SUBJECT_SELECTOR = "#mpcore-subject";
|
|
131
127
|
function createSlotMarkup(slots) {
|
|
@@ -175,8 +171,7 @@ function createComponentHostProject(project, componentPath, options, events) {
|
|
|
175
171
|
})
|
|
176
172
|
};
|
|
177
173
|
}
|
|
178
|
-
|
|
179
|
-
//#region src/componentHarness/index.ts
|
|
174
|
+
// src/componentHarness/index.ts
|
|
180
175
|
/** 复用宿主会话更新与移除真实组件,不重新构造主体实例。 */
|
|
181
176
|
function createComponentRenderResult(base, session, settle, host, events) {
|
|
182
177
|
let mounted = true;
|
|
@@ -235,8 +230,7 @@ function createComponentRenderResult(base, session, settle, host, events) {
|
|
|
235
230
|
}
|
|
236
231
|
});
|
|
237
232
|
}
|
|
238
|
-
|
|
239
|
-
//#region src/componentHarness/events.ts
|
|
233
|
+
// src/componentHarness/events.ts
|
|
240
234
|
/** 将事件订阅映射到宿主声明绑定,不拦截组件 triggerEvent。 */
|
|
241
235
|
function createComponentEvents(options = {}) {
|
|
242
236
|
const subscriptions = /* @__PURE__ */ new Map();
|
|
@@ -296,8 +290,7 @@ function createComponentEvents(options = {}) {
|
|
|
296
290
|
}
|
|
297
291
|
};
|
|
298
292
|
}
|
|
299
|
-
|
|
300
|
-
//#region src/snapshot/tree.ts
|
|
293
|
+
// src/snapshot/tree.ts
|
|
301
294
|
const EVENT_ATTRIBUTE = /^(?:(?:capture-)?(?:bind|catch)|mut-bind)(?::[\w:.-]+|\w+)$/;
|
|
302
295
|
const SCOPED_STYLE_ATTRIBUTE = /^data-v-[a-f\d]+$/i;
|
|
303
296
|
function snapshotAttributes(attributes) {
|
|
@@ -312,8 +305,7 @@ function createMiniProgramTreeSnapshot(node) {
|
|
|
312
305
|
tag: node.tag ?? "root"
|
|
313
306
|
};
|
|
314
307
|
}
|
|
315
|
-
|
|
316
|
-
//#region src/screen/helpers.ts
|
|
308
|
+
// src/screen/helpers.ts
|
|
317
309
|
function matchesText(value, matcher) {
|
|
318
310
|
if (typeof matcher === "string") return value === matcher;
|
|
319
311
|
matcher.lastIndex = 0;
|
|
@@ -347,8 +339,7 @@ function findNodeById(root, nodeId) {
|
|
|
347
339
|
if (match) return match;
|
|
348
340
|
}
|
|
349
341
|
}
|
|
350
|
-
|
|
351
|
-
//#region src/screen/node.ts
|
|
342
|
+
// src/screen/node.ts
|
|
352
343
|
var MiniProgramNode = class {
|
|
353
344
|
owner;
|
|
354
345
|
nodeId;
|
|
@@ -385,8 +376,7 @@ var MiniProgramNode = class {
|
|
|
385
376
|
return createMiniProgramTreeSnapshot(this.current);
|
|
386
377
|
}
|
|
387
378
|
};
|
|
388
|
-
|
|
389
|
-
//#region src/screen/index.ts
|
|
379
|
+
// src/screen/index.ts
|
|
390
380
|
var MiniProgramScreen = class MiniProgramScreen {
|
|
391
381
|
page;
|
|
392
382
|
snapshotStore;
|
|
@@ -561,8 +551,7 @@ var MiniProgramScreen = class MiniProgramScreen {
|
|
|
561
551
|
return await this.page.$$(selector);
|
|
562
552
|
}
|
|
563
553
|
};
|
|
564
|
-
|
|
565
|
-
//#region src/user.ts
|
|
554
|
+
// src/user.ts
|
|
566
555
|
var MiniProgramUser = class {
|
|
567
556
|
page;
|
|
568
557
|
screen;
|
|
@@ -606,8 +595,7 @@ var MiniProgramUser = class {
|
|
|
606
595
|
await this.finish();
|
|
607
596
|
}
|
|
608
597
|
};
|
|
609
|
-
|
|
610
|
-
//#region src/project.ts
|
|
598
|
+
// src/project.ts
|
|
611
599
|
function formatDiagnostic(entry) {
|
|
612
600
|
return entry.args.map((arg) => {
|
|
613
601
|
if (arg && typeof arg === "object" && "message" in arg && typeof arg.message === "string") return "stack" in arg && typeof arg.stack === "string" ? arg.stack : arg.message;
|
|
@@ -707,8 +695,7 @@ function createTestProject(options) {
|
|
|
707
695
|
platform: options.platform ?? wechat$1()
|
|
708
696
|
});
|
|
709
697
|
}
|
|
710
|
-
|
|
711
|
-
//#region src/snapshot/index.ts
|
|
698
|
+
// src/snapshot/index.ts
|
|
712
699
|
/** 将查询对象或完整诊断快照显式转换为适合稳定断言的语义树。 */
|
|
713
700
|
function toMiniProgramSnapshot(source) {
|
|
714
701
|
return source instanceof MiniProgramScreen || source instanceof MiniProgramNode ? source.snapshot() : createMiniProgramTreeSnapshot(source.root);
|
|
@@ -722,5 +709,4 @@ const mpcoreSnapshotSerializer = {
|
|
|
722
709
|
return JSON.stringify(toMiniProgramSnapshot(value), null, 2);
|
|
723
710
|
}
|
|
724
711
|
};
|
|
725
|
-
//#endregion
|
|
726
712
|
export { MiniProgramNode, MiniProgramScreen, MiniProgramTestProject, MiniProgramUser, applyWxMock, artifactFromProject, createTestProject, createWxMock, mpcoreMatchers, mpcoreSnapshotSerializer, toBeInTheMiniProgram, toHaveAttribute, toHaveDataset, toHaveEmitted, toHaveTextContent, toMiniProgramSnapshot, wechat };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpcore/test",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.2.0",
|
|
5
5
|
"description": "Testing Library-style utilities for compiled WeChat mini-program artifacts",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -39,10 +39,10 @@
|
|
|
39
39
|
"dist"
|
|
40
40
|
],
|
|
41
41
|
"engines": {
|
|
42
|
-
"node": "^22.
|
|
42
|
+
"node": "^22.23.4 || ^24.22.1 || >=26.12.1"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@mpcore/simulator": "1.
|
|
45
|
+
"@mpcore/simulator": "1.2.0"
|
|
46
46
|
},
|
|
47
47
|
"publishConfig": {
|
|
48
48
|
"access": "public",
|