@lytjs/plugin-testing 6.5.0 → 6.6.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.cjs +13 -13
- package/dist/index.js +13 -13
- package/package.json +51 -51
- package/dist/index.d.cts +0 -256
- package/dist/index.d.ts +0 -256
package/dist/index.cjs
CHANGED
|
@@ -259,7 +259,7 @@ function createFuzzTestHelpers() {
|
|
|
259
259
|
}
|
|
260
260
|
return result;
|
|
261
261
|
};
|
|
262
|
-
const randomDate = (
|
|
262
|
+
const randomDate = (_options = {}) => {
|
|
263
263
|
const now = Date.now();
|
|
264
264
|
const offset = Math.floor(Math.random() * 1e10) - 5e9;
|
|
265
265
|
return new Date(now + offset);
|
|
@@ -327,11 +327,11 @@ function createPerformanceTestHelpers() {
|
|
|
327
327
|
};
|
|
328
328
|
benchmarks.set(name, result);
|
|
329
329
|
if (options.verbose) {
|
|
330
|
-
console.
|
|
331
|
-
console.
|
|
332
|
-
console.
|
|
333
|
-
console.
|
|
334
|
-
console.
|
|
330
|
+
console.warn(`Benchmark "${name}":`);
|
|
331
|
+
console.warn(` Average: ${averageTime.toFixed(4)}ms`);
|
|
332
|
+
console.warn(` Min: ${minTime.toFixed(4)}ms`);
|
|
333
|
+
console.warn(` Max: ${maxTime.toFixed(4)}ms`);
|
|
334
|
+
console.warn(` Ops/s: ${opsPerSecond.toFixed(2)}`);
|
|
335
335
|
}
|
|
336
336
|
return result;
|
|
337
337
|
};
|
|
@@ -403,7 +403,7 @@ function createPerformanceTestHelpers() {
|
|
|
403
403
|
loadBaseline
|
|
404
404
|
};
|
|
405
405
|
}
|
|
406
|
-
function createTestingContext(
|
|
406
|
+
function createTestingContext(_options = {}) {
|
|
407
407
|
const mocks = /* @__PURE__ */ new Map();
|
|
408
408
|
const mockFns = [];
|
|
409
409
|
const domHelpers = createDOMTestHelpers();
|
|
@@ -411,15 +411,15 @@ function createTestingContext(options = {}) {
|
|
|
411
411
|
const fuzzHelpers = createFuzzTestHelpers();
|
|
412
412
|
const performanceHelpers = createPerformanceTestHelpers();
|
|
413
413
|
return {
|
|
414
|
-
mount: (component,
|
|
415
|
-
const container = typeof
|
|
414
|
+
mount: (component, options = {}) => {
|
|
415
|
+
const container = typeof options.container === "string" ? document.querySelector(options.container) : options.container || document.createElement("div");
|
|
416
416
|
if (!container) {
|
|
417
417
|
throw new Error("Invalid container");
|
|
418
418
|
}
|
|
419
|
-
if (
|
|
419
|
+
if (options.attach !== false && container.parentNode === null) {
|
|
420
420
|
document.body.appendChild(container);
|
|
421
421
|
}
|
|
422
|
-
|
|
422
|
+
const instance = {};
|
|
423
423
|
const element = container;
|
|
424
424
|
return {
|
|
425
425
|
instance,
|
|
@@ -428,11 +428,11 @@ function createTestingContext(options = {}) {
|
|
|
428
428
|
while (container.firstChild) {
|
|
429
429
|
container.firstChild.remove();
|
|
430
430
|
}
|
|
431
|
-
if (
|
|
431
|
+
if (options.attach !== false && container.parentNode === document.body) {
|
|
432
432
|
document.body.removeChild(container);
|
|
433
433
|
}
|
|
434
434
|
},
|
|
435
|
-
rerender: (
|
|
435
|
+
rerender: (_newProps) => {
|
|
436
436
|
},
|
|
437
437
|
find: (selector) => element.querySelector(selector),
|
|
438
438
|
findAll: (selector) => Array.from(element.querySelectorAll(selector)),
|
package/dist/index.js
CHANGED
|
@@ -240,7 +240,7 @@ function createFuzzTestHelpers() {
|
|
|
240
240
|
}
|
|
241
241
|
return result;
|
|
242
242
|
};
|
|
243
|
-
const randomDate = (
|
|
243
|
+
const randomDate = (_options = {}) => {
|
|
244
244
|
const now = Date.now();
|
|
245
245
|
const offset = Math.floor(Math.random() * 1e10) - 5e9;
|
|
246
246
|
return new Date(now + offset);
|
|
@@ -308,11 +308,11 @@ function createPerformanceTestHelpers() {
|
|
|
308
308
|
};
|
|
309
309
|
benchmarks.set(name, result);
|
|
310
310
|
if (options.verbose) {
|
|
311
|
-
console.
|
|
312
|
-
console.
|
|
313
|
-
console.
|
|
314
|
-
console.
|
|
315
|
-
console.
|
|
311
|
+
console.warn(`Benchmark "${name}":`);
|
|
312
|
+
console.warn(` Average: ${averageTime.toFixed(4)}ms`);
|
|
313
|
+
console.warn(` Min: ${minTime.toFixed(4)}ms`);
|
|
314
|
+
console.warn(` Max: ${maxTime.toFixed(4)}ms`);
|
|
315
|
+
console.warn(` Ops/s: ${opsPerSecond.toFixed(2)}`);
|
|
316
316
|
}
|
|
317
317
|
return result;
|
|
318
318
|
};
|
|
@@ -384,7 +384,7 @@ function createPerformanceTestHelpers() {
|
|
|
384
384
|
loadBaseline
|
|
385
385
|
};
|
|
386
386
|
}
|
|
387
|
-
function createTestingContext(
|
|
387
|
+
function createTestingContext(_options = {}) {
|
|
388
388
|
const mocks = /* @__PURE__ */ new Map();
|
|
389
389
|
const mockFns = [];
|
|
390
390
|
const domHelpers = createDOMTestHelpers();
|
|
@@ -392,15 +392,15 @@ function createTestingContext(options = {}) {
|
|
|
392
392
|
const fuzzHelpers = createFuzzTestHelpers();
|
|
393
393
|
const performanceHelpers = createPerformanceTestHelpers();
|
|
394
394
|
return {
|
|
395
|
-
mount: (component,
|
|
396
|
-
const container = typeof
|
|
395
|
+
mount: (component, options = {}) => {
|
|
396
|
+
const container = typeof options.container === "string" ? document.querySelector(options.container) : options.container || document.createElement("div");
|
|
397
397
|
if (!container) {
|
|
398
398
|
throw new Error("Invalid container");
|
|
399
399
|
}
|
|
400
|
-
if (
|
|
400
|
+
if (options.attach !== false && container.parentNode === null) {
|
|
401
401
|
document.body.appendChild(container);
|
|
402
402
|
}
|
|
403
|
-
|
|
403
|
+
const instance = {};
|
|
404
404
|
const element = container;
|
|
405
405
|
return {
|
|
406
406
|
instance,
|
|
@@ -409,11 +409,11 @@ function createTestingContext(options = {}) {
|
|
|
409
409
|
while (container.firstChild) {
|
|
410
410
|
container.firstChild.remove();
|
|
411
411
|
}
|
|
412
|
-
if (
|
|
412
|
+
if (options.attach !== false && container.parentNode === document.body) {
|
|
413
413
|
document.body.removeChild(container);
|
|
414
414
|
}
|
|
415
415
|
},
|
|
416
|
-
rerender: (
|
|
416
|
+
rerender: (_newProps) => {
|
|
417
417
|
},
|
|
418
418
|
find: (selector) => element.querySelector(selector),
|
|
419
419
|
findAll: (selector) => Array.from(element.querySelectorAll(selector)),
|
package/package.json
CHANGED
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@lytjs/plugin-testing",
|
|
3
|
-
"version": "6.
|
|
4
|
-
"description": "LytJS official testing plugin with testing utilities and helpers",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "./dist/index.cjs",
|
|
7
|
-
"module": "./dist/index.mjs",
|
|
8
|
-
"types": "./dist/index.d.ts",
|
|
9
|
-
"exports": {
|
|
10
|
-
".": {
|
|
11
|
-
"types": "./dist/index.d.ts",
|
|
12
|
-
"import": "./dist/index.mjs",
|
|
13
|
-
"require": "./dist/index.cjs"
|
|
14
|
-
},
|
|
15
|
-
"./package.json": "./package.json"
|
|
16
|
-
},
|
|
17
|
-
"files": [
|
|
18
|
-
"dist"
|
|
19
|
-
],
|
|
20
|
-
"sideEffects": false,
|
|
21
|
-
"scripts": {
|
|
22
|
-
"build": "tsup",
|
|
23
|
-
"dev": "tsup --watch",
|
|
24
|
-
"test": "vitest run",
|
|
25
|
-
"test:watch": "vitest",
|
|
26
|
-
"test:coverage": "vitest run --coverage",
|
|
27
|
-
"type-check": "tsc --noEmit",
|
|
28
|
-
"lint": "eslint \"src/**/*.ts\"",
|
|
29
|
-
"clean": "rm -rf dist"
|
|
30
|
-
},
|
|
31
|
-
"dependencies": {
|
|
32
|
-
"@lytjs/core": "
|
|
33
|
-
"@lytjs/reactivity": "
|
|
34
|
-
},
|
|
35
|
-
"devDependencies": {
|
|
36
|
-
"tsup": "^8.0.0",
|
|
37
|
-
"typescript": "^5.4.0",
|
|
38
|
-
"vitest": "^3.0.0"
|
|
39
|
-
},
|
|
40
|
-
"license": "MIT",
|
|
41
|
-
"repository": {
|
|
42
|
-
"type": "git",
|
|
43
|
-
"url": "https://gitee.com/lytjs/lytjs.git",
|
|
44
|
-
"directory": "packages/plugins/packages/plugin-testing"
|
|
45
|
-
},
|
|
46
|
-
"keywords": [
|
|
47
|
-
"lytjs",
|
|
48
|
-
"testing",
|
|
49
|
-
"test-utilities"
|
|
50
|
-
]
|
|
51
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@lytjs/plugin-testing",
|
|
3
|
+
"version": "6.6.0",
|
|
4
|
+
"description": "LytJS official testing plugin with testing utilities and helpers",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.mjs",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.mjs",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsup",
|
|
23
|
+
"dev": "tsup --watch",
|
|
24
|
+
"test": "vitest run",
|
|
25
|
+
"test:watch": "vitest",
|
|
26
|
+
"test:coverage": "vitest run --coverage",
|
|
27
|
+
"type-check": "tsc --noEmit",
|
|
28
|
+
"lint": "eslint \"src/**/*.ts\"",
|
|
29
|
+
"clean": "rm -rf dist"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@lytjs/core": "workspace:*",
|
|
33
|
+
"@lytjs/reactivity": "workspace:*"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"tsup": "^8.0.0",
|
|
37
|
+
"typescript": "^5.4.0",
|
|
38
|
+
"vitest": "^3.0.0"
|
|
39
|
+
},
|
|
40
|
+
"license": "MIT",
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "https://gitee.com/lytjs/lytjs.git",
|
|
44
|
+
"directory": "packages/plugins/packages/plugin-testing"
|
|
45
|
+
},
|
|
46
|
+
"keywords": [
|
|
47
|
+
"lytjs",
|
|
48
|
+
"testing",
|
|
49
|
+
"test-utilities"
|
|
50
|
+
]
|
|
51
|
+
}
|
package/dist/index.d.cts
DELETED
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
import * as _lytjs_core from '@lytjs/core';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @lytjs/plugin-testing - 类型定义
|
|
5
|
-
*/
|
|
6
|
-
interface TestingPluginOptions {
|
|
7
|
-
/** 默认超时时间(毫秒) */
|
|
8
|
-
defaultTimeout?: number;
|
|
9
|
-
/** 是否启用自动清理 */
|
|
10
|
-
autoCleanup?: boolean;
|
|
11
|
-
/** 测试环境配置 */
|
|
12
|
-
environment?: 'node' | 'jsdom' | 'browser';
|
|
13
|
-
}
|
|
14
|
-
interface WrapperOptions {
|
|
15
|
-
/** 挂载目标 */
|
|
16
|
-
container?: Element | string;
|
|
17
|
-
/** 组件 props */
|
|
18
|
-
props?: Record<string, unknown>;
|
|
19
|
-
/** 插槽内容 */
|
|
20
|
-
slots?: Record<string, unknown>;
|
|
21
|
-
/** 是否挂载到 DOM */
|
|
22
|
-
attach?: boolean;
|
|
23
|
-
}
|
|
24
|
-
interface ComponentWrapper<T = unknown> {
|
|
25
|
-
/** 实例 */
|
|
26
|
-
instance: T;
|
|
27
|
-
/** 根元素 */
|
|
28
|
-
element: Element;
|
|
29
|
-
/** 组件卸载 */
|
|
30
|
-
unmount: () => void;
|
|
31
|
-
/** 重新渲染 */
|
|
32
|
-
rerender: (props?: Record<string, unknown>) => void;
|
|
33
|
-
/** 查找元素 */
|
|
34
|
-
find: (selector: string) => Element | null;
|
|
35
|
-
/** 查找所有元素 */
|
|
36
|
-
findAll: (selector: string) => Element[];
|
|
37
|
-
/** 触发事件 */
|
|
38
|
-
trigger: (eventName: string, payload?: unknown) => void;
|
|
39
|
-
}
|
|
40
|
-
interface MockOptions {
|
|
41
|
-
/** 是否保留原实现 */
|
|
42
|
-
preserveOriginal?: boolean;
|
|
43
|
-
/** 模拟实现 */
|
|
44
|
-
implementation?: (...args: unknown[]) => unknown;
|
|
45
|
-
}
|
|
46
|
-
interface MockFn {
|
|
47
|
-
/** 调用次数 */
|
|
48
|
-
readonly callCount: number;
|
|
49
|
-
/** 所有调用参数 */
|
|
50
|
-
readonly calls: unknown[][];
|
|
51
|
-
/** 最后一次调用参数 */
|
|
52
|
-
readonly lastCall: unknown[] | undefined;
|
|
53
|
-
/** 模拟返回值 */
|
|
54
|
-
mockReturnValue: (value: unknown) => void;
|
|
55
|
-
/** 模拟实现 */
|
|
56
|
-
mockImplementation: (fn: (...args: unknown[]) => unknown) => void;
|
|
57
|
-
/** 重置 mock */
|
|
58
|
-
mockReset: () => void;
|
|
59
|
-
/** 清除所有调用记录 */
|
|
60
|
-
mockClear: () => void;
|
|
61
|
-
/** 原始函数(如果有) */
|
|
62
|
-
readonly originalFn: ((...args: unknown[]) => unknown) | undefined;
|
|
63
|
-
}
|
|
64
|
-
interface SignalTestHelpers {
|
|
65
|
-
/** 检查 signal 是否更新 */
|
|
66
|
-
trackUpdates: <T>(signal: {
|
|
67
|
-
value: T;
|
|
68
|
-
}) => {
|
|
69
|
-
readonly value: T;
|
|
70
|
-
readonly updateCount: number;
|
|
71
|
-
readonly history: T[];
|
|
72
|
-
};
|
|
73
|
-
/** 等待 signal 更新 */
|
|
74
|
-
waitForUpdate: <T>(signal: {
|
|
75
|
-
value: T;
|
|
76
|
-
}, timeout?: number) => Promise<void>;
|
|
77
|
-
}
|
|
78
|
-
interface DOMTestHelpers {
|
|
79
|
-
/** 等待元素出现 */
|
|
80
|
-
waitForElement: (selector: string, timeout?: number) => Promise<Element>;
|
|
81
|
-
/** 等待元素消失 */
|
|
82
|
-
waitForElementToDisappear: (selector: string, timeout?: number) => Promise<void>;
|
|
83
|
-
/** 等待文本出现 */
|
|
84
|
-
waitForText: (text: string, timeout?: number) => Promise<Element>;
|
|
85
|
-
/** 模拟用户输入 */
|
|
86
|
-
fillForm: (data: Record<string, string | boolean>) => void;
|
|
87
|
-
/** 模拟点击 */
|
|
88
|
-
click: (selector: string | Element) => void;
|
|
89
|
-
/** 检查元素是否存在 */
|
|
90
|
-
exists: (selector: string) => boolean;
|
|
91
|
-
/** 检查元素是否可见 */
|
|
92
|
-
isVisible: (selector: string | Element) => boolean;
|
|
93
|
-
/** 检查元素是否禁用 */
|
|
94
|
-
isDisabled: (selector: string | Element) => boolean;
|
|
95
|
-
/** 获取元素文本 */
|
|
96
|
-
text: (selector: string | Element) => string;
|
|
97
|
-
/** 获取元素属性 */
|
|
98
|
-
attribute: (selector: string | Element, name: string) => string | null;
|
|
99
|
-
/** 获取元素类名 */
|
|
100
|
-
classes: (selector: string | Element) => string[];
|
|
101
|
-
/** 检查元素是否包含类名 */
|
|
102
|
-
hasClass: (selector: string | Element, className: string) => boolean;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* 模糊测试生成器配置
|
|
106
|
-
*/
|
|
107
|
-
interface FuzzGeneratorOptions {
|
|
108
|
-
/** 生成值的最大长度(针对字符串、数组等) */
|
|
109
|
-
maxLength?: number;
|
|
110
|
-
/** 最小值(针对数字) */
|
|
111
|
-
min?: number;
|
|
112
|
-
/** 最大值(针对数字) */
|
|
113
|
-
max?: number;
|
|
114
|
-
/** 是否允许 null/undefined */
|
|
115
|
-
allowNull?: boolean;
|
|
116
|
-
/** 是否允许 undefined */
|
|
117
|
-
allowUndefined?: boolean;
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* 模糊测试结果
|
|
121
|
-
*/
|
|
122
|
-
interface FuzzTestResult {
|
|
123
|
-
/** 测试用例总数 */
|
|
124
|
-
totalCases: number;
|
|
125
|
-
/** 通过的测试用例数 */
|
|
126
|
-
passedCases: number;
|
|
127
|
-
/** 失败的测试用例 */
|
|
128
|
-
failedCases: Array<{
|
|
129
|
-
input: unknown;
|
|
130
|
-
error: Error;
|
|
131
|
-
}>;
|
|
132
|
-
/** 是否全部通过 */
|
|
133
|
-
success: boolean;
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* 性能基准测试配置
|
|
137
|
-
*/
|
|
138
|
-
interface BenchmarkOptions {
|
|
139
|
-
/** 迭代次数 */
|
|
140
|
-
iterations?: number;
|
|
141
|
-
/** 预热次数 */
|
|
142
|
-
warmupIterations?: number;
|
|
143
|
-
/** 是否输出详细信息 */
|
|
144
|
-
verbose?: boolean;
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* 性能基准测试结果
|
|
148
|
-
*/
|
|
149
|
-
interface BenchmarkResult {
|
|
150
|
-
/** 操作名称 */
|
|
151
|
-
name: string;
|
|
152
|
-
/** 总执行时间(毫秒) */
|
|
153
|
-
totalTime: number;
|
|
154
|
-
/** 平均执行时间(毫秒) */
|
|
155
|
-
averageTime: number;
|
|
156
|
-
/** 最快执行时间(毫秒) */
|
|
157
|
-
minTime: number;
|
|
158
|
-
/** 最慢执行时间(毫秒) */
|
|
159
|
-
maxTime: number;
|
|
160
|
-
/** 操作次数 */
|
|
161
|
-
iterations: number;
|
|
162
|
-
/** 每秒操作数 */
|
|
163
|
-
opsPerSecond: number;
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* 性能回归测试配置
|
|
167
|
-
*/
|
|
168
|
-
interface RegressionTestOptions {
|
|
169
|
-
/** 性能阈值(百分比),如果新的性能比基准慢超过这个百分比则失败 */
|
|
170
|
-
threshold?: number;
|
|
171
|
-
/** 基准数据 */
|
|
172
|
-
baseline?: BenchmarkResult;
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* 性能回归测试结果
|
|
176
|
-
*/
|
|
177
|
-
interface RegressionTestResult {
|
|
178
|
-
/** 是否通过回归测试 */
|
|
179
|
-
passed: boolean;
|
|
180
|
-
/** 基准结果 */
|
|
181
|
-
baseline: BenchmarkResult;
|
|
182
|
-
/** 当前结果 */
|
|
183
|
-
current: BenchmarkResult;
|
|
184
|
-
/** 性能差异百分比(正值表示变慢,负值表示变快) */
|
|
185
|
-
regressionPercent: number;
|
|
186
|
-
/** 消息 */
|
|
187
|
-
message: string;
|
|
188
|
-
}
|
|
189
|
-
interface FuzzTestHelpers {
|
|
190
|
-
/** 生成随机字符串 */
|
|
191
|
-
randomString: (options?: FuzzGeneratorOptions) => string;
|
|
192
|
-
/** 生成随机数字 */
|
|
193
|
-
randomNumber: (options?: FuzzGeneratorOptions) => number;
|
|
194
|
-
/** 生成随机布尔值 */
|
|
195
|
-
randomBoolean: () => boolean;
|
|
196
|
-
/** 生成随机数组 */
|
|
197
|
-
randomArray: <T>(generator: () => T, options?: FuzzGeneratorOptions) => T[];
|
|
198
|
-
/** 生成随机对象 */
|
|
199
|
-
randomObject: (options?: FuzzGeneratorOptions) => Record<string, unknown>;
|
|
200
|
-
/** 生成随机日期 */
|
|
201
|
-
randomDate: (options?: FuzzGeneratorOptions) => Date;
|
|
202
|
-
/** 运行模糊测试 */
|
|
203
|
-
fuzz: <T>(generator: () => T, testFn: (input: T) => void | Promise<void>, iterations?: number) => Promise<FuzzTestResult>;
|
|
204
|
-
}
|
|
205
|
-
interface PerformanceTestHelpers {
|
|
206
|
-
/** 运行基准测试 */
|
|
207
|
-
benchmark: (name: string, fn: () => void | Promise<void>, options?: BenchmarkOptions) => Promise<BenchmarkResult>;
|
|
208
|
-
/** 比较两次基准测试结果 */
|
|
209
|
-
compare: (baseline: BenchmarkResult, current: BenchmarkResult) => {
|
|
210
|
-
percentChange: number;
|
|
211
|
-
isFaster: boolean;
|
|
212
|
-
isSlower: boolean;
|
|
213
|
-
};
|
|
214
|
-
/** 性能回归测试 */
|
|
215
|
-
regressionTest: (name: string, fn: () => void | Promise<void>, baseline: BenchmarkResult, options?: RegressionTestOptions) => Promise<RegressionTestResult>;
|
|
216
|
-
/** 保存基准数据 */
|
|
217
|
-
saveBaseline: (result: BenchmarkResult, path?: string) => void;
|
|
218
|
-
/** 加载基准数据 */
|
|
219
|
-
loadBaseline: (name: string, path?: string) => BenchmarkResult | null;
|
|
220
|
-
}
|
|
221
|
-
interface TestingContext {
|
|
222
|
-
/** 组件包装器 */
|
|
223
|
-
mount: <T = unknown>(component: unknown, options?: WrapperOptions) => ComponentWrapper<T>;
|
|
224
|
-
/** 创建 mock 函数 */
|
|
225
|
-
mockFn: (options?: MockOptions) => MockFn;
|
|
226
|
-
/** 模拟模块 */
|
|
227
|
-
mockModule: (moduleName: string, factory: () => unknown) => void;
|
|
228
|
-
/** 清除所有 mock */
|
|
229
|
-
clearAllMocks: () => void;
|
|
230
|
-
/** 信号测试助手 */
|
|
231
|
-
signal: SignalTestHelpers;
|
|
232
|
-
/** DOM 测试助手 */
|
|
233
|
-
dom: DOMTestHelpers;
|
|
234
|
-
/** 等待指定时间 */
|
|
235
|
-
wait: (ms: number) => Promise<void>;
|
|
236
|
-
/** 等待条件满足 */
|
|
237
|
-
waitFor: (condition: () => boolean | Promise<boolean>, timeout?: number) => Promise<void>;
|
|
238
|
-
/** 下一帧 */
|
|
239
|
-
nextTick: () => Promise<void>;
|
|
240
|
-
/** 模糊测试助手 */
|
|
241
|
-
fuzz: FuzzTestHelpers;
|
|
242
|
-
/** 性能测试助手 */
|
|
243
|
-
performance: PerformanceTestHelpers;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* 创建 mock 函数
|
|
248
|
-
*/
|
|
249
|
-
declare function createMockFn(options?: MockOptions): MockFn;
|
|
250
|
-
/**
|
|
251
|
-
* 创建测试上下文
|
|
252
|
-
*/
|
|
253
|
-
declare function createTestingContext(options?: TestingPluginOptions): TestingContext;
|
|
254
|
-
declare const pluginTesting: _lytjs_core.PluginDefinition<unknown>;
|
|
255
|
-
|
|
256
|
-
export { type BenchmarkOptions, type BenchmarkResult, type ComponentWrapper, type DOMTestHelpers, type FuzzGeneratorOptions, type FuzzTestHelpers, type FuzzTestResult, type MockFn, type MockOptions, type PerformanceTestHelpers, type RegressionTestOptions, type RegressionTestResult, type SignalTestHelpers, type TestingContext, type TestingPluginOptions, type WrapperOptions, createMockFn, createTestingContext, pluginTesting as default };
|
package/dist/index.d.ts
DELETED
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
import * as _lytjs_core from '@lytjs/core';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @lytjs/plugin-testing - 类型定义
|
|
5
|
-
*/
|
|
6
|
-
interface TestingPluginOptions {
|
|
7
|
-
/** 默认超时时间(毫秒) */
|
|
8
|
-
defaultTimeout?: number;
|
|
9
|
-
/** 是否启用自动清理 */
|
|
10
|
-
autoCleanup?: boolean;
|
|
11
|
-
/** 测试环境配置 */
|
|
12
|
-
environment?: 'node' | 'jsdom' | 'browser';
|
|
13
|
-
}
|
|
14
|
-
interface WrapperOptions {
|
|
15
|
-
/** 挂载目标 */
|
|
16
|
-
container?: Element | string;
|
|
17
|
-
/** 组件 props */
|
|
18
|
-
props?: Record<string, unknown>;
|
|
19
|
-
/** 插槽内容 */
|
|
20
|
-
slots?: Record<string, unknown>;
|
|
21
|
-
/** 是否挂载到 DOM */
|
|
22
|
-
attach?: boolean;
|
|
23
|
-
}
|
|
24
|
-
interface ComponentWrapper<T = unknown> {
|
|
25
|
-
/** 实例 */
|
|
26
|
-
instance: T;
|
|
27
|
-
/** 根元素 */
|
|
28
|
-
element: Element;
|
|
29
|
-
/** 组件卸载 */
|
|
30
|
-
unmount: () => void;
|
|
31
|
-
/** 重新渲染 */
|
|
32
|
-
rerender: (props?: Record<string, unknown>) => void;
|
|
33
|
-
/** 查找元素 */
|
|
34
|
-
find: (selector: string) => Element | null;
|
|
35
|
-
/** 查找所有元素 */
|
|
36
|
-
findAll: (selector: string) => Element[];
|
|
37
|
-
/** 触发事件 */
|
|
38
|
-
trigger: (eventName: string, payload?: unknown) => void;
|
|
39
|
-
}
|
|
40
|
-
interface MockOptions {
|
|
41
|
-
/** 是否保留原实现 */
|
|
42
|
-
preserveOriginal?: boolean;
|
|
43
|
-
/** 模拟实现 */
|
|
44
|
-
implementation?: (...args: unknown[]) => unknown;
|
|
45
|
-
}
|
|
46
|
-
interface MockFn {
|
|
47
|
-
/** 调用次数 */
|
|
48
|
-
readonly callCount: number;
|
|
49
|
-
/** 所有调用参数 */
|
|
50
|
-
readonly calls: unknown[][];
|
|
51
|
-
/** 最后一次调用参数 */
|
|
52
|
-
readonly lastCall: unknown[] | undefined;
|
|
53
|
-
/** 模拟返回值 */
|
|
54
|
-
mockReturnValue: (value: unknown) => void;
|
|
55
|
-
/** 模拟实现 */
|
|
56
|
-
mockImplementation: (fn: (...args: unknown[]) => unknown) => void;
|
|
57
|
-
/** 重置 mock */
|
|
58
|
-
mockReset: () => void;
|
|
59
|
-
/** 清除所有调用记录 */
|
|
60
|
-
mockClear: () => void;
|
|
61
|
-
/** 原始函数(如果有) */
|
|
62
|
-
readonly originalFn: ((...args: unknown[]) => unknown) | undefined;
|
|
63
|
-
}
|
|
64
|
-
interface SignalTestHelpers {
|
|
65
|
-
/** 检查 signal 是否更新 */
|
|
66
|
-
trackUpdates: <T>(signal: {
|
|
67
|
-
value: T;
|
|
68
|
-
}) => {
|
|
69
|
-
readonly value: T;
|
|
70
|
-
readonly updateCount: number;
|
|
71
|
-
readonly history: T[];
|
|
72
|
-
};
|
|
73
|
-
/** 等待 signal 更新 */
|
|
74
|
-
waitForUpdate: <T>(signal: {
|
|
75
|
-
value: T;
|
|
76
|
-
}, timeout?: number) => Promise<void>;
|
|
77
|
-
}
|
|
78
|
-
interface DOMTestHelpers {
|
|
79
|
-
/** 等待元素出现 */
|
|
80
|
-
waitForElement: (selector: string, timeout?: number) => Promise<Element>;
|
|
81
|
-
/** 等待元素消失 */
|
|
82
|
-
waitForElementToDisappear: (selector: string, timeout?: number) => Promise<void>;
|
|
83
|
-
/** 等待文本出现 */
|
|
84
|
-
waitForText: (text: string, timeout?: number) => Promise<Element>;
|
|
85
|
-
/** 模拟用户输入 */
|
|
86
|
-
fillForm: (data: Record<string, string | boolean>) => void;
|
|
87
|
-
/** 模拟点击 */
|
|
88
|
-
click: (selector: string | Element) => void;
|
|
89
|
-
/** 检查元素是否存在 */
|
|
90
|
-
exists: (selector: string) => boolean;
|
|
91
|
-
/** 检查元素是否可见 */
|
|
92
|
-
isVisible: (selector: string | Element) => boolean;
|
|
93
|
-
/** 检查元素是否禁用 */
|
|
94
|
-
isDisabled: (selector: string | Element) => boolean;
|
|
95
|
-
/** 获取元素文本 */
|
|
96
|
-
text: (selector: string | Element) => string;
|
|
97
|
-
/** 获取元素属性 */
|
|
98
|
-
attribute: (selector: string | Element, name: string) => string | null;
|
|
99
|
-
/** 获取元素类名 */
|
|
100
|
-
classes: (selector: string | Element) => string[];
|
|
101
|
-
/** 检查元素是否包含类名 */
|
|
102
|
-
hasClass: (selector: string | Element, className: string) => boolean;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* 模糊测试生成器配置
|
|
106
|
-
*/
|
|
107
|
-
interface FuzzGeneratorOptions {
|
|
108
|
-
/** 生成值的最大长度(针对字符串、数组等) */
|
|
109
|
-
maxLength?: number;
|
|
110
|
-
/** 最小值(针对数字) */
|
|
111
|
-
min?: number;
|
|
112
|
-
/** 最大值(针对数字) */
|
|
113
|
-
max?: number;
|
|
114
|
-
/** 是否允许 null/undefined */
|
|
115
|
-
allowNull?: boolean;
|
|
116
|
-
/** 是否允许 undefined */
|
|
117
|
-
allowUndefined?: boolean;
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* 模糊测试结果
|
|
121
|
-
*/
|
|
122
|
-
interface FuzzTestResult {
|
|
123
|
-
/** 测试用例总数 */
|
|
124
|
-
totalCases: number;
|
|
125
|
-
/** 通过的测试用例数 */
|
|
126
|
-
passedCases: number;
|
|
127
|
-
/** 失败的测试用例 */
|
|
128
|
-
failedCases: Array<{
|
|
129
|
-
input: unknown;
|
|
130
|
-
error: Error;
|
|
131
|
-
}>;
|
|
132
|
-
/** 是否全部通过 */
|
|
133
|
-
success: boolean;
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* 性能基准测试配置
|
|
137
|
-
*/
|
|
138
|
-
interface BenchmarkOptions {
|
|
139
|
-
/** 迭代次数 */
|
|
140
|
-
iterations?: number;
|
|
141
|
-
/** 预热次数 */
|
|
142
|
-
warmupIterations?: number;
|
|
143
|
-
/** 是否输出详细信息 */
|
|
144
|
-
verbose?: boolean;
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* 性能基准测试结果
|
|
148
|
-
*/
|
|
149
|
-
interface BenchmarkResult {
|
|
150
|
-
/** 操作名称 */
|
|
151
|
-
name: string;
|
|
152
|
-
/** 总执行时间(毫秒) */
|
|
153
|
-
totalTime: number;
|
|
154
|
-
/** 平均执行时间(毫秒) */
|
|
155
|
-
averageTime: number;
|
|
156
|
-
/** 最快执行时间(毫秒) */
|
|
157
|
-
minTime: number;
|
|
158
|
-
/** 最慢执行时间(毫秒) */
|
|
159
|
-
maxTime: number;
|
|
160
|
-
/** 操作次数 */
|
|
161
|
-
iterations: number;
|
|
162
|
-
/** 每秒操作数 */
|
|
163
|
-
opsPerSecond: number;
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* 性能回归测试配置
|
|
167
|
-
*/
|
|
168
|
-
interface RegressionTestOptions {
|
|
169
|
-
/** 性能阈值(百分比),如果新的性能比基准慢超过这个百分比则失败 */
|
|
170
|
-
threshold?: number;
|
|
171
|
-
/** 基准数据 */
|
|
172
|
-
baseline?: BenchmarkResult;
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* 性能回归测试结果
|
|
176
|
-
*/
|
|
177
|
-
interface RegressionTestResult {
|
|
178
|
-
/** 是否通过回归测试 */
|
|
179
|
-
passed: boolean;
|
|
180
|
-
/** 基准结果 */
|
|
181
|
-
baseline: BenchmarkResult;
|
|
182
|
-
/** 当前结果 */
|
|
183
|
-
current: BenchmarkResult;
|
|
184
|
-
/** 性能差异百分比(正值表示变慢,负值表示变快) */
|
|
185
|
-
regressionPercent: number;
|
|
186
|
-
/** 消息 */
|
|
187
|
-
message: string;
|
|
188
|
-
}
|
|
189
|
-
interface FuzzTestHelpers {
|
|
190
|
-
/** 生成随机字符串 */
|
|
191
|
-
randomString: (options?: FuzzGeneratorOptions) => string;
|
|
192
|
-
/** 生成随机数字 */
|
|
193
|
-
randomNumber: (options?: FuzzGeneratorOptions) => number;
|
|
194
|
-
/** 生成随机布尔值 */
|
|
195
|
-
randomBoolean: () => boolean;
|
|
196
|
-
/** 生成随机数组 */
|
|
197
|
-
randomArray: <T>(generator: () => T, options?: FuzzGeneratorOptions) => T[];
|
|
198
|
-
/** 生成随机对象 */
|
|
199
|
-
randomObject: (options?: FuzzGeneratorOptions) => Record<string, unknown>;
|
|
200
|
-
/** 生成随机日期 */
|
|
201
|
-
randomDate: (options?: FuzzGeneratorOptions) => Date;
|
|
202
|
-
/** 运行模糊测试 */
|
|
203
|
-
fuzz: <T>(generator: () => T, testFn: (input: T) => void | Promise<void>, iterations?: number) => Promise<FuzzTestResult>;
|
|
204
|
-
}
|
|
205
|
-
interface PerformanceTestHelpers {
|
|
206
|
-
/** 运行基准测试 */
|
|
207
|
-
benchmark: (name: string, fn: () => void | Promise<void>, options?: BenchmarkOptions) => Promise<BenchmarkResult>;
|
|
208
|
-
/** 比较两次基准测试结果 */
|
|
209
|
-
compare: (baseline: BenchmarkResult, current: BenchmarkResult) => {
|
|
210
|
-
percentChange: number;
|
|
211
|
-
isFaster: boolean;
|
|
212
|
-
isSlower: boolean;
|
|
213
|
-
};
|
|
214
|
-
/** 性能回归测试 */
|
|
215
|
-
regressionTest: (name: string, fn: () => void | Promise<void>, baseline: BenchmarkResult, options?: RegressionTestOptions) => Promise<RegressionTestResult>;
|
|
216
|
-
/** 保存基准数据 */
|
|
217
|
-
saveBaseline: (result: BenchmarkResult, path?: string) => void;
|
|
218
|
-
/** 加载基准数据 */
|
|
219
|
-
loadBaseline: (name: string, path?: string) => BenchmarkResult | null;
|
|
220
|
-
}
|
|
221
|
-
interface TestingContext {
|
|
222
|
-
/** 组件包装器 */
|
|
223
|
-
mount: <T = unknown>(component: unknown, options?: WrapperOptions) => ComponentWrapper<T>;
|
|
224
|
-
/** 创建 mock 函数 */
|
|
225
|
-
mockFn: (options?: MockOptions) => MockFn;
|
|
226
|
-
/** 模拟模块 */
|
|
227
|
-
mockModule: (moduleName: string, factory: () => unknown) => void;
|
|
228
|
-
/** 清除所有 mock */
|
|
229
|
-
clearAllMocks: () => void;
|
|
230
|
-
/** 信号测试助手 */
|
|
231
|
-
signal: SignalTestHelpers;
|
|
232
|
-
/** DOM 测试助手 */
|
|
233
|
-
dom: DOMTestHelpers;
|
|
234
|
-
/** 等待指定时间 */
|
|
235
|
-
wait: (ms: number) => Promise<void>;
|
|
236
|
-
/** 等待条件满足 */
|
|
237
|
-
waitFor: (condition: () => boolean | Promise<boolean>, timeout?: number) => Promise<void>;
|
|
238
|
-
/** 下一帧 */
|
|
239
|
-
nextTick: () => Promise<void>;
|
|
240
|
-
/** 模糊测试助手 */
|
|
241
|
-
fuzz: FuzzTestHelpers;
|
|
242
|
-
/** 性能测试助手 */
|
|
243
|
-
performance: PerformanceTestHelpers;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* 创建 mock 函数
|
|
248
|
-
*/
|
|
249
|
-
declare function createMockFn(options?: MockOptions): MockFn;
|
|
250
|
-
/**
|
|
251
|
-
* 创建测试上下文
|
|
252
|
-
*/
|
|
253
|
-
declare function createTestingContext(options?: TestingPluginOptions): TestingContext;
|
|
254
|
-
declare const pluginTesting: _lytjs_core.PluginDefinition<unknown>;
|
|
255
|
-
|
|
256
|
-
export { type BenchmarkOptions, type BenchmarkResult, type ComponentWrapper, type DOMTestHelpers, type FuzzGeneratorOptions, type FuzzTestHelpers, type FuzzTestResult, type MockFn, type MockOptions, type PerformanceTestHelpers, type RegressionTestOptions, type RegressionTestResult, type SignalTestHelpers, type TestingContext, type TestingPluginOptions, type WrapperOptions, createMockFn, createTestingContext, pluginTesting as default };
|