• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024 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 fs from 'fs';
17import path from 'path';
18import {describe, expect, test} from '@jest/globals';
19import { createSourceFile, ScriptTarget } from 'typescript';
20import { generateTypeAliasDeclaration } from '../generate/generateTypeAlias';
21
22describe('generateTypeAliasDeclaration.ts file test', () => {
23  test('Test the generateTypeAliasDeclaration function', () => {
24    const filePath = path.join(__dirname, './api/@ohos.ability.ability.d.ts')
25    const code = fs.readFileSync(filePath);
26    const sourceFile = createSourceFile(filePath, code.toString(), ScriptTarget.Latest);
27    const typeAliasEntity = {
28      typeAliasName: 'DataAbilityHelper',
29      typeAliasTypeKind: 173,
30      typeAliasTypeElements: [
31        {
32          typeName: '_DataAbilityHelper',
33          typeKind: 78,
34        },
35      ],
36      modifiers: [
37        92,
38      ],
39    }
40    const isInner = true;
41    const extraImport = [];
42    const mockApi = 'import { DataAbilityHelper as _DataAbilityHelper } from \'./ability/dataAbilityHelper\''
43      + 'import { PacMap as _PacMap } from \'./ability/dataAbilityHelper\''
44      + 'import { DataAbilityOperation as _DataAbilityOperation } from \'./ability/dataAbilityOperation\''
45      + 'import { DataAbilityResult as _DataAbilityResult } from \'./ability/dataAbilityResult\''
46      + 'import { AbilityResult as _AbilityResult } from \'./ability/abilityResult\''
47      + 'import { ConnectOptions as _ConnectOptions } from \'./ability/connectOptions\''
48      + 'import { StartAbilityParameter as _StartAbilityParameter } from \'./ability/startAbilityParameter\'';
49    const result = generateTypeAliasDeclaration(typeAliasEntity, isInner, sourceFile, extraImport, mockApi);
50    expect(result).toBe('const DataAbilityHelper = _DataAbilityHelper;');
51  });
52});