• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-2023 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 './src/core';
17import {DEFAULT, TestType, Size, Level} from './src/Constant';
18import DataDriver from './src/module/config/DataDriver';
19import ExpectExtend from './src/module/assert/ExpectExtend';
20import OhReport from './src/module/report/OhReport';
21import SysTestKit from './src/module/kit/SysTestKit';
22import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from './src/interface';
23import {MockKit, when} from './src/module/mock/MockKit';
24import ArgumentMatchers from './src/module/mock/ArgumentMatchers';
25
26class Hypium {
27    static setData(data) {
28        const core = Core.getInstance();
29        const dataDriver = new DataDriver({data});
30        core.addService('dataDriver', dataDriver);
31    }
32
33    static setTimeConfig(systemTime) {
34        SysTestKit.systemTime = systemTime;
35    }
36
37    static hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) {
38        const core = Core.getInstance();
39        const expectExtend = new ExpectExtend({
40            'id': 'extend'
41        });
42        core.addService('expect', expectExtend);
43        const ohReport = new OhReport({
44            'delegator': abilityDelegator,
45            'abilityDelegatorArguments': abilityDelegatorArguments
46        });
47        SysTestKit.delegator = abilityDelegator;
48        core.addService('report', ohReport);
49        core.init();
50        core.subscribeEvent('spec', ohReport);
51        core.subscribeEvent('suite', ohReport);
52        core.subscribeEvent('task', ohReport);
53        const configService = core.getDefaultService('config');
54
55        let testParameters = {};
56        if (abilityDelegatorArguments !== null) {
57            testParameters = configService.translateParams(abilityDelegatorArguments.parameters);
58        }
59        console.info('parameters:' + JSON.stringify(testParameters));
60        configService.setConfig(testParameters);
61
62        testsuite();
63        if (Object.prototype.hasOwnProperty.call(globalThis, 'setupUiTestEnvironment')) {
64            globalThis.setupUiTestEnvironment().then(() => {
65                console.info('UiTestKit::after run uitest setup, start run testcases');
66                core.execute(abilityDelegator);
67            }).catch((error) => {
68                console.error('UiTestKit:: call setupUiTestEnvironment failure:' + error);
69                core.execute(abilityDelegator);
70            });
71        } else {
72            console.info('UiTestKit:: no need to setup uitest, start run testcases');
73            core.execute(abilityDelegator);
74        }
75    }
76}
77
78export {
79    Hypium,
80    Core,
81    DEFAULT,
82    TestType,
83    Size,
84    Level,
85    DataDriver,
86    ExpectExtend,
87    OhReport,
88    SysTestKit,
89    describe, beforeAll, beforeEach, afterEach, afterAll, it, expect,
90    MockKit, when,
91    ArgumentMatchers
92};