1/*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use rollupObject 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 { expect } from 'chai';
17import mocha from 'mocha';
18import sinon from 'sinon';
19
20import {
21  getOhmUrlByFilepath,
22  getOhmUrlByExternalPackage,
23  getOhmUrlBySystemApiOrLibRequest,
24  getNormalizedOhmUrlByFilepath,
25  getNormalizedOhmUrlByAliasName
26} from '../../../../lib/ark_utils';
27import { PACKAGES } from '../../../../lib/pre_define';
28import projectConfig from '../../utils/processProjectConfig';
29import { projectConfig as mainProjectConfig } from '../../../../main';
30import RollUpPluginMock from '../../mock/rollup_mock/rollup_plugin_mock';
31import { GEN_ABC_PLUGIN_NAME } from '../../../../lib/fast_build/ark_compiler/common/ark_define';
32import { ModuleSourceFile } from '../../../../lib/fast_build/ark_compiler/module/module_source_file';
33const PRVIEW_MOCK_CONFIG : Object = {
34  // system api mock
35  "@ohos.bluetooth": {
36    "source": "src/main/mock/ohos/bluetooth.mock.ts"
37  },
38  // local function mock
39  "./src/main/ets/calc": {
40    "source": "src/main/mock/module/calc.mock.ts"
41  },
42  // ohpm dependency mock
43  "lib": {
44    "source": "src/main/mock/module/bigInt.mock.ts"
45  },
46  // native mock
47  "libentry.so": {
48    "source": "src/main/mock/native/libentry.mock.ts"
49  }
50}
51
52const MOCK_CONFIG_FILEPATH = {
53  'lib': `${projectConfig.projectRootPath}/oh_modules/lib/dist/index.js`,
54  './src/main/ets/calc': `${projectConfig.projectRootPath}/entry/src/main/ets/calc.ets`,
55}
56
57mocha.describe('generate ohmUrl', function () {
58  mocha.before(function () {
59    this.rollup = new RollUpPluginMock();
60  });
61
62  mocha.after(() => {
63    delete this.rollup;
64  });
65
66  mocha.it('nested src main ets|js in filePath', function () {
67    const filePath: string = `${projectConfig.projectRootPath}/entry/src/main/ets/feature/src/main/js/`
68      + `subfeature/src/main/ets/pages/test.ts`;
69    const moduleName: string = 'entry';
70    const moduleNamespace: string = 'library';
71    let ohmUrl_1 = getOhmUrlByFilepath(filePath, projectConfig, undefined, moduleName);
72    let ohmUrl_2 = getOhmUrlByFilepath(filePath, projectConfig, undefined, moduleNamespace);
73    let expected_1 = 'UtTestApplication/entry/ets/feature/src/main/js/subfeature/src/main/ets/pages/test';
74    let expected_2 = 'UtTestApplication/entry@library/ets/feature/src/main/js/subfeature/src/main/ets/pages/test';
75    expect(ohmUrl_1 == expected_1).to.be.true;
76    expect(ohmUrl_2 == expected_2).to.be.true;
77  });
78
79  mocha.it('nested src ohosTest ets|js in filePath', function () {
80    const filePath: string = `${projectConfig.projectRootPath}/entry/src/ohosTest/ets/feature/src/main/js/`
81      + `subfeature/src/main/ets/pages/test.ts`;
82    const moduleName: string = 'entry';
83    const moduleNamespace: string = 'library';
84    let ohmUrl_1 = getOhmUrlByFilepath(filePath, projectConfig, undefined, moduleName);
85    let ohmUrl_2 = getOhmUrlByFilepath(filePath, projectConfig, undefined, moduleNamespace);
86    let expected_1 = 'UtTestApplication/entry/ets/feature/src/main/js/subfeature/src/main/ets/pages/test';
87    let expected_2 = 'UtTestApplication/entry@library/ets/feature/src/main/js/subfeature/src/main/ets/pages/test';
88    expect(ohmUrl_1 == expected_1).to.be.true;
89    expect(ohmUrl_2 == expected_2).to.be.true;
90  });
91
92  mocha.it('system builtins & app builtins', function () {
93    mainProjectConfig.bundleName = 'UtTestApplication';
94    mainProjectConfig.moduleName = 'entry';
95    const systemModuleRequest: string = '@system.app';
96    const ohosModuleRequest: string = '@ohos.hilog';
97    const appSoModuleRequest: string = 'libapplication.so';
98    const systemOhmUrl: string = getOhmUrlBySystemApiOrLibRequest(systemModuleRequest);
99    const ohosOhmUrl: string = getOhmUrlBySystemApiOrLibRequest(ohosModuleRequest);
100    const appOhmUrl: string = getOhmUrlBySystemApiOrLibRequest(appSoModuleRequest);
101    const expectedSystemOhmUrl: string = '@native:system.app';
102    const expectedOhosOhmUrl: string = '@ohos:hilog';
103    const expectedappOhmUrl: string = '@app:UtTestApplication/entry/application';
104    expect(systemOhmUrl == expectedSystemOhmUrl).to.be.true;
105    expect(ohosOhmUrl == expectedOhosOhmUrl).to.be.true;
106    expect(appOhmUrl == expectedappOhmUrl).to.be.true;
107  });
108
109  mocha.it('shared library', function () {
110    const sharedLibraryPackageName: string = "@ohos/sharedLibrary";
111    const sharedLibraryPage: string = "@ohos/sharedLibrary/src/main/ets/pages/page1";
112    const errorSharedLibrary: string = "@ohos/staticLibrary";
113    const sharedLibraryPackageNameOhmUrl: string = getOhmUrlByExternalPackage(sharedLibraryPackageName, projectConfig);
114    const sharedLibraryPageOhmUrl: string = getOhmUrlByExternalPackage(sharedLibraryPage, projectConfig);
115    const errorSharedLibraryOhmUrl = getOhmUrlByExternalPackage(errorSharedLibrary, projectConfig);
116    const expectedSharedLibraryOhmUrl: string = "@bundle:UtTestApplication/sharedLibrary/ets/index";
117    const expectedSharedLibraryPageOhmUrl: string = "@bundle:UtTestApplication/sharedLibrary/ets/pages/page1";
118    const expectedErrorSharedLibraryOhmUrl = undefined;
119    expect(sharedLibraryPackageNameOhmUrl == expectedSharedLibraryOhmUrl).to.be.true;
120    expect(sharedLibraryPageOhmUrl == expectedSharedLibraryPageOhmUrl).to.be.true;
121    expect(errorSharedLibraryOhmUrl == expectedErrorSharedLibraryOhmUrl).to.be.true;
122  });
123
124  mocha.it('project module', function () {
125    const filePath: string = `${projectConfig.projectRootPath}/entry/src/main/ets/pages/test.ts`;
126    const harFilePath = `${projectConfig.projectRootPath}/library/src/main/ets/pages/test.ts`;
127    const moduleName: string = 'entry';
128    const moduleNamespace: string = 'library';
129    const ohmUrl = getOhmUrlByFilepath(filePath, projectConfig, undefined, moduleName);
130    const harOhmUrl = getOhmUrlByFilepath(harFilePath, projectConfig, undefined, moduleNamespace);
131    const expected = 'UtTestApplication/entry/ets/pages/test';
132    const harOhmUrlExpected = 'UtTestApplication/entry@library/ets/pages/test';
133    expect(ohmUrl == expected).to.be.true;
134    expect(harOhmUrl == harOhmUrlExpected).to.be.true;
135  });
136
137  mocha.it('thirdParty module', function () {
138    const moduleLevelPkgPath = `${projectConfig.projectRootPath}/entry/oh_modules/json5/dist/index.js`;
139    const projectLevelPkgPath = `${projectConfig.projectRootPath}/oh_modules/json5/dist/index.js`;
140    const moduleName: string = 'entry';
141    const moduleLevelPkgOhmUrl = getOhmUrlByFilepath(moduleLevelPkgPath, projectConfig, undefined, undefined);
142    const projectLevelPkgOhmUrl = getOhmUrlByFilepath(projectLevelPkgPath, projectConfig, undefined, undefined);
143    const moduleLevelPkgOhmUrlExpected = `${PACKAGES}@${moduleName}/json5/dist/index`;
144    const projectLevelPkgOhmUrlExpected = `${PACKAGES}/json5/dist/index`;
145    expect(moduleLevelPkgOhmUrl == moduleLevelPkgOhmUrlExpected).to.be.true;
146    expect(projectLevelPkgOhmUrl == projectLevelPkgOhmUrlExpected).to.be.true;
147  });
148
149  mocha.it('static library entry', function () {
150    const staticLibraryEntry = `${projectConfig.projectRootPath}/library/index.ets`;
151    const moduleNamespace: string = 'library';
152    const staticLibraryEntryOhmUrl =
153      getOhmUrlByFilepath(staticLibraryEntry, projectConfig, undefined, moduleNamespace);
154    const staticLibraryEntryOhmUrlExpected = 'UtTestApplication/entry@library/index';
155    expect(staticLibraryEntryOhmUrl == staticLibraryEntryOhmUrlExpected).to.be.true;
156  });
157
158  mocha.it('ohosTest module', function () {
159    const ohosTestfilePath = `${projectConfig.projectRootPath}/entry/src/ohosTest/ets/pages/test.ts`;
160    const moduleName: string = 'entry';
161    const ohmUrl = getOhmUrlByFilepath(ohosTestfilePath, projectConfig, undefined, moduleName);
162    const expected = 'UtTestApplication/entry/ets/pages/test';
163    expect(ohmUrl == expected).to.be.true;
164  });
165
166  mocha.it('the error message of processPackageDir', function () {
167    this.rollup.build();
168    projectConfig.modulePathMap = {};
169    const red: string = '\u001b[31m';
170    const reset: string = '\u001b[39m';
171    const filePath: string = `${projectConfig.projectRootPath}/entry/oh_modules/json5/dist/index.js`;
172    const moduleName: string = 'entry';
173    const importerFile: string = 'importTest.ts';
174    const logger = this.rollup.share.getLogger(GEN_ABC_PLUGIN_NAME)
175    const loggerStub = sinon.stub(logger, 'error');
176    getOhmUrlByFilepath(filePath, projectConfig, logger, moduleName, importerFile);
177    expect(loggerStub.calledWith(red, 'ArkTS:ERROR Failed to resolve OhmUrl.\n' +
178      `Error Message: Failed to get a resolved OhmUrl for "${filePath}" imported by "${importerFile}".\n` +
179      `Solutions: > Check whether the module which ${filePath} belongs to is correctly configured.` +
180      '> Check the corresponding file name is correct(including case-sensitivity).', reset)).to.be.true;
181    loggerStub.restore();
182  });
183
184  mocha.it('the error message of processPackageDir(packageDir is invalid value)', function () {
185    this.rollup.build();
186    projectConfig.packageDir = undefined;
187    projectConfig.modulePathMap = {};
188    const red: string = '\u001b[31m';
189    const reset: string = '\u001b[39m';
190    const filePath: string = `${projectConfig.projectRootPath}/entry/oh_modules/json5/dist/index.js`;
191    const moduleName: string = 'entry';
192    const importerFile: string = 'importTest.ts';
193    const logger = this.rollup.share.getLogger(GEN_ABC_PLUGIN_NAME)
194    const loggerStub = sinon.stub(logger, 'error');
195    getOhmUrlByFilepath(filePath, projectConfig, logger, moduleName, importerFile);
196    expect(loggerStub.calledWith(red, 'ArkTS:ERROR Failed to resolve OhmUrl.\n' +
197      `Error Message: Failed to get a resolved OhmUrl for "${filePath}" imported by "${importerFile}".\n` +
198      `Solutions: > Check whether the module which ${filePath} belongs to is correctly configured.` +
199      '> Check the corresponding file name is correct(including case-sensitivity).', reset)).to.be.true;
200    loggerStub.restore();
201  });
202
203  mocha.it('NormalizedOHMUrl inter-app hsp self import', function () {
204    this.rollup.build();
205    this.rollup.share.projectConfig.useNormalizedOHMUrl = true;
206    this.rollup.share.projectConfig.pkgContextInfo = {
207      'pkghsp': {
208        'packageName': 'pkghsp',
209        'bundleName': 'com.test.testHsp',
210        'moduleName': '',
211        'version': '',
212        'entryPath': 'Index.ets',
213        'isSO': false
214      }
215    }
216    const filePath: string = '/testHsp/hsp/src/main/ets/utils/Calc.ets';
217    const moduleInfo = {
218      id: filePath,
219      meta: {
220        pkgName: 'pkghsp',
221        pkgPath: '/testHsp/hsp'
222      }
223    }
224    this.rollup.moduleInfos.push(moduleInfo);
225    const importerFile: string = '/testHsp/hsp/src/main/ets/pages/Index.ets'
226    const relativePath: string = '../utils/Calc';
227    const etsBasedAbsolutePath: string = 'ets/utils/Calc';
228    const standardImportPath: string = 'pkghsp/src/main/ets/utils/Calc';
229    const moduleSourceFile: string = new ModuleSourceFile();
230    ModuleSourceFile.initPluginEnv(this.rollup);
231    const relativePathOhmUrl: string = moduleSourceFile.getOhmUrl(this.rollup, relativePath, filePath, importerFile);
232    const etsBasedAbsolutePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, etsBasedAbsolutePath, filePath,
233      importerFile);
234    const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath,
235      importerFile);
236    const expectedNormalizedOhmUrl: string = '@normalized:N&&com.test.testHsp&pkghsp/src/main/ets/utils/Calc&';
237    expect(relativePathOhmUrl == expectedNormalizedOhmUrl).to.be.true;
238    expect(etsBasedAbsolutePathOhmUrl == expectedNormalizedOhmUrl).to.be.true;
239    expect(standardImportPathOhmUrl == expectedNormalizedOhmUrl).to.be.true;
240  });
241
242  mocha.it('NormalizedOHMUrl inter-app hsp others import', function () {
243    this.rollup.build();
244    this.rollup.share.projectConfig.useNormalizedOHMUrl = true;
245    this.rollup.share.projectConfig.pkgContextInfo = {
246      'pkghsp': {
247        'packageName': 'pkghsp',
248        'bundleName': 'com.test.testHsp',
249        'moduleName': 'hsp',
250        'version': '',
251        'entryPath': 'Index.ets',
252        'isSO': false
253      }
254    }
255    this.rollup.share.projectConfig.dependencyAliasMap = new Map([
256      ['pkghsp_alias', 'pkghsp']
257    ]);
258    this.rollup.share.projectConfig.harNameOhmMap = {
259      'pkghsp_alias': '@bundle:com.test.testHsp/src/main/ets/utils/Calc'
260    }
261    const filePath: string = 'pkghsp/src/main/ets/utils/Calc';
262    const indexFilePath: string = 'pkghsp_alias';
263    const importerFile: string = '/testHap/entry/src/main/ets/pages/index.ets'
264    const importByPkgName = 'pkghsp_alias';
265    const standardImportPath: string = 'pkghsp_alias/src/main/ets/utils/Calc';
266    const moduleSourceFile: string = new ModuleSourceFile();
267    ModuleSourceFile.initPluginEnv(this.rollup);
268    const importByPkgNameOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, importByPkgName, indexFilePath, importerFile);
269    const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath,
270      importerFile);
271    const importByPkgNameNormalizedOhmUrl: string = '@normalized:N&hsp&com.test.testHsp&pkghsp/Index&';
272    const standardImportPathNormalizedOhmUrl: string =
273      '@normalized:N&hsp&com.test.testHsp&pkghsp/src/main/ets/utils/Calc&';
274    expect(importByPkgNameOhmUrl == importByPkgNameNormalizedOhmUrl).to.be.true;
275    expect(standardImportPathOhmUrl == standardImportPathNormalizedOhmUrl).to.be.true;
276  });
277
278  mocha.it('NormalizedOHMUrl in-app hsp self import', function () {
279    this.rollup.build();
280    this.rollup.share.projectConfig.useNormalizedOHMUrl = true;
281    this.rollup.share.projectConfig.pkgContextInfo = {
282      'pkghsp': {
283        'packageName': 'pkghsp',
284        'bundleName': '',
285        'moduleName': '',
286        'version': '',
287        'entryPath': 'Index.ets',
288        'isSO': false
289      }
290    }
291    const filePath: string = '/testHsp/hsp/src/main/ets/utils/Calc.ets';
292    const moduleInfo = {
293      id: filePath,
294      meta: {
295        pkgName: 'pkghsp',
296        pkgPath: '/testHsp/hsp'
297      }
298    }
299    this.rollup.moduleInfos.push(moduleInfo);
300    const importerFile: string = '/testHsp/hsp/src/main/ets/pages/Index.ets'
301    const relativePath: string = '../utils/Calc';
302    const etsBasedAbsolutePath: string = 'ets/utils/Calc';
303    const standardImportPath: string = 'pkghsp/src/main/ets/utils/Calc';
304    const moduleSourceFile: string = new ModuleSourceFile();
305    ModuleSourceFile.initPluginEnv(this.rollup);
306    const relativePathOhmUrl: string = moduleSourceFile.getOhmUrl(this.rollup, relativePath, filePath, importerFile);
307    const etsBasedAbsolutePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, etsBasedAbsolutePath, filePath,
308      importerFile);
309    const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath,
310      importerFile);
311    const expectedNormalizedOhmUrl: string = '@normalized:N&&&pkghsp/src/main/ets/utils/Calc&';
312    expect(relativePathOhmUrl == expectedNormalizedOhmUrl).to.be.true;
313    expect(etsBasedAbsolutePathOhmUrl == expectedNormalizedOhmUrl).to.be.true;
314    expect(standardImportPathOhmUrl == expectedNormalizedOhmUrl).to.be.true;
315  });
316
317  mocha.it('NormalizedOHMUrl in-app hsp others import', function () {
318    this.rollup.build();
319    this.rollup.share.projectConfig.useNormalizedOHMUrl = true;
320    this.rollup.share.projectConfig.pkgContextInfo = {
321      'pkghsp': {
322        'packageName': 'pkghsp',
323        'bundleName': '',
324        'moduleName': 'hsp',
325        'version': '',
326        'entryPath': 'Index.ets',
327        'isSO': false
328      }
329    }
330    this.rollup.share.projectConfig.dependencyAliasMap = new Map([
331      ['pkghsp_alias', 'pkghsp']
332    ]);
333    this.rollup.share.projectConfig.harNameOhmMap = {
334      'pkghsp_alias': '@bundle:com.test.testHap/src/main/ets/utils/Calc'
335    }
336    const filePath: string = 'pkghsp_alias/src/main/ets/utils/Calc';
337    const indexFilePath: string = 'pkghsp_alias';
338
339    const importerFile: string = '/testHap/entry/src/main/ets/pages/index.ets'
340    const importByPkgName = 'pkghsp_alias';
341    const standardImportPath: string = 'pkghsp_alias/src/main/ets/utils/Calc';
342    const moduleSourceFile: string = new ModuleSourceFile();
343    ModuleSourceFile.initPluginEnv(this.rollup);
344    const importByPkgNameOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, importByPkgName, indexFilePath, importerFile);
345    const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath,
346      importerFile);
347    const importByPkgNameNormalizedOhmUrl: string = '@normalized:N&hsp&&pkghsp/Index&';
348    const standardImportPathNormalizedOhmUrl: string = '@normalized:N&hsp&&pkghsp/src/main/ets/utils/Calc&';
349    expect(importByPkgNameOhmUrl == importByPkgNameNormalizedOhmUrl).to.be.true;
350    expect(standardImportPathOhmUrl == standardImportPathNormalizedOhmUrl).to.be.true;
351  });
352
353  mocha.it('NormalizedOHMUrl hap self import', function () {
354    this.rollup.build();
355    this.rollup.share.projectConfig.useNormalizedOHMUrl = true;
356    this.rollup.share.projectConfig.pkgContextInfo = {
357      'entry': {
358        'packageName': 'entry',
359        'bundleName': '',
360        'moduleName': '',
361        'version': '',
362        'entryPath': '',
363        'isSO': false
364      }
365    }
366    const filePath: string = '/testHap/entry/src/main/ets/utils/Calc.ets';
367    const moduleInfo = {
368      id: filePath,
369      meta: {
370        pkgName: 'entry',
371        pkgPath: '/testHap/entry'
372      }
373    }
374    this.rollup.moduleInfos.push(moduleInfo);
375    const importerFile: string = '/testHap/entry/src/main/ets/pages/index.ets'
376    const relativePath: string = '../utils/Calc';
377    const etsBasedAbsolutePath: string = 'ets/utils/Calc';
378    const standardImportPath: string = 'entry/src/main/ets/utils/Calc';
379    const moduleSourceFile: string = new ModuleSourceFile();
380    ModuleSourceFile.initPluginEnv(this.rollup);
381    const relativePathOhmUrl: string = moduleSourceFile.getOhmUrl(this.rollup, relativePath, filePath, importerFile);
382    const etsBasedAbsolutePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, etsBasedAbsolutePath, filePath,
383      importerFile);
384    const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath,
385      importerFile);
386    const expectedNormalizedOhmUrl: string = '@normalized:N&&&entry/src/main/ets/utils/Calc&';
387    expect(relativePathOhmUrl == expectedNormalizedOhmUrl).to.be.true;
388    expect(etsBasedAbsolutePathOhmUrl == expectedNormalizedOhmUrl).to.be.true;
389    expect(standardImportPathOhmUrl == expectedNormalizedOhmUrl).to.be.true;
390  });
391
392  mocha.it('NormalizedOHMUrl source code har self import (hap/in-app hsp)', function () {
393    this.rollup.build();
394    this.rollup.share.projectConfig.useNormalizedOHMUrl = true;
395    this.rollup.share.projectConfig.pkgContextInfo = {
396      'pkghar': {
397        'packageName': 'pkghar',
398        'bundleName': '',
399        'moduleName': '',
400        'version': '1.0.1',
401        'entryPath': 'Index.ets',
402        'isSO': false
403      }
404    }
405    const filePath: string = '/testHar/har/src/main/ets/utils/Calc.ets';
406    const moduleInfo = {
407      id: filePath,
408      meta: {
409        pkgName: 'pkghar',
410        pkgPath: '/testHar/har'
411      }
412    }
413    this.rollup.moduleInfos.push(moduleInfo);
414    const importerFile: string = '/testHar/har/src/main/ets/pages/Index.ets'
415    const relativePath: string = '../utils/Calc';
416    const etsBasedAbsolutePath: string = 'ets/utils/Calc';
417    const standardImportPath: string = 'pkghar/src/main/ets/utils/Calc';
418    const moduleSourceFile: string = new ModuleSourceFile();
419    ModuleSourceFile.initPluginEnv(this.rollup); 
420    const relativePathOhmUrl: string = moduleSourceFile.getOhmUrl(this.rollup, relativePath, filePath, importerFile);
421    const etsBasedAbsolutePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, etsBasedAbsolutePath, filePath,
422      importerFile);
423    const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath,
424      importerFile);
425    const expectedNormalizedOhmUrl: string = '@normalized:N&&&pkghar/src/main/ets/utils/Calc&1.0.1';
426    expect(relativePathOhmUrl == expectedNormalizedOhmUrl).to.be.true;
427    expect(etsBasedAbsolutePathOhmUrl == expectedNormalizedOhmUrl).to.be.true;
428    expect(standardImportPathOhmUrl == expectedNormalizedOhmUrl).to.be.true;
429  });
430
431  mocha.it('NormalizedOHMUrl source code har others import (hap/in-app hsp)', function () {
432    this.rollup.build();
433    this.rollup.share.projectConfig.useNormalizedOHMUrl = true;
434    this.rollup.share.projectConfig.pkgContextInfo = {
435      'pkghar': {
436        'packageName': 'pkghar',
437        'bundleName': '',
438        'moduleName': '',
439        'version': '1.0.1',
440        'entryPath': 'Index.ets',
441        'isSO': false
442      }
443    }
444    const filePath: string = '/testHar/har/src/main/ets/utils/Calc.ets';
445    const indexFilePath: string = '/testHar/har/Index.ets';
446    for (let file of [filePath, indexFilePath]) {
447      const moduleInfo = {
448        id: file,
449        meta: {
450          pkgName: 'pkghar',
451          pkgPath: '/testHar/har'
452        }
453      }
454      this.rollup.moduleInfos.push(moduleInfo);
455    }
456    const importerFile: string = '/testHar/entry/src/main/ets/pages/Index.ets'
457    const importByPkgName = 'pkghar';
458    const standardImportPath: string = 'pkghar/src/main/ets/utils/Calc';
459    const moduleSourceFile: string = new ModuleSourceFile();
460    ModuleSourceFile.initPluginEnv(this.rollup);
461    const importByPkgNameOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, importByPkgName, indexFilePath, importerFile);
462    const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath,
463      importerFile);
464    const importByPkgNameNormalizedOhmUrl: string = '@normalized:N&&&pkghar/Index&1.0.1';
465    const standardImportPathNormalizedOhmUrl: string = '@normalized:N&&&pkghar/src/main/ets/utils/Calc&1.0.1';
466    expect(importByPkgNameOhmUrl == importByPkgNameNormalizedOhmUrl).to.be.true;
467    expect(standardImportPathOhmUrl == standardImportPathNormalizedOhmUrl).to.be.true;
468  });
469
470  mocha.it('NormalizedOHMUrl source code har self import (inter-app hsp)', function () {
471    this.rollup.build();
472    this.rollup.share.projectConfig.useNormalizedOHMUrl = true;
473    this.rollup.share.projectConfig.pkgContextInfo = {
474      'pkghar': {
475        'packageName': 'pkghar',
476        'bundleName': 'com.test.testHsp',
477        'moduleName': '',
478        'version': '1.0.1',
479        'entryPath': 'Index.ets',
480        'isSO': false
481      }
482    }
483    const filePath: string = '/testHsp/har/src/main/ets/utils/Calc.ets';
484    const moduleInfo = {
485      id: filePath,
486      meta: {
487        pkgName: 'pkghar',
488        pkgPath: '/testHsp/har'
489      }
490    }
491    this.rollup.moduleInfos.push(moduleInfo);
492    const importerFile: string = '/testHsp/har/src/main/ets/pages/Index.ets'
493    const relativePath: string = '../utils/Calc';
494    const etsBasedAbsolutePath: string = 'ets/utils/Calc';
495    const standardImportPath: string = 'pkghar/src/main/ets/utils/Calc';
496    const moduleSourceFile: string = new ModuleSourceFile();
497    ModuleSourceFile.initPluginEnv(this.rollup); 
498    const relativePathOhmUrl: string = moduleSourceFile.getOhmUrl(this.rollup, relativePath, filePath, importerFile);
499    const etsBasedAbsolutePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, etsBasedAbsolutePath, filePath,
500      importerFile);
501    const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath,
502      importerFile);
503    const expectedNormalizedOhmUrl: string = '@normalized:N&&com.test.testHsp&pkghar/src/main/ets/utils/Calc&1.0.1';
504    expect(relativePathOhmUrl == expectedNormalizedOhmUrl).to.be.true;
505    expect(etsBasedAbsolutePathOhmUrl == expectedNormalizedOhmUrl).to.be.true;
506    expect(standardImportPathOhmUrl == expectedNormalizedOhmUrl).to.be.true;
507  });
508
509  mocha.it('NormalizedOHMUrl source code har others import (inter-app hsp)', function () {
510    this.rollup.build();
511    this.rollup.share.projectConfig.useNormalizedOHMUrl = true;
512    this.rollup.share.projectConfig.pkgContextInfo = {
513      'pkghar': {
514        'packageName': 'pkghar',
515        'bundleName': 'com.test.testHsp',
516        'moduleName': '',
517        'version': '1.0.1',
518        'entryPath': 'Index.ets',
519        'isSO': false
520      }
521    }
522    const filePath: string = '/testHsp/har/src/main/ets/utils/Calc.ets';
523    const indexFilePath: string = '/testHsp/har/Index.ets';
524    for (let file of [filePath, indexFilePath]) {
525      const moduleInfo = {
526        id: file,
527        meta: {
528          pkgName: 'pkghar',
529          pkgPath: '/testHsp/har'
530        }
531      }
532      this.rollup.moduleInfos.push(moduleInfo);
533    }
534    const importerFile: string = '/testHsp/hsp/src/main/ets/pages/Index.ets'
535    const importByPkgName = 'pkghar';
536    const standardImportPath: string = 'pkghar/src/main/ets/utils/Calc';
537    const moduleSourceFile: string = new ModuleSourceFile();
538    ModuleSourceFile.initPluginEnv(this.rollup);
539    const importByPkgNameOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, importByPkgName, indexFilePath, importerFile);
540    const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath,
541      importerFile);
542    const importByPkgNameNormalizedOhmUrl: string = '@normalized:N&&com.test.testHsp&pkghar/Index&1.0.1';
543    const standardImportPathNormalizedOhmUrl: string =
544      '@normalized:N&&com.test.testHsp&pkghar/src/main/ets/utils/Calc&1.0.1';
545    expect(importByPkgNameOhmUrl == importByPkgNameNormalizedOhmUrl).to.be.true;
546    expect(standardImportPathOhmUrl == standardImportPathNormalizedOhmUrl).to.be.true;
547  });
548
549  mocha.it('NormalizedOHMUrl product har self import (hap/in-app hsp)', function () {
550    this.rollup.build();
551    this.rollup.share.projectConfig.useNormalizedOHMUrl = true;
552    this.rollup.share.projectConfig.pkgContextInfo = {
553      'pkghar': {
554        'packageName': 'pkghar',
555        'bundleName': '',
556        'moduleName': '',
557        'version': '1.0.1',
558        'entryPath': 'Index.ets',
559        'isSO': false
560      }
561    }
562    const filePath: string = '/testHar/har/src/main/ets/utils/Calc.ets';
563    const moduleInfo = {
564      id: filePath,
565      meta: {
566        pkgName: 'pkghar',
567        pkgPath: '/testHar/har'
568      }
569    }
570    this.rollup.moduleInfos.push(moduleInfo);
571    const importerFile: string = '/testHar/har/src/main/ets/pages/Index.ets'
572    const relativePath: string = '../utils/Calc';
573    const etsBasedAbsolutePath: string = 'ets/utils/Calc';
574    const standardImportPath: string = 'pkghar/src/main/ets/utils/Calc';
575    const moduleSourceFile: string = new ModuleSourceFile();
576    ModuleSourceFile.initPluginEnv(this.rollup); 
577    const relativePathOhmUrl: string = moduleSourceFile.getOhmUrl(this.rollup, relativePath, filePath, importerFile);
578    const etsBasedAbsolutePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, etsBasedAbsolutePath, filePath,
579      importerFile);
580    const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath,
581      importerFile);
582    const expectedNormalizedOhmUrl: string = '@normalized:N&&&pkghar/src/main/ets/utils/Calc&1.0.1';
583    expect(relativePathOhmUrl == expectedNormalizedOhmUrl).to.be.true;
584    expect(etsBasedAbsolutePathOhmUrl == expectedNormalizedOhmUrl).to.be.true;
585    expect(standardImportPathOhmUrl == expectedNormalizedOhmUrl).to.be.true;
586  });
587
588  mocha.it('NormalizedOHMUrl product har others import (hap/in-app hsp)', function () {
589    this.rollup.build();
590    this.rollup.share.projectConfig.useNormalizedOHMUrl = true;
591    this.rollup.share.projectConfig.pkgContextInfo = {
592      'pkghar': {
593        'packageName': 'pkghar',
594        'bundleName': '',
595        'moduleName': '',
596        'version': '1.0.1',
597        'entryPath': 'Index.ets',
598        'isSO': false
599      }
600    }
601    const filePath: string = '/testHap/oh_modules/.ohpm/pkghar@test=/oh_modules/pkghar/src/main/ets/utils/Calc.ets';
602    const indexFilePath: string = '/testHap/oh_modules/.ohpm/pkghar@test=/oh_modules/pkghar/Index.ets';
603    for (let file of [filePath, indexFilePath]) {
604      const moduleInfo = {
605        id: file,
606        meta: {
607          pkgName: 'pkghar',
608          pkgPath: '/testHap/oh_modules/.ohpm/pkghar@test=/oh_modules/pkghar'
609        }
610      }
611      this.rollup.moduleInfos.push(moduleInfo);
612    }
613    const importerFile: string = '/testHar/entry/src/main/ets/pages/index.ets'
614    const importByPkgName = 'pkghar';
615    const standardImportPath: string = 'pkghar/src/main/ets/utils/Calc';
616    const moduleSourceFile: string = new ModuleSourceFile();
617    ModuleSourceFile.initPluginEnv(this.rollup);
618    const importByPkgNameOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, importByPkgName, indexFilePath, importerFile);
619    const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath,
620      importerFile);
621    const importByPkgNameNormalizedOhmUrl: string = '@normalized:N&&&pkghar/Index&1.0.1';
622    const standardImportPathNormalizedOhmUrl: string = '@normalized:N&&&pkghar/src/main/ets/utils/Calc&1.0.1';
623    expect(importByPkgNameOhmUrl == importByPkgNameNormalizedOhmUrl).to.be.true;
624    expect(standardImportPathOhmUrl == standardImportPathNormalizedOhmUrl).to.be.true;
625  });
626
627  mocha.it('NormalizedOHMUrl remote source code har self import (inter-app hsp)', function () {
628    this.rollup.build();
629    this.rollup.share.projectConfig.useNormalizedOHMUrl = true;
630    this.rollup.share.projectConfig.pkgContextInfo = {
631      'pkghar': {
632        'packageName': 'pkghar',
633        'bundleName': 'com.test.testHsp',
634        'moduleName': '',
635        'version': '1.0.1',
636        'entryPath': 'Index.ets',
637        'isSO': false
638      }
639    }
640    const filePath: string = '/testHsp/har/src/main/ets/utils/Calc.ets';
641    const moduleInfo = {
642      id: filePath,
643      meta: {
644        pkgName: 'pkghar',
645        pkgPath: '/testHsp/har'
646      }
647    }
648    this.rollup.moduleInfos.push(moduleInfo);
649    const importerFile: string = '/testHsp/har/src/main/ets/pages/Index.ets'
650    const relativePath: string = '../utils/Calc';
651    const etsBasedAbsolutePath: string = 'ets/utils/Calc';
652    const standardImportPath: string = 'pkghar/src/main/ets/utils/Calc';
653    const moduleSourceFile: string = new ModuleSourceFile();
654    ModuleSourceFile.initPluginEnv(this.rollup); 
655    const relativePathOhmUrl: string = moduleSourceFile.getOhmUrl(this.rollup, relativePath, filePath, importerFile);
656    const etsBasedAbsolutePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, etsBasedAbsolutePath, filePath,
657      importerFile);
658    const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath,
659      importerFile);
660    const expectedNormalizedOhmUrl: string = '@normalized:N&&com.test.testHsp&pkghar/src/main/ets/utils/Calc&1.0.1';
661    expect(relativePathOhmUrl == expectedNormalizedOhmUrl).to.be.true;
662    expect(etsBasedAbsolutePathOhmUrl == expectedNormalizedOhmUrl).to.be.true;
663    expect(standardImportPathOhmUrl == expectedNormalizedOhmUrl).to.be.true;
664  });
665
666  mocha.it('NormalizedOHMUrl remote source code har others import (inter-app hsp)', function () {
667    this.rollup.build();
668    this.rollup.share.projectConfig.useNormalizedOHMUrl = true;
669    this.rollup.share.projectConfig.pkgContextInfo = {
670      'pkghar': {
671        'packageName': 'pkghar',
672        'bundleName': 'com.test.testHsp',
673        'moduleName': '',
674        'version': '1.0.1',
675        'entryPath': 'Index.ets',
676        'isSO': false
677      }
678    }
679    const filePath: string = '/testHsp/har/src/main/ets/utils/Calc.ets';
680    const indexFilePath: string = '/testHsp/har/Index.ets';
681    for (let file of [filePath, indexFilePath]) {
682      const moduleInfo = {
683        id: file,
684        meta: {
685          pkgName: 'pkghar',
686          pkgPath: '/testHsp/har'
687        }
688      }
689      this.rollup.moduleInfos.push(moduleInfo);
690    }
691    const importerFile: string = '/testHsp/hsp/src/main/ets/pages/Index.ets'
692    const importByPkgName = 'pkghar';
693    const standardImportPath: string = 'pkghar/src/main/ets/utils/Calc';
694    const moduleSourceFile: string = new ModuleSourceFile();
695    ModuleSourceFile.initPluginEnv(this.rollup);
696    const importByPkgNameOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, importByPkgName, indexFilePath, importerFile);
697    const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath,
698      importerFile);
699    const importByPkgNameNormalizedOhmUrl: string = '@normalized:N&&com.test.testHsp&pkghar/Index&1.0.1';
700    const standardImportPathNormalizedOhmUrl: string =
701      '@normalized:N&&com.test.testHsp&pkghar/src/main/ets/utils/Calc&1.0.1';
702    expect(importByPkgNameOhmUrl == importByPkgNameNormalizedOhmUrl).to.be.true;
703    expect(standardImportPathOhmUrl == standardImportPathNormalizedOhmUrl).to.be.true;
704  });
705
706  mocha.it('NormalizedOHMUrl native so others import (hap/in-app hsp)', function () {
707    this.rollup.build();
708    this.rollup.share.projectConfig.useNormalizedOHMUrl = true;
709    this.rollup.share.projectConfig.pkgContextInfo = {
710      'libproduct.so': {
711        'packageName': 'libproduct.so',
712        'bundleName': '',
713        'moduleName': '',
714        'version': '',
715        'entryPath': '',
716        'isSO': true
717      }
718    }
719    const importerFile: string = '/testHap/hsp/src/main/ets/pages/Index.ets'
720    const moduleRequest = 'libproduct.so';
721    const moduleSourceFile: string = new ModuleSourceFile();
722    ModuleSourceFile.initPluginEnv(this.rollup);
723    const moduleRequestOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, moduleRequest, undefined, importerFile);
724    const expectedNormalizedOhmUrl: string = '@normalized:Y&&&libproduct.so&';
725    expect(moduleRequestOhmUrl == expectedNormalizedOhmUrl).to.be.true;
726  });
727
728  mocha.it('NormalizedOHMUrl native so others import (inter-app hsp)', function () {
729    this.rollup.build();
730    this.rollup.share.projectConfig.useNormalizedOHMUrl = true;
731    this.rollup.share.projectConfig.pkgContextInfo = {
732      'libproduct.so': {
733        'packageName': 'libproduct.so',
734        'bundleName': 'com.test.testHsp',
735        'moduleName': '',
736        'version': '',
737        'entryPath': '',
738        'isSO': true
739      }
740    }
741    const importerFile: string = '/testHsp/hsp/src/main/ets/pages/Index.ets'
742    const moduleRequest = 'libproduct.so';
743    const moduleSourceFile: string = new ModuleSourceFile();
744    ModuleSourceFile.initPluginEnv(this.rollup);
745    const moduleRequestOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, moduleRequest, undefined, importerFile);
746    const expectedNormalizedOhmUrl: string = '@normalized:Y&&com.test.testHsp&libproduct.so&';
747    expect(moduleRequestOhmUrl == expectedNormalizedOhmUrl).to.be.true;
748  });
749
750  mocha.it('NormalizedOHMUrl native so others import (source code har)', function () {
751    this.rollup.build();
752    this.rollup.share.projectConfig.useNormalizedOHMUrl = true;
753    this.rollup.share.projectConfig.pkgContextInfo = {
754      'libhar.so': {
755        'packageName': 'libhar.so',
756        'bundleName': '',
757        'moduleName': '',
758        'version': '',
759        'entryPath': '',
760        'isSO': true
761      }
762    }
763    const importerFile: string = '/testHap/har/src/main/ets/pages/Index.ets'
764    const moduleRequest = 'libhar.so';
765    const moduleSourceFile: string = new ModuleSourceFile();
766    ModuleSourceFile.initPluginEnv(this.rollup);
767    const moduleRequestOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, moduleRequest, undefined, importerFile);
768    const expectedNormalizedOhmUrl: string = '@normalized:Y&&&libhar.so&';
769    expect(moduleRequestOhmUrl == expectedNormalizedOhmUrl).to.be.true;
770  });
771
772  mocha.it('NormalizedOHMUrl native so others import (product har)', function () {
773    this.rollup.build();
774    this.rollup.share.projectConfig.useNormalizedOHMUrl = true;
775    this.rollup.share.projectConfig.pkgContextInfo = {
776      'libhar.so': {
777        'packageName': 'libhar.so',
778        'bundleName': '',
779        'moduleName': '',
780        'version': '',
781        'entryPath': '',
782        'isSO': true
783      }
784    }
785    const importerFile: string =
786      '/testHap/oh_modules/.ohpm/pkghar@test+har=/oh_modules/pkghar/src/main/ets/pages/Index.ets';
787    const moduleRequest = 'libhar.so';
788    const moduleSourceFile: string = new ModuleSourceFile();
789    ModuleSourceFile.initPluginEnv(this.rollup);
790    const moduleRequestOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, moduleRequest, undefined, importerFile);
791    const expectedNormalizedOhmUrl: string = '@normalized:Y&&&libhar.so&';
792    expect(moduleRequestOhmUrl == expectedNormalizedOhmUrl).to.be.true;
793  });
794
795  mocha.it('NormalizedOHMUrl ohpm package others import (hap/in-app hsp)', function () {
796    this.rollup.build();
797    this.rollup.share.projectConfig.useNormalizedOHMUrl = true;
798    this.rollup.share.projectConfig.pkgContextInfo = {
799      '@ohos/Test': {
800        'packageName': '@ohos/Test',
801        'bundleName': '',
802        'moduleName': '',
803        'version': '2.3.1',
804        'entryPath': 'index.ets',
805        'isSO': false
806      }
807    }
808    const filePath: string =
809      '/testHap/oh_modules/.ohpm/@ohos+test@2.3.1/oh_modules/@ohos/test/src/main/ets/utils/Calc.ets'
810    const indexFilePath: string = '/testHap/oh_modules/.ohpm/@ohos+test@2.3.1/oh_modules/@ohos/test/index.ets';
811    for (let file of [filePath, indexFilePath]) {
812      const moduleInfo = {
813        id: file,
814        meta: {
815          pkgName: '@ohos/Test',
816          pkgPath: '/testHap/oh_modules/.ohpm/@ohos+test@2.3.1/oh_modules/@ohos/test'
817        }
818      }
819      this.rollup.moduleInfos.push(moduleInfo);
820    }
821    const importerFile: string = '/testHap/entry/src/main/ets/pages/index.ets'
822    const importByPkgName = '@ohos/Test';
823    const standardImportPath: string = '@ohos/Test/src/main/ets/utils/Calc';
824    const moduleSourceFile: string = new ModuleSourceFile();
825    ModuleSourceFile.initPluginEnv(this.rollup);
826    const importByPkgNameOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, importByPkgName, indexFilePath, importerFile);
827    const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath,
828      importerFile);
829    const importByPkgNameNormalizedOhmUrl: string = '@normalized:N&&&@ohos/Test/index&2.3.1';
830    const standardImportPathNormalizedOhmUrl: string = '@normalized:N&&&@ohos/Test/src/main/ets/utils/Calc&2.3.1';
831    expect(importByPkgNameOhmUrl == importByPkgNameNormalizedOhmUrl).to.be.true;
832    expect(standardImportPathOhmUrl == standardImportPathNormalizedOhmUrl).to.be.true;
833  });
834
835  mocha.it('NormalizedOHMUrl ohpm package others import (inter-app hsp)', function () {
836    this.rollup.build();
837    this.rollup.share.projectConfig.useNormalizedOHMUrl = true;
838    this.rollup.share.projectConfig.pkgContextInfo = {
839      '@ohos/Test': {
840        'packageName': '@ohos/Test',
841        'bundleName': 'com.test.testHsp',
842        'moduleName': '',
843        'version': '2.3.1',
844        'entryPath': 'index.ets',
845        'isSO': false
846      }
847    }
848    const filePath: string =
849      '/testHsp/oh_modules/.ohpm/@ohos+test@2.3.1/oh_modules/@ohos/test/src/main/ets/utils/Calc.ets'
850    const indexFilePath: string = '/testHsp/oh_modules/.ohpm/@ohos+test@2.3.1/oh_modules/@ohos/test/index.ets';
851    for (let file of [filePath, indexFilePath]) {
852      const moduleInfo = {
853        id: file,
854        meta: {
855          pkgName: '@ohos/Test',
856          pkgPath: '/testHsp/oh_modules/.ohpm/@ohos+test@2.3.1/oh_modules/@ohos/test'
857        }
858      }
859      this.rollup.moduleInfos.push(moduleInfo);
860    }
861    const importerFile: string = '/testHsp/entry/src/main/ets/pages/index.ets'
862    const importByPkgName = '@ohos/Test';
863    const standardImportPath: string = '@ohos/Test/src/main/ets/utils/Calc';
864    const moduleSourceFile: string = new ModuleSourceFile();
865    ModuleSourceFile.initPluginEnv(this.rollup);
866    const importByPkgNameOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, importByPkgName, indexFilePath, importerFile);
867    const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath,
868      importerFile);
869    const importByPkgNameNormalizedOhmUrl: string = '@normalized:N&&com.test.testHsp&@ohos/Test/index&2.3.1';
870    const standardImportPathNormalizedOhmUrl: string =
871      '@normalized:N&&com.test.testHsp&@ohos/Test/src/main/ets/utils/Calc&2.3.1';
872    expect(importByPkgNameOhmUrl == importByPkgNameNormalizedOhmUrl).to.be.true;
873    expect(standardImportPathOhmUrl == standardImportPathNormalizedOhmUrl).to.be.true;
874  });
875
876  mocha.it('the error message of getNormalizedOhmUrlByFilepath', function () {
877    this.rollup.build();
878    const pkgParams = {
879      pkgName: 'json5',
880      pkgPath: `${projectConfig.projectRootPath}/entry/oh_modules/json5`,
881      isRecordName: false
882    };
883    projectConfig.pkgContextInfo = {
884      'json5': undefined
885    };
886    const red: string = '\u001b[31m';
887    const reset: string = '\u001b[39m';
888    const filePath: string = `${projectConfig.projectRootPath}/entry/oh_modules/json5/dist/index.js`;
889    const moduleName: string = 'entry';
890    const importerFile: string = 'importTest.ts';
891    const logger = this.rollup.share.getLogger(GEN_ABC_PLUGIN_NAME)
892    const loggerStub = sinon.stub(logger, 'error');
893    try {
894      getNormalizedOhmUrlByFilepath(filePath, projectConfig, logger, pkgParams, importerFile);
895    } catch (e) {
896    }
897    expect(loggerStub.calledWith(red, 'ArkTS:ERROR Failed to resolve OhmUrl.\n' +
898      `Error Message: Failed to get a resolved OhmUrl for "${filePath}" imported by "${importerFile}".\n` +
899      `Solutions: > Check whether the module which ${filePath} belongs to is correctly configured.` +
900      '> Check the corresponding file name is correct(including case-sensitivity).', reset)).to.be.true;
901    loggerStub.restore();
902  });
903
904  mocha.it('transform mockConfigInfo', function () {
905    this.rollup.preview();
906    ModuleSourceFile.mockConfigInfo = PRVIEW_MOCK_CONFIG;
907    this.rollup.share.projectConfig.modulePath = `${projectConfig.projectRootPath}/entry`;
908    this.rollup.share.projectConfig.mockParams = {
909      etsSourceRootPath: 'src/main/ets',
910      mockConfigPath: `${projectConfig.projectRootPath}/entry/src/mock/mock-config.json5`
911    }
912    this.rollup.share.projectConfig.entryModuleName = 'entry';
913    const importerFile: string = `${projectConfig.projectRootPath}/entry/src/main/ets/pages/index.ets`;
914    const moduleInfo = {
915      id: importerFile,
916      meta: {
917        moduleName: 'entry',
918      }
919    };
920    this.rollup.moduleInfos.push(moduleInfo);
921    for (let moduleRequest in PRVIEW_MOCK_CONFIG) {
922      let mockPath = PRVIEW_MOCK_CONFIG[moduleRequest]
923      let filePath: string;
924      if (Object.prototype.hasOwnProperty.call(MOCK_CONFIG_FILEPATH, moduleRequest)) {
925        filePath = MOCK_CONFIG_FILEPATH[moduleRequest];
926        const moduleInfo = {
927          id: filePath,
928          meta: {
929            moduleName: moduleRequest === 'lib' ? 'lib' : 'entry',
930            pkgName: moduleRequest === 'lib' ? 'lib' : 'entry',
931            pkgPath: moduleRequest === 'lib' ? `${projectConfig.projectRootPath}/oh_modules/lib` :
932              `${projectConfig.projectRootPath}/entry`
933          }
934        };
935        this.rollup.moduleInfos.push(moduleInfo);
936      }
937      const moduleSourceFile: string = new ModuleSourceFile();
938      ModuleSourceFile.initPluginEnv(this.rollup);
939      ModuleSourceFile.setProcessMock(this.rollup);
940      moduleSourceFile.getOhmUrl(this.rollup, moduleRequest, filePath, importerFile);
941    }
942    const expectMockConfig: Object = {
943      '@ohos:bluetooth': {
944        source: '@bundle:com.example.app/entry/mock/ohos/bluetooth.mock'
945      },
946      '@bundle:com.example.app/entry/ets/calc': {
947        source: '@bundle:com.example.app/entry/mock/module/calc.mock'
948      },
949      '@bundle:/testProjectRootPath/oh_modules/lib/dist/index.js': {
950        source: '@bundle:com.example.app/entry/mock/module/bigInt.mock'
951      },
952      '@app:UtTestApplication/entry/entry': {
953        source: '@bundle:com.example.app/entry/mock/native/libentry.mock'
954      }
955    };
956    expect(ModuleSourceFile.newMockConfigInfo.toString() === expectMockConfig.toString()).to.be.true;
957    ModuleSourceFile.cleanUpObjects();
958  });
959
960  mocha.it('NormalizedOHMUrl transform mockConfigInfo', function () {
961    this.rollup.preview();
962    this.rollup.useNormalizedOHMUrl();
963    this.rollup.share.projectConfig.pkgContextInfo = {
964      'entry': {
965        'packageName': 'entry',
966        'bundleName': '',
967        'moduleName': '',
968        'version': '',
969        'entryPath': 'index.ets',
970        'isSO': false
971      },
972      'lib': {
973        'packageName': 'lib',
974        'bundleName': '',
975        'moduleName': 'lib',
976        'version': '',
977        'entryPath': 'index.ets',
978        'isSO': false
979      },
980      'libentry.so': {
981        'packageName': 'libentry.so',
982        'bundleName': '',
983        'moduleName': '',
984        'version': '',
985        'entryPath': '',
986        'isSO': true
987      }
988    };
989    ModuleSourceFile.mockConfigInfo = PRVIEW_MOCK_CONFIG;
990    this.rollup.share.projectConfig.modulePath = `${projectConfig.projectRootPath}/entry`;
991    this.rollup.share.projectConfig.mockParams = {
992      etsSourceRootPath: 'src/main/ets',
993      mockConfigPath: `${projectConfig.projectRootPath}/entry/src/mock/mock-config.json5`
994    }
995    this.rollup.share.projectConfig.entryModuleName = 'entry';
996    
997    const importerFile: string = `${projectConfig.projectRootPath}/entry/src/main/ets/pages/index.ets`;
998    const moduleInfo = {
999      id: importerFile,
1000      meta: {
1001        moduleName: 'entry',
1002        pkgName: 'entry',
1003        pkgPath: `${projectConfig.projectRootPath}/entry`
1004      }
1005    }
1006    this.rollup.moduleInfos.push(moduleInfo);
1007    
1008    for (let moduleRequest in PRVIEW_MOCK_CONFIG) {
1009      let mockPath = PRVIEW_MOCK_CONFIG[moduleRequest]
1010      let filePath: string;
1011      if (Object.prototype.hasOwnProperty.call(MOCK_CONFIG_FILEPATH, moduleRequest)) {
1012        filePath = MOCK_CONFIG_FILEPATH[moduleRequest];
1013        const moduleInfo = {
1014          id: filePath,
1015          meta: {
1016            moduleName: moduleRequest === 'lib' ? 'lib' : 'entry',
1017            pkgName: moduleRequest === 'lib' ? 'lib' : 'entry',
1018            pkgPath: moduleRequest === 'lib' ? `${projectConfig.projectRootPath}/oh_modules/lib` :
1019              `${projectConfig.projectRootPath}/entry`
1020          }
1021        }
1022        this.rollup.moduleInfos.push(moduleInfo);
1023      }
1024      const moduleSourceFile: string = new ModuleSourceFile();
1025      ModuleSourceFile.initPluginEnv(this.rollup);
1026      ModuleSourceFile.setProcessMock(this.rollup);
1027      moduleSourceFile.getOhmUrl(this.rollup, moduleRequest, filePath, importerFile);
1028    }
1029    const expectMockConfig = {
1030      '@ohos:bluetooth': {
1031        source: '@normalized:N&&&entry/src/main/mock/ohos/bluetooth.mock&'
1032      },
1033      '@normalized:N&&&entry/src/main/ets/calc&': {
1034        source: '@normalized:N&&&entry/src/main/mock/module/calc.mock&'
1035      },
1036      '@normalized:N&lib&&lib/dist/index&': {
1037        source: '@normalized:N&&&entry/src/main/mock/module/bigInt.mock&'
1038      },
1039      '@normalized:Y&&&libentry.so&': {
1040        source: '@normalized:N&&&entry/src/main/mock/native/libentry.mock&'
1041      }
1042    };
1043    expect(ModuleSourceFile.newMockConfigInfo.toString() === expectMockConfig.toString()).to.be.true;
1044    ModuleSourceFile.cleanUpObjects();
1045  });
1046
1047  mocha.it('NormalizedOHMUrl bytecode har import', function () {
1048    this.rollup.build();
1049    this.rollup.share.projectConfig.useNormalizedOHMUrl = true;
1050    this.rollup.share.projectConfig.pkgContextInfo = {
1051      'bytecode_har': {
1052        'packageName': 'bytecode_har',
1053        'bundleName': '',
1054        'moduleName': '',
1055        'version': '1.0.0',
1056        'entryPath': 'Index.ets',
1057        'isSO': false
1058      }
1059    }
1060    this.rollup.share.projectConfig.dependencyAliasMap = new Map([
1061      ['bytecode_alias', 'bytecode_har']
1062    ]);
1063    this.rollup.share.projectConfig.byteCodeHarInfo = {
1064      'bytecode_alias': {
1065        'abcPath':'D:\\projectPath\\bytecode_har\\modules.abc'
1066      }
1067    }
1068    const filePath: string = 'bytecode_alias/src/main/ets/utils/Calc';
1069    const indexFilePath: string = 'bytecode_alias'; 
1070
1071    const importerFile: string = '/testHap/entry/src/main/ets/pages/index.ets'
1072    const importByPkgName = 'bytecode_alias';
1073    const standardImportPath: string = 'bytecode_alias/src/main/ets/utils/Calc';
1074    const moduleSourceFile: string = new ModuleSourceFile();
1075    ModuleSourceFile.initPluginEnv(this.rollup);
1076    const importByPkgNameOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, importByPkgName, indexFilePath, importerFile);
1077    const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath,
1078      importerFile);
1079    const importByPkgNameNormalizedOhmUrl: string = '@normalized:N&&&bytecode_har/Index&1.0.0';
1080    const standardImportPathNormalizedOhmUrl: string = '@normalized:N&&&bytecode_har/src/main/ets/utils/Calc&1.0.0';
1081    expect(importByPkgNameOhmUrl == importByPkgNameNormalizedOhmUrl).to.be.true;
1082    expect(standardImportPathOhmUrl == standardImportPathNormalizedOhmUrl).to.be.true;
1083  });
1084
1085  mocha.it('useNormalizedOHMUrl app builtins error message', function () {
1086    this.rollup.build();
1087    this.rollup.useNormalizedOHMUrl();
1088    this.rollup.share.projectConfig.pkgContextInfo = {};
1089    const red: string = '\u001b[31m';
1090    const reset: string = '\u001b[39m';
1091    const logger = this.rollup.share.getLogger(GEN_ABC_PLUGIN_NAME);
1092    const loggerStub = sinon.stub(logger, 'error');
1093    const importerFile: string =
1094      '/testHap/oh_modules/.ohpm/pkghar@test+har=/oh_modules/pkghar/src/main/ets/pages/Index.ets';
1095    const appSoModuleRequest: string = 'libapplication.so';
1096    try {
1097      getOhmUrlBySystemApiOrLibRequest(appSoModuleRequest, this.rollup.share.projectConfig, logger,
1098        importerFile, true);
1099    } catch (e) {
1100    }
1101    expect(loggerStub.calledWith(red, 'ArkTS:INTERNAL ERROR: Can not get pkgContextInfo of package ' +
1102      `'${appSoModuleRequest}' which being imported by '${importerFile}'`, reset)).to.be.true;
1103    loggerStub.restore();
1104  });
1105
1106  mocha.it('the error message of getNormalizedOhmUrlByAliasName', function () {
1107    this.rollup.build();
1108    this.rollup.share.projectConfig.useNormalizedOHMUrl = true;
1109    this.rollup.share.projectConfig.pkgContextInfo = {
1110      'bytecode_har': {
1111        'packageName': 'bytecode_har',
1112        'bundleName': '',
1113        'moduleName': '',
1114        'version': '1.0.0',
1115        'entryPath': 'Index.ets',
1116        'isSO': false
1117      }
1118    }
1119    this.rollup.share.projectConfig.dependencyAliasMap = new Map([
1120      ['bytecode_alias', 'bytecode_har']
1121    ]);
1122    this.rollup.share.projectConfig.byteCodeHarInfo = {
1123      'bytecode_alias': {
1124        'abcPath': 'D:\\projectPath\\bytecode_har\\modules.abc'
1125      }
1126    }
1127
1128    const aliasPkgName = 'bytecode_alias';
1129    const pkgName = 'bytecode_har';
1130    const logger = this.rollup.share.getLogger(GEN_ABC_PLUGIN_NAME)
1131    const loggerStub = sinon.stub(logger, 'error');
1132    const red: string = '\u001b[31m';
1133    const reset: string = '\u001b[39m';
1134
1135    try {
1136      delete this.rollup.share.projectConfig.pkgContextInfo['bytecode_har']['entryPath'];
1137      getNormalizedOhmUrlByAliasName(aliasPkgName, this.rollup.share.projectConfig, logger);
1138    } catch (e) {
1139    }
1140
1141    expect(loggerStub.getCall(0).calledWith(red, `ArkTS:INTERNAL ERROR: Failed to find entry file of '${pkgName}'.\n` +
1142        `Error Message: Failed to obtain the entry file information of '${pkgName}' from the package context information.`, reset)).to.be.true;
1143
1144    try {
1145      delete this.rollup.share.projectConfig.pkgContextInfo['bytecode_har'];
1146      getNormalizedOhmUrlByAliasName(aliasPkgName, this.rollup.share.projectConfig, logger);
1147    } catch (e) {
1148    }
1149
1150    expect(loggerStub.getCall(1).calledWith(red, `ArkTS:INTERNAL ERROR: Failed to find package '${pkgName}'.\n` +
1151      `Error Message: Failed to obtain package '${pkgName}' from the package context information.`, reset)).to.be.true;
1152
1153    loggerStub.restore();
1154  });
1155});