node-os-utils
Version:
Advanced cross-platform operating system monitoring utilities with TypeScript support
157 lines • 3.79 kB
TypeScript
/**
* 测试基础工具类
* 提供跨平台的测试工具函数和平台检测功能
*/
/// <reference types="mocha" />
/**
* 平台检测工具类
*/
export declare class PlatformUtils {
/**
* 检查是否为Linux系统
*/
static isLinux(): boolean;
/**
* 检查是否为macOS系统
*/
static isMacOS(): boolean;
/**
* 检查是否为Windows系统
*/
static isWindows(): boolean;
/**
* 获取当前平台
*/
static getCurrentPlatform(): string;
/**
* 获取平台友好名称
*/
static getPlatformName(): string;
}
/**
* 测试验证工具类
*/
export declare class TestValidators {
/**
* 检查是否为有效的数字
*/
static isValidNumber(num: any): boolean;
/**
* 检查是否为有效的百分比 (0-100)
*/
static isValidPercentage(num: any): boolean;
/**
* 检查是否为正数
*/
static isPositiveNumber(num: any): boolean;
/**
* 检查是否为非空字符串
*/
static isNonEmptyString(str: any): boolean;
/**
* 检查是否为有效的数组
*/
static isValidArray(arr: any): boolean;
/**
* 检查是否为有效的对象
*/
static isValidObject(obj: any): boolean;
}
/**
* 测试配置类
*/
export declare class TestConfig {
/**
* 默认超时时间
*/
static readonly DEFAULT_TIMEOUT = 10000;
/**
* 长时间运行测试的超时时间
*/
static readonly LONG_TIMEOUT = 30000;
/**
* 性能测试的最大执行时间
*/
static readonly PERF_MAX_DURATION = 5000;
/**
* 内存测试的最大内存增长(MB)
*/
static readonly MAX_MEMORY_INCREASE_MB = 10;
}
/**
* 异步测试装饰器
*/
export declare function asyncTest(testFn: Function): (this: Mocha.Context) => Promise<void>;
/**
* 长时间测试装饰器
*/
export declare function longTest(testFn: Function): (this: Mocha.Context) => Promise<void>;
/**
* 平台条件测试装饰器
*/
export declare function platformTest(platforms: string[], testFn: Function): (this: Mocha.Context) => any;
/**
* 跳过特定平台的测试装饰器
*/
export declare function skipOnPlatform(platforms: string[], testFn: Function): (this: Mocha.Context) => any;
/**
* 测试数据验证助手
*/
export declare class TestAssertions {
/**
* 断言系统信息对象的有效性
*/
static assertSystemInfo(info: any, requiredFields: string[]): void;
/**
* 断言百分比字段的有效性
*/
static assertPercentageFields(info: any, percentageFields: string[]): void;
/**
* 断言内存信息的一致性
*/
static assertMemoryConsistency(info: any): void;
/**
* 断言网络统计信息的有效性
*/
static assertNetworkStats(stats: any[]): void;
}
/**
* 性能监控工具
*/
export declare class PerformanceMonitor {
private startTime;
private startMemory;
private timings;
constructor();
/**
* 获取执行时间(毫秒)
*/
getExecutionTime(): number;
/**
* 获取内存使用增长(字节)
*/
getMemoryIncrease(): number;
/**
* 验证性能是否在可接受范围内
*/
assertPerformance(maxTimeMs?: number): void;
/**
* 验证内存使用是否在可接受范围内
*/
assertMemoryUsage(maxIncreaseMB?: number): void;
/**
* 计时方法 - 执行函数并记录执行时间
*/
time<T>(label: string, fn: () => Promise<T>): Promise<T>;
/**
* 获取所有计时报告
*/
getReport(): {
[key: string]: number;
};
/**
* 重置所有计时记录
*/
reset(): void;
}
//# sourceMappingURL=test-base.d.ts.map