• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 */
15
16import { Core } from './core';
17import { AnyType, HookFuncType, ItfnType } from './module/types/common';
18
19const core = Core.getInstance();
20const hypiumDescribe = (desc: string, func: () => void): Promise<undefined> => {
21  if (core) {
22    return (core as Core).describe(desc, func);
23  }
24};
25
26const hypiumIt = (desc: string, filter: int, func: ItfnType) => {
27  if (core) {
28    return (core as Core).it(desc, filter, func);
29  }
30};
31const hypiumBeforeItSpecified = (itDescs: string | string[], func: HookFuncType) => {
32  if (core) {
33    return (core as Core).beforeItSpecified(itDescs, func);
34  }
35};
36
37const hypiumAfterItSpecified = (itDescs: string | string[], func: HookFuncType) => {
38  if (core) {
39    return (core as Core).afterItSpecified(itDescs, func);
40  }
41};
42const hypiumBeforeEach = (func: HookFuncType) => {
43  if (core) {
44    return (core as Core).beforeEach(func);
45  }
46};
47const hypiumAfterEach = (func: HookFuncType) => {
48  if (core) {
49    return (core as Core).afterEach(func);
50  }
51};
52const hypiumBeforeAll = (func: HookFuncType) => {
53  if (core) {
54    return (core as Core).beforeAll(func);
55  }
56};
57const hypiumAfterAll = (func: HookFuncType) => {
58  if (core) {
59    return (core as Core).afterAll(func);
60  }
61};
62const hypiumExpect = (actualValue?: AnyType) => {
63  if (core) {
64    const expect = (core as Core).expect;
65    if (expect) {
66      return expect(actualValue);
67    }
68  }
69};
70
71const hypiumXdescribe = (desc: string, func: () => void) => {
72  if (core) {
73    return (core as Core).xdescribe(desc, func, '');
74  }
75};
76const hypiumXdescribeReason = (reason: string) => {
77  return (desc: string, func: () => void) => {
78    if (core) {
79      return (core as Core).xdescribe(desc, func, reason);
80    }
81  };
82};
83const hypiumXit = (desc: string, filter: int, func: ItfnType) => {
84  if (core) {
85    return (core as Core).xit(desc, filter, func, '');
86  }
87};
88const hypiumXitReason = (reason: string) => {
89  return (desc: string, filter: int, func: (() => void) | (() => Promise<void>)) => {
90    if (core) {
91      return (core as Core).xit(desc, filter, func, reason);
92    }
93  };
94};
95
96export {
97  hypiumDescribe,
98  hypiumIt,
99  hypiumBeforeAll,
100  hypiumBeforeEach,
101  hypiumAfterEach,
102  hypiumAfterAll,
103  hypiumExpect,
104  hypiumBeforeItSpecified,
105  hypiumAfterItSpecified,
106  hypiumXdescribe,
107  hypiumXit,
108  hypiumXdescribeReason,
109  hypiumXitReason,
110};
111