• 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, TAG} 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, beforeItSpecified, afterItSpecified} 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        if (abilityDelegatorArguments !== null) {
55            let testParameters = configService.translateParams(abilityDelegatorArguments.parameters);
56            console.info(`${TAG}parameters:${JSON.stringify(testParameters)}`);
57            configService.setConfig(testParameters);
58        }
59        testsuite();
60        core.execute(abilityDelegator);
61    }
62}
63
64export {
65    Hypium,
66    Core,
67    DEFAULT,
68    TestType,
69    Size,
70    Level,
71    DataDriver,
72    ExpectExtend,
73    OhReport,
74    SysTestKit,
75    describe, beforeAll, beforeEach, afterEach, afterAll, it, expect, beforeItSpecified, afterItSpecified,
76    MockKit, when,
77    ArgumentMatchers
78};