1/* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; 16import { ConfigService } from './module/config/configService'; 17import { SuiteService } from './module/service/SuiteService'; 18import { SpecService } from './module/service/SpecService'; 19import { ExpectService, AssertMatcher } from './module/service/ExpectService'; 20import { ReportService } from './module/service/ReportService'; 21import { OhReport } from './module/report/OhReport'; 22import { ExpectExtend } from './module/assert/ExpectExtend'; 23import { AnyType, HookFuncType, ItfnType, NumberType } from './module/types/common'; 24 25import { SpecEvent, TaskEvent, SuiteEvent } from './module/service/event'; 26import { Core } from './core'; 27import { AssertResult } from './module/modal/assertModel'; 28 29export interface ConfigIf { 30 size?: string; 31 level?: string; 32 testType?: string; 33 timeout?: string; 34 className?: string; 35 notClass?: string; 36 flag?: boolean; 37 suite?: string; 38 itName?: string; 39 filter?: int; 40 dryRun?: string; 41 breakOnError?: string; 42 random?: string; 43 stress?: string; 44 coverage?: string; 45 skipMessage?: string; 46 runSkipped?: string; 47} 48 49export interface StaticServiceIF { 50 description: string; 51} 52 53export interface StaticSpecIF { 54 description: string; 55 fi: int; 56 fn?: () => void; 57 asyncFn?: (() => Promise<void>) | ((params: AnyType) => Promise<void>); 58} 59 60export interface ServiceAttrIF { 61 id: string; 62} 63 64export interface ItItemIF { 65 currentThreadName: string; 66 description: string; 67 result: byte; 68} 69 70export interface TestcaseSummaryIF { 71 total: int; 72 failure: int; 73 error: int; 74 pass: int; 75 ignore: int; 76 duration: int; 77 itItemList: Array<ItItemIF>; 78} 79 80export interface CoreServiceIF { 81 suite?: SuiteService; 82 spec?: SpecService; 83 expect?: ExpectService | ExpectExtend; 84 report?: ReportService | OhReport; 85 config?: ConfigService; 86} 87 88export interface CoreEventIF { 89 suite?: SuiteEvent; 90 spec?: SpecEvent; 91 task?: TaskEvent; 92} 93 94export interface EventAttrIF { 95 id: string; 96 coreContext: Core; 97} 98 99export interface SuiteReportIF { 100 tag: string; 101 name?: string; 102 errors?: int; 103 tests?: int; 104 failures?: int; 105 time?: string; 106 timestamp?: string; 107 children?: Array<SuiteReportIF>; 108 type?: string; 109 message?: string; 110} 111 112export interface CaseReportIF { 113 tag: string; 114 type: string; 115 message: string; 116} 117 118export interface ReportAttrIF { 119 delegator: abilityDelegatorRegistry.AbilityDelegator; 120 abilityDelegatorArguments: abilityDelegatorRegistry.AbilityDelegatorArgs; 121} 122 123export interface AssertMatcherIF { 124 assertClose: (actualValue: number, expected: number[]) => AssertResult; 125 assertContain: (actualValue: AnyType, expect: AnyType[]) => AssertResult; 126 assertFail: () => AssertResult; 127 assertTrue: (actualValue: boolean) => AssertResult; 128 assertFalse: (actualValue: boolean) => AssertResult; 129 assertInstanceOf: (actualValue: AnyType, expected: string[]) => AssertResult; 130 assertLarger: (actualValue: number, expected: number[]) => AssertResult; 131 assertLess: (actualValue: number, expected: number[]) => AssertResult; 132 assertNull: (actualValue: AnyType) => AssertResult; 133 assertThrow: (actualValue: () => void, args: string[]) => AssertResult; 134 assertThrowError: (actualValue: () => void, args: string[]) => AssertResult; 135 assertUndefined: (actualValue: AnyType) => AssertResult; 136 assertLargerOrEqual: (actualValue: number, expected: number[]) => AssertResult; 137 assertLessOrEqual: (actualValue: number, expected: number[]) => AssertResult; 138 assertNaN: (actualValue: number) => AssertResult; 139 assertNegUnlimited: (actualValue: number) => AssertResult; 140 assertPosUnlimited: (actualValue: number) => AssertResult; 141 assertEqual: (actualValue: AnyType, expect: AnyType[]) => AssertResult; 142 assertDeepEquals: (actualValue: AnyType, expected: AnyType[]) => AssertResult; 143 assertPromiseIsPending: (actualPromise: Promise<AnyType>) => Promise<AssertResult>; 144 assertPromiseIsRejected: (actualPromise: Promise<AnyType>) => Promise<AssertResult>; 145 assertPromiseIsRejectedWith: (actualPromise: Promise<AnyType>, expectedValue: AnyType[]) => Promise<AssertResult>; 146 assertPromiseIsRejectedWithError: (actualPromise: Promise<AnyType>, expectedValue: string[]) => Promise<AssertResult>; 147 assertPromiseIsResolved: (actualPromise: Promise<AnyType>) => Promise<AssertResult>; 148 assertPromiseIsResolvedWith: (actualPromise: Promise<AnyType>, expectedValue: AnyType[]) => Promise<AssertResult>; 149} 150 151export interface WrappedMatchersIF { 152 isNot: boolean; 153 // 翻转方法 154 not: () => ExpectService; 155 message: (msg: string) => ExpectExtend; 156} 157 158export interface FilterParamIF { 159 size: Map<string, int>; 160 level: int[]; 161 testType: Map<string, int>; 162} 163 164export interface ApiIF { 165 name: string; 166 describe?: (desc: string, func: () => void) => Promise<undefined>; 167 xdescribe?: (desc: string, func: () => void, reason: string) => Promise<void>; 168 beforeItSpecified?: (itDescs: string | string[], func: HookFuncType) => void; 169 afterItSpecified?: (itDescs: string | string[], func: HookFuncType) => void; 170 beforeAll?: (func: HookFuncType) => void; 171 beforeEach?: (func: HookFuncType) => void; 172 afterAll?: (func: HookFuncType) => void; 173 afterEach?: (func: HookFuncType) => void; 174 it?: (desc: string, filter: int, func: ItfnType) => void; 175 xit?: (desc: string, filter: int, func: ItfnType, reason: string) => void; 176 expect?: (actualValue?: AnyType) => AssertMatcher; 177} 178 179export interface DryrunResultIF { 180 suites: Array<Map<string, Array<ConfigIf>>>; 181 skipSuites?: Array<Map<string, Array<ConfigIf>>>; 182} 183 184type allExpectType = Object | undefined | null; 185export interface Assert { 186 assertClose(expectValue: number, precision: number): void; 187 assertContain(expectValue: allExpectType): void; 188 assertEqual(expectValue: allExpectType): void; 189 assertFail(): void; 190 assertFalse(): void; 191 assertTrue(): void; 192 assertInstanceOf(expectValue: string): void; 193 assertLarger(expectValue: number): void; 194 assertLess(expectValue: number): void; 195 assertNull(): void; 196 assertThrow(expectValue: string): void; 197 assertThrowError(...expectValue: string[]): void; 198 assertUndefined(): void; 199 assertLargerOrEqual(expectValue: number): void; 200 assertLessOrEqual(expectValue: number): void; 201 assertNaN(): void; 202 assertNegUnlimited(): void; 203 assertPosUnlimited(): void; 204 not(): Assert; 205 assertDeepEquals(expectValue: allExpectType): void; 206 assertPromiseIsPending(): Promise<void>; 207 assertPromiseIsRejected(): Promise<void>; 208 assertPromiseIsRejectedWith: (expectValue: allExpectType) => Promise<void>; 209 assertPromiseIsRejectedWithError(...expectValue: allExpectType[]): Promise<void>; 210 assertPromiseIsResolved(): Promise<void>; 211 assertPromiseIsResolvedWith(expectValue?: allExpectType): Promise<void>; 212 message(msg: string): Assert; 213} 214 215export interface whenResult { 216 afterReturn: (value: allExpectType) => allExpectType; 217 afterReturnNothing: () => undefined; 218 afterAction: (action: allExpectType) => allExpectType; 219 afterThrow: (e_msg: string) => string; 220} 221 222export interface VerificationMode { 223 times(count: Number): void; 224 never(): void; 225 once(): void; 226 atLeast(count: Number): void; 227 atMost(count: Number): void; 228} 229 230export interface ExtendAssert { 231 pass: boolean; 232 message: string; 233 actualValue: AnyType; 234 checkFunc: string; 235} 236 237export interface DataDriverSuite { 238 describe?: string[]; 239 stress?: NumberType; 240 it?: string; 241 params: Record<string, AnyType> | Record<string, AnyType>[] 242 items?: DataDriverSuite[]; 243} 244 245export interface DataDriverData { 246 suites?: DataDriverSuite[]; 247} 248 249export interface DataDriverAttr { 250 data: DataDriverData; 251} 252