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'; 33import { 34 ArkTSErrorDescription, 35 ArkTSInternalErrorDescription, 36 ErrorCode 37} from '../../../../lib/fast_build/ark_compiler/error_code'; 38import { 39 CommonLogger, 40 LogData, 41 LogDataFactory 42} from '../../../../lib/fast_build/ark_compiler/logger'; 43 44const PRVIEW_MOCK_CONFIG : Object = { 45 // system api mock 46 "@ohos.bluetooth": { 47 "source": "src/main/mock/ohos/bluetooth.mock.ts" 48 }, 49 // local function mock 50 "./src/main/ets/calc": { 51 "source": "src/main/mock/module/calc.mock.ts" 52 }, 53 // ohpm dependency mock 54 "lib": { 55 "source": "src/main/mock/module/bigInt.mock.ts" 56 }, 57 // native mock 58 "libentry.so": { 59 "source": "src/main/mock/native/libentry.mock.ts" 60 } 61} 62 63const MOCK_CONFIG_FILEPATH = { 64 'lib': `${projectConfig.projectRootPath}/oh_modules/lib/dist/index.js`, 65 './src/main/ets/calc': `${projectConfig.projectRootPath}/entry/src/main/ets/calc.ets`, 66} 67 68mocha.describe('generate ohmUrl', function () { 69 mocha.before(function () { 70 this.rollup = new RollUpPluginMock(); 71 }); 72 73 mocha.after(() => { 74 delete this.rollup; 75 }); 76 77 mocha.it('nested src main ets|js in filePath', function () { 78 const filePath: string = `${projectConfig.projectRootPath}/entry/src/main/ets/feature/src/main/js/` 79 + `subfeature/src/main/ets/pages/test.ts`; 80 const moduleName: string = 'entry'; 81 const moduleNamespace: string = 'library'; 82 let ohmUrl_1 = getOhmUrlByFilepath(filePath, projectConfig, undefined, moduleName); 83 let ohmUrl_2 = getOhmUrlByFilepath(filePath, projectConfig, undefined, moduleNamespace); 84 let expected_1 = 'UtTestApplication/entry/ets/feature/src/main/js/subfeature/src/main/ets/pages/test'; 85 let expected_2 = 'UtTestApplication/entry@library/ets/feature/src/main/js/subfeature/src/main/ets/pages/test'; 86 expect(ohmUrl_1 == expected_1).to.be.true; 87 expect(ohmUrl_2 == expected_2).to.be.true; 88 }); 89 90 mocha.it('nested src ohosTest ets|js in filePath', function () { 91 const filePath: string = `${projectConfig.projectRootPath}/entry/src/ohosTest/ets/feature/src/main/js/` 92 + `subfeature/src/main/ets/pages/test.ts`; 93 const moduleName: string = 'entry'; 94 const moduleNamespace: string = 'library'; 95 let ohmUrl_1 = getOhmUrlByFilepath(filePath, projectConfig, undefined, moduleName); 96 let ohmUrl_2 = getOhmUrlByFilepath(filePath, projectConfig, undefined, moduleNamespace); 97 let expected_1 = 'UtTestApplication/entry/ets/feature/src/main/js/subfeature/src/main/ets/pages/test'; 98 let expected_2 = 'UtTestApplication/entry@library/ets/feature/src/main/js/subfeature/src/main/ets/pages/test'; 99 expect(ohmUrl_1 == expected_1).to.be.true; 100 expect(ohmUrl_2 == expected_2).to.be.true; 101 }); 102 103 mocha.it('system builtins & app builtins', function () { 104 mainProjectConfig.bundleName = 'UtTestApplication'; 105 mainProjectConfig.moduleName = 'entry'; 106 const systemModuleRequest: string = '@system.app'; 107 const ohosModuleRequest: string = '@ohos.hilog'; 108 const appSoModuleRequest: string = 'libapplication.so'; 109 const systemOhmUrl: string = getOhmUrlBySystemApiOrLibRequest(systemModuleRequest); 110 const ohosOhmUrl: string = getOhmUrlBySystemApiOrLibRequest(ohosModuleRequest); 111 const appOhmUrl: string = getOhmUrlBySystemApiOrLibRequest(appSoModuleRequest); 112 const expectedSystemOhmUrl: string = '@native:system.app'; 113 const expectedOhosOhmUrl: string = '@ohos:hilog'; 114 const expectedappOhmUrl: string = '@app:UtTestApplication/entry/application'; 115 expect(systemOhmUrl == expectedSystemOhmUrl).to.be.true; 116 expect(ohosOhmUrl == expectedOhosOhmUrl).to.be.true; 117 expect(appOhmUrl == expectedappOhmUrl).to.be.true; 118 }); 119 120 mocha.it('shared library', function () { 121 const sharedLibraryPackageName: string = "@ohos/sharedLibrary"; 122 const sharedLibraryPackageNameSlashes: string = "@ohos/library///"; 123 const sharedLibraryPage: string = "@ohos/sharedLibrary/src/main/ets/pages/page1"; 124 const errorSharedLibrary: string = "@ohos/staticLibrary"; 125 const sharedLibraryPackageNameOhmUrl: string = getOhmUrlByExternalPackage(sharedLibraryPackageName, projectConfig); 126 const sharedLibraryPackageNameSlashesOhmUrl: string = getOhmUrlByExternalPackage(sharedLibraryPackageNameSlashes, projectConfig, ModuleSourceFile.logger, true); 127 const sharedLibraryPageOhmUrl: string = getOhmUrlByExternalPackage(sharedLibraryPage, projectConfig); 128 const errorSharedLibraryOhmUrl = getOhmUrlByExternalPackage(errorSharedLibrary, projectConfig); 129 const expectedSharedLibraryOhmUrl: string = "@bundle:UtTestApplication/sharedLibrary/ets/index"; 130 const expectedSharedLibrarySlashesOhmUrl: string = "@normalized:N&&&@ohos/library/Index&1.0.0"; 131 const expectedSharedLibraryPageOhmUrl: string = "@bundle:UtTestApplication/sharedLibrary/ets/pages/page1"; 132 const expectedErrorSharedLibraryOhmUrl = undefined; 133 expect(sharedLibraryPackageNameOhmUrl == expectedSharedLibraryOhmUrl).to.be.true; 134 expect(sharedLibraryPackageNameSlashesOhmUrl == expectedSharedLibrarySlashesOhmUrl).to.be.true; 135 expect(sharedLibraryPageOhmUrl == expectedSharedLibraryPageOhmUrl).to.be.true; 136 expect(errorSharedLibraryOhmUrl == expectedErrorSharedLibraryOhmUrl).to.be.true; 137 }); 138 139 mocha.it('project module', function () { 140 const filePath: string = `${projectConfig.projectRootPath}/entry/src/main/ets/pages/test.ts`; 141 const harFilePath = `${projectConfig.projectRootPath}/library/src/main/ets/pages/test.ts`; 142 const moduleName: string = 'entry'; 143 const moduleNamespace: string = 'library'; 144 const ohmUrl = getOhmUrlByFilepath(filePath, projectConfig, undefined, moduleName); 145 const harOhmUrl = getOhmUrlByFilepath(harFilePath, projectConfig, undefined, moduleNamespace); 146 const expected = 'UtTestApplication/entry/ets/pages/test'; 147 const harOhmUrlExpected = 'UtTestApplication/entry@library/ets/pages/test'; 148 expect(ohmUrl == expected).to.be.true; 149 expect(harOhmUrl == harOhmUrlExpected).to.be.true; 150 }); 151 152 mocha.it('thirdParty module', function () { 153 const moduleLevelPkgPath = `${projectConfig.projectRootPath}/entry/oh_modules/json5/dist/index.js`; 154 const projectLevelPkgPath = `${projectConfig.projectRootPath}/oh_modules/json5/dist/index.js`; 155 const moduleName: string = 'entry'; 156 const moduleLevelPkgOhmUrl = getOhmUrlByFilepath(moduleLevelPkgPath, projectConfig, undefined, undefined); 157 const projectLevelPkgOhmUrl = getOhmUrlByFilepath(projectLevelPkgPath, projectConfig, undefined, undefined); 158 const moduleLevelPkgOhmUrlExpected = `${PACKAGES}@${moduleName}/json5/dist/index`; 159 const projectLevelPkgOhmUrlExpected = `${PACKAGES}/json5/dist/index`; 160 expect(moduleLevelPkgOhmUrl == moduleLevelPkgOhmUrlExpected).to.be.true; 161 expect(projectLevelPkgOhmUrl == projectLevelPkgOhmUrlExpected).to.be.true; 162 }); 163 164 mocha.it('static library entry', function () { 165 const staticLibraryEntry = `${projectConfig.projectRootPath}/library/index.ets`; 166 const moduleNamespace: string = 'library'; 167 const staticLibraryEntryOhmUrl = 168 getOhmUrlByFilepath(staticLibraryEntry, projectConfig, undefined, moduleNamespace); 169 const staticLibraryEntryOhmUrlExpected = 'UtTestApplication/entry@library/index'; 170 expect(staticLibraryEntryOhmUrl == staticLibraryEntryOhmUrlExpected).to.be.true; 171 }); 172 173 mocha.it('ohosTest module', function () { 174 const ohosTestfilePath = `${projectConfig.projectRootPath}/entry/src/ohosTest/ets/pages/test.ts`; 175 const moduleName: string = 'entry'; 176 const ohmUrl = getOhmUrlByFilepath(ohosTestfilePath, projectConfig, undefined, moduleName); 177 const expected = 'UtTestApplication/entry/ets/pages/test'; 178 expect(ohmUrl == expected).to.be.true; 179 }); 180 181 mocha.it('the error message of processPackageDir', function () { 182 this.rollup.build(); 183 projectConfig.modulePathMap = {}; 184 const filePath: string = `${projectConfig.projectRootPath}/entry/oh_modules/json5/dist/index.js`; 185 const moduleName: string = 'entry'; 186 const importerFile: string = 'importTest.ts'; 187 const errInfo: LogData = LogDataFactory.newInstance( 188 ErrorCode.ETS2BUNDLE_EXTERNAL_FAILED_TO_RESOLVE_OHM_URL, 189 ArkTSErrorDescription, 190 'Failed to resolve OhmUrl. ' + 191 'Failed to get a resolved OhmUrl for "/testProjectRootPath/entry/oh_modules/json5/dist/index.js" imported by "importTest.ts".', 192 '', 193 ['Check whether the module which /testProjectRootPath/entry/oh_modules/json5/dist/index.js belongs to is correctly configured.', 194 'Check the corresponding file name is correct(including case-sensitivity).'] 195 ); 196 const logger = CommonLogger.getInstance(this.rollup); 197 const stub = sinon.stub(logger.getLoggerFromErrorCode(errInfo.code), 'printError'); 198 getOhmUrlByFilepath(filePath, projectConfig, logger, moduleName, importerFile); 199 expect(stub.calledWith(errInfo)).to.be.true; 200 stub.restore(); 201 }); 202 203 mocha.it('the error message of processPackageDir without getHvigorConsoleLogger', function () { 204 this.rollup.build(); 205 projectConfig.modulePathMap = {}; 206 const filePath: string = `${projectConfig.projectRootPath}/entry/oh_modules/json5/dist/index.js`; 207 const moduleName: string = 'entry'; 208 const importerFile: string = 'importTest.ts'; 209 const errInfo: LogData = LogDataFactory.newInstance( 210 ErrorCode.ETS2BUNDLE_EXTERNAL_FAILED_TO_RESOLVE_OHM_URL, 211 ArkTSErrorDescription, 212 'Failed to resolve OhmUrl. ' + 213 'Failed to get a resolved OhmUrl for "/testProjectRootPath/entry/oh_modules/json5/dist/index.js" imported by "importTest.ts".', 214 '', 215 ['Check whether the module which /testProjectRootPath/entry/oh_modules/json5/dist/index.js belongs to is correctly configured.', 216 'Check the corresponding file name is correct(including case-sensitivity).'] 217 ); 218 CommonLogger.destroyInstance(); 219 const getHvigorConsoleLogger = this.rollup.share.getHvigorConsoleLogger; 220 this.rollup.share.getHvigorConsoleLogger = undefined; 221 const logger = CommonLogger.getInstance(this.rollup); 222 const stub = sinon.stub(logger.logger, 'error'); 223 getOhmUrlByFilepath(filePath, projectConfig, logger, moduleName, importerFile); 224 expect(stub.calledWith(errInfo.toString())).to.be.true; 225 CommonLogger.destroyInstance(); 226 this.rollup.share.getHvigorConsoleLogger = getHvigorConsoleLogger; 227 stub.restore(); 228 }); 229 230 mocha.it('the error message of processPackageDir(packageDir is invalid value)', function () { 231 this.rollup.build(); 232 projectConfig.packageDir = undefined; 233 projectConfig.modulePathMap = {}; 234 const filePath: string = `${projectConfig.projectRootPath}/entry/oh_modules/json5/dist/index.js`; 235 const moduleName: string = 'entry'; 236 const importerFile: string = 'importTest.ts'; 237 const errInfo: LogData = LogDataFactory.newInstance( 238 ErrorCode.ETS2BUNDLE_EXTERNAL_FAILED_TO_RESOLVE_OHM_URL, 239 ArkTSErrorDescription, 240 'Failed to resolve OhmUrl. Failed to get a resolved OhmUrl for ' + 241 '"/testProjectRootPath/entry/oh_modules/json5/dist/index.js" imported by "importTest.ts".', 242 '', 243 ['Check whether the module which /testProjectRootPath/entry/oh_modules/json5/dist/index.js belongs to is correctly configured.', 244 'Check the corresponding file name is correct(including case-sensitivity).'] 245 ); 246 const logger = CommonLogger.getInstance(this.rollup); 247 const stub = sinon.stub(logger.getLoggerFromErrorCode(errInfo.code), 'printError'); 248 getOhmUrlByFilepath(filePath, projectConfig, logger, moduleName, importerFile); 249 expect(stub.calledWith(errInfo)).to.be.true; 250 stub.restore(); 251 }); 252 253 mocha.it('the error message of processPackageDir(packageDir is invalid value) ' + 254 'without getHvigorConsoleLogger', function () { 255 this.rollup.build(); 256 projectConfig.packageDir = undefined; 257 projectConfig.modulePathMap = {}; 258 const filePath: string = `${projectConfig.projectRootPath}/entry/oh_modules/json5/dist/index.js`; 259 const moduleName: string = 'entry'; 260 const importerFile: string = 'importTest.ts'; 261 const errInfo: LogData = LogDataFactory.newInstance( 262 ErrorCode.ETS2BUNDLE_EXTERNAL_FAILED_TO_RESOLVE_OHM_URL, 263 ArkTSErrorDescription, 264 'Failed to resolve OhmUrl. Failed to get a resolved OhmUrl for ' + 265 '"/testProjectRootPath/entry/oh_modules/json5/dist/index.js" imported by "importTest.ts".', 266 '', 267 ['Check whether the module which /testProjectRootPath/entry/oh_modules/json5/dist/index.js belongs to is correctly configured.', 268 'Check the corresponding file name is correct(including case-sensitivity).'] 269 ); 270 CommonLogger.destroyInstance(); 271 const getHvigorConsoleLogger = this.rollup.share.getHvigorConsoleLogger; 272 this.rollup.share.getHvigorConsoleLogger = undefined; 273 const logger = CommonLogger.getInstance(this.rollup); 274 const stub = sinon.stub(logger.logger, 'error'); 275 getOhmUrlByFilepath(filePath, projectConfig, logger, moduleName, importerFile); 276 expect(stub.calledWith(errInfo.toString())).to.be.true; 277 CommonLogger.destroyInstance(); 278 this.rollup.share.getHvigorConsoleLogger = getHvigorConsoleLogger; 279 stub.restore(); 280 }); 281 282 mocha.it('NormalizedOHMUrl inter-app hsp self import', function () { 283 this.rollup.build(); 284 this.rollup.share.projectConfig.useNormalizedOHMUrl = true; 285 this.rollup.share.projectConfig.pkgContextInfo = { 286 'pkghsp': { 287 'packageName': 'pkghsp', 288 'bundleName': 'com.test.testHsp', 289 'moduleName': '', 290 'version': '', 291 'entryPath': 'Index.ets', 292 'isSO': false 293 } 294 } 295 const filePath: string = '/testHsp/hsp/src/main/ets/utils/Calc.ets'; 296 const moduleInfo = { 297 id: filePath, 298 meta: { 299 pkgName: 'pkghsp', 300 pkgPath: '/testHsp/hsp' 301 } 302 } 303 this.rollup.moduleInfos.push(moduleInfo); 304 const importerFile: string = '/testHsp/hsp/src/main/ets/pages/Index.ets' 305 const relativePath: string = '../utils/Calc'; 306 const etsBasedAbsolutePath: string = 'ets/utils/Calc'; 307 const standardImportPath: string = 'pkghsp/src/main/ets/utils/Calc'; 308 const moduleSourceFile: string = new ModuleSourceFile(); 309 ModuleSourceFile.initPluginEnv(this.rollup); 310 const relativePathOhmUrl: string = moduleSourceFile.getOhmUrl(this.rollup, relativePath, filePath, importerFile); 311 const etsBasedAbsolutePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, etsBasedAbsolutePath, filePath, 312 importerFile); 313 const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, 314 importerFile); 315 const expectedNormalizedOhmUrl: string = '@normalized:N&&com.test.testHsp&pkghsp/src/main/ets/utils/Calc&'; 316 expect(relativePathOhmUrl == expectedNormalizedOhmUrl).to.be.true; 317 expect(etsBasedAbsolutePathOhmUrl == expectedNormalizedOhmUrl).to.be.true; 318 expect(standardImportPathOhmUrl == expectedNormalizedOhmUrl).to.be.true; 319 }); 320 321 mocha.it('NormalizedOHMUrl inter-app hsp others import', function () { 322 this.rollup.build(); 323 this.rollup.share.projectConfig.useNormalizedOHMUrl = true; 324 this.rollup.share.projectConfig.pkgContextInfo = { 325 'pkghsp': { 326 'packageName': 'pkghsp', 327 'bundleName': 'com.test.testHsp', 328 'moduleName': 'hsp', 329 'version': '', 330 'entryPath': 'Index.ets', 331 'isSO': false 332 } 333 } 334 this.rollup.share.projectConfig.dependencyAliasMap = new Map([ 335 ['pkghsp_alias', 'pkghsp'] 336 ]); 337 this.rollup.share.projectConfig.harNameOhmMap = { 338 'pkghsp_alias': '@bundle:com.test.testHsp/src/main/ets/utils/Calc' 339 } 340 const filePath: string = 'pkghsp/src/main/ets/utils/Calc'; 341 const indexFilePath: string = 'pkghsp_alias'; 342 const importerFile: string = '/testHap/entry/src/main/ets/pages/index.ets' 343 const importByPkgName = 'pkghsp_alias'; 344 const standardImportPath: string = 'pkghsp_alias/src/main/ets/utils/Calc'; 345 const moduleSourceFile: string = new ModuleSourceFile(); 346 ModuleSourceFile.initPluginEnv(this.rollup); 347 const importByPkgNameOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, importByPkgName, indexFilePath, importerFile); 348 const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, 349 importerFile); 350 const importByPkgNameNormalizedOhmUrl: string = '@normalized:N&hsp&com.test.testHsp&pkghsp/Index&'; 351 const standardImportPathNormalizedOhmUrl: string = 352 '@normalized:N&hsp&com.test.testHsp&pkghsp/src/main/ets/utils/Calc&'; 353 expect(importByPkgNameOhmUrl == importByPkgNameNormalizedOhmUrl).to.be.true; 354 expect(standardImportPathOhmUrl == standardImportPathNormalizedOhmUrl).to.be.true; 355 }); 356 357 mocha.it('NormalizedOHMUrl in-app hsp self import', function () { 358 this.rollup.build(); 359 this.rollup.share.projectConfig.useNormalizedOHMUrl = true; 360 this.rollup.share.projectConfig.pkgContextInfo = { 361 'pkghsp': { 362 'packageName': 'pkghsp', 363 'bundleName': '', 364 'moduleName': '', 365 'version': '', 366 'entryPath': 'Index.ets', 367 'isSO': false 368 } 369 } 370 const filePath: string = '/testHsp/hsp/src/main/ets/utils/Calc.ets'; 371 const moduleInfo = { 372 id: filePath, 373 meta: { 374 pkgName: 'pkghsp', 375 pkgPath: '/testHsp/hsp' 376 } 377 } 378 this.rollup.moduleInfos.push(moduleInfo); 379 const importerFile: string = '/testHsp/hsp/src/main/ets/pages/Index.ets' 380 const relativePath: string = '../utils/Calc'; 381 const etsBasedAbsolutePath: string = 'ets/utils/Calc'; 382 const standardImportPath: string = 'pkghsp/src/main/ets/utils/Calc'; 383 const moduleSourceFile: string = new ModuleSourceFile(); 384 ModuleSourceFile.initPluginEnv(this.rollup); 385 const relativePathOhmUrl: string = moduleSourceFile.getOhmUrl(this.rollup, relativePath, filePath, importerFile); 386 const etsBasedAbsolutePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, etsBasedAbsolutePath, filePath, 387 importerFile); 388 const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, 389 importerFile); 390 const expectedNormalizedOhmUrl: string = '@normalized:N&&&pkghsp/src/main/ets/utils/Calc&'; 391 expect(relativePathOhmUrl == expectedNormalizedOhmUrl).to.be.true; 392 expect(etsBasedAbsolutePathOhmUrl == expectedNormalizedOhmUrl).to.be.true; 393 expect(standardImportPathOhmUrl == expectedNormalizedOhmUrl).to.be.true; 394 }); 395 396 mocha.it('NormalizedOHMUrl in-app hsp others import', function () { 397 this.rollup.build(); 398 this.rollup.share.projectConfig.useNormalizedOHMUrl = true; 399 this.rollup.share.projectConfig.pkgContextInfo = { 400 'pkghsp': { 401 'packageName': 'pkghsp', 402 'bundleName': '', 403 'moduleName': 'hsp', 404 'version': '', 405 'entryPath': 'Index.ets', 406 'isSO': false 407 } 408 } 409 this.rollup.share.projectConfig.dependencyAliasMap = new Map([ 410 ['pkghsp_alias', 'pkghsp'] 411 ]); 412 this.rollup.share.projectConfig.harNameOhmMap = { 413 'pkghsp_alias': '@bundle:com.test.testHap/src/main/ets/utils/Calc' 414 } 415 const filePath: string = 'pkghsp_alias/src/main/ets/utils/Calc'; 416 const indexFilePath: string = 'pkghsp_alias'; 417 418 const importerFile: string = '/testHap/entry/src/main/ets/pages/index.ets' 419 const importByPkgName = 'pkghsp_alias'; 420 const standardImportPath: string = 'pkghsp_alias/src/main/ets/utils/Calc'; 421 const moduleSourceFile: string = new ModuleSourceFile(); 422 ModuleSourceFile.initPluginEnv(this.rollup); 423 const importByPkgNameOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, importByPkgName, indexFilePath, importerFile); 424 const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, 425 importerFile); 426 const importByPkgNameNormalizedOhmUrl: string = '@normalized:N&hsp&&pkghsp/Index&'; 427 const standardImportPathNormalizedOhmUrl: string = '@normalized:N&hsp&&pkghsp/src/main/ets/utils/Calc&'; 428 expect(importByPkgNameOhmUrl == importByPkgNameNormalizedOhmUrl).to.be.true; 429 expect(standardImportPathOhmUrl == standardImportPathNormalizedOhmUrl).to.be.true; 430 }); 431 432 mocha.it('NormalizedOHMUrl hap self import', function () { 433 this.rollup.build(); 434 this.rollup.share.projectConfig.useNormalizedOHMUrl = true; 435 this.rollup.share.projectConfig.pkgContextInfo = { 436 'entry': { 437 'packageName': 'entry', 438 'bundleName': '', 439 'moduleName': '', 440 'version': '', 441 'entryPath': '', 442 'isSO': false 443 } 444 } 445 const filePath: string = '/testHap/entry/src/main/ets/utils/Calc.ets'; 446 const moduleInfo = { 447 id: filePath, 448 meta: { 449 pkgName: 'entry', 450 pkgPath: '/testHap/entry' 451 } 452 } 453 this.rollup.moduleInfos.push(moduleInfo); 454 const importerFile: string = '/testHap/entry/src/main/ets/pages/index.ets' 455 const relativePath: string = '../utils/Calc'; 456 const etsBasedAbsolutePath: string = 'ets/utils/Calc'; 457 const standardImportPath: string = 'entry/src/main/ets/utils/Calc'; 458 const moduleSourceFile: string = new ModuleSourceFile(); 459 ModuleSourceFile.initPluginEnv(this.rollup); 460 const relativePathOhmUrl: string = moduleSourceFile.getOhmUrl(this.rollup, relativePath, filePath, importerFile); 461 const etsBasedAbsolutePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, etsBasedAbsolutePath, filePath, 462 importerFile); 463 const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, 464 importerFile); 465 const expectedNormalizedOhmUrl: string = '@normalized:N&&&entry/src/main/ets/utils/Calc&'; 466 expect(relativePathOhmUrl == expectedNormalizedOhmUrl).to.be.true; 467 expect(etsBasedAbsolutePathOhmUrl == expectedNormalizedOhmUrl).to.be.true; 468 expect(standardImportPathOhmUrl == expectedNormalizedOhmUrl).to.be.true; 469 }); 470 471 mocha.it('NormalizedOHMUrl source code har self import (hap/in-app hsp)', function () { 472 this.rollup.build(); 473 this.rollup.share.projectConfig.useNormalizedOHMUrl = true; 474 this.rollup.share.projectConfig.pkgContextInfo = { 475 'pkghar': { 476 'packageName': 'pkghar', 477 'bundleName': '', 478 'moduleName': '', 479 'version': '1.0.1', 480 'entryPath': 'Index.ets', 481 'isSO': false 482 } 483 } 484 const filePath: string = '/testHar/har/src/main/ets/utils/Calc.ets'; 485 const moduleInfo = { 486 id: filePath, 487 meta: { 488 pkgName: 'pkghar', 489 pkgPath: '/testHar/har' 490 } 491 } 492 this.rollup.moduleInfos.push(moduleInfo); 493 const importerFile: string = '/testHar/har/src/main/ets/pages/Index.ets' 494 const relativePath: string = '../utils/Calc'; 495 const etsBasedAbsolutePath: string = 'ets/utils/Calc'; 496 const standardImportPath: string = 'pkghar/src/main/ets/utils/Calc'; 497 const moduleSourceFile: string = new ModuleSourceFile(); 498 ModuleSourceFile.initPluginEnv(this.rollup); 499 const relativePathOhmUrl: string = moduleSourceFile.getOhmUrl(this.rollup, relativePath, filePath, importerFile); 500 const etsBasedAbsolutePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, etsBasedAbsolutePath, filePath, 501 importerFile); 502 const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, 503 importerFile); 504 const expectedNormalizedOhmUrl: string = '@normalized:N&&&pkghar/src/main/ets/utils/Calc&1.0.1'; 505 expect(relativePathOhmUrl == expectedNormalizedOhmUrl).to.be.true; 506 expect(etsBasedAbsolutePathOhmUrl == expectedNormalizedOhmUrl).to.be.true; 507 expect(standardImportPathOhmUrl == expectedNormalizedOhmUrl).to.be.true; 508 }); 509 510 mocha.it('NormalizedOHMUrl source code har others import (hap/in-app hsp)', function () { 511 this.rollup.build(); 512 this.rollup.share.projectConfig.useNormalizedOHMUrl = true; 513 this.rollup.share.projectConfig.pkgContextInfo = { 514 'pkghar': { 515 'packageName': 'pkghar', 516 'bundleName': '', 517 'moduleName': '', 518 'version': '1.0.1', 519 'entryPath': 'Index.ets', 520 'isSO': false 521 } 522 } 523 const filePath: string = '/testHar/har/src/main/ets/utils/Calc.ets'; 524 const indexFilePath: string = '/testHar/har/Index.ets'; 525 for (let file of [filePath, indexFilePath]) { 526 const moduleInfo = { 527 id: file, 528 meta: { 529 pkgName: 'pkghar', 530 pkgPath: '/testHar/har' 531 } 532 } 533 this.rollup.moduleInfos.push(moduleInfo); 534 } 535 const importerFile: string = '/testHar/entry/src/main/ets/pages/Index.ets' 536 const importByPkgName = 'pkghar'; 537 const standardImportPath: string = 'pkghar/src/main/ets/utils/Calc'; 538 const moduleSourceFile: string = new ModuleSourceFile(); 539 ModuleSourceFile.initPluginEnv(this.rollup); 540 const importByPkgNameOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, importByPkgName, indexFilePath, importerFile); 541 const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, 542 importerFile); 543 const importByPkgNameNormalizedOhmUrl: string = '@normalized:N&&&pkghar/Index&1.0.1'; 544 const standardImportPathNormalizedOhmUrl: string = '@normalized:N&&&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 source code har self import (inter-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': 'com.test.testHsp', 556 'moduleName': '', 557 'version': '1.0.1', 558 'entryPath': 'Index.ets', 559 'isSO': false 560 } 561 } 562 const filePath: string = '/testHsp/har/src/main/ets/utils/Calc.ets'; 563 const moduleInfo = { 564 id: filePath, 565 meta: { 566 pkgName: 'pkghar', 567 pkgPath: '/testHsp/har' 568 } 569 } 570 this.rollup.moduleInfos.push(moduleInfo); 571 const importerFile: string = '/testHsp/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&&com.test.testHsp&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 source code har others import (inter-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': 'com.test.testHsp', 595 'moduleName': '', 596 'version': '1.0.1', 597 'entryPath': 'Index.ets', 598 'isSO': false 599 } 600 } 601 const filePath: string = '/testHsp/har/src/main/ets/utils/Calc.ets'; 602 const indexFilePath: string = '/testHsp/har/Index.ets'; 603 for (let file of [filePath, indexFilePath]) { 604 const moduleInfo = { 605 id: file, 606 meta: { 607 pkgName: 'pkghar', 608 pkgPath: '/testHsp/har' 609 } 610 } 611 this.rollup.moduleInfos.push(moduleInfo); 612 } 613 const importerFile: string = '/testHsp/hsp/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&&com.test.testHsp&pkghar/Index&1.0.1'; 622 const standardImportPathNormalizedOhmUrl: string = 623 '@normalized:N&&com.test.testHsp&pkghar/src/main/ets/utils/Calc&1.0.1'; 624 expect(importByPkgNameOhmUrl == importByPkgNameNormalizedOhmUrl).to.be.true; 625 expect(standardImportPathOhmUrl == standardImportPathNormalizedOhmUrl).to.be.true; 626 }); 627 628 mocha.it('NormalizedOHMUrl product har self import (hap/in-app hsp)', function () { 629 this.rollup.build(); 630 this.rollup.share.projectConfig.useNormalizedOHMUrl = true; 631 this.rollup.share.projectConfig.pkgContextInfo = { 632 'pkghar': { 633 'packageName': 'pkghar', 634 'bundleName': '', 635 'moduleName': '', 636 'version': '1.0.1', 637 'entryPath': 'Index.ets', 638 'isSO': false 639 } 640 } 641 const filePath: string = '/testHar/har/src/main/ets/utils/Calc.ets'; 642 const moduleInfo = { 643 id: filePath, 644 meta: { 645 pkgName: 'pkghar', 646 pkgPath: '/testHar/har' 647 } 648 } 649 this.rollup.moduleInfos.push(moduleInfo); 650 const importerFile: string = '/testHar/har/src/main/ets/pages/Index.ets' 651 const relativePath: string = '../utils/Calc'; 652 const etsBasedAbsolutePath: string = 'ets/utils/Calc'; 653 const standardImportPath: string = 'pkghar/src/main/ets/utils/Calc'; 654 const moduleSourceFile: string = new ModuleSourceFile(); 655 ModuleSourceFile.initPluginEnv(this.rollup); 656 const relativePathOhmUrl: string = moduleSourceFile.getOhmUrl(this.rollup, relativePath, filePath, importerFile); 657 const etsBasedAbsolutePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, etsBasedAbsolutePath, filePath, 658 importerFile); 659 const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, 660 importerFile); 661 const expectedNormalizedOhmUrl: string = '@normalized:N&&&pkghar/src/main/ets/utils/Calc&1.0.1'; 662 expect(relativePathOhmUrl == expectedNormalizedOhmUrl).to.be.true; 663 expect(etsBasedAbsolutePathOhmUrl == expectedNormalizedOhmUrl).to.be.true; 664 expect(standardImportPathOhmUrl == expectedNormalizedOhmUrl).to.be.true; 665 }); 666 667 mocha.it('NormalizedOHMUrl product har others import (hap/in-app hsp)', function () { 668 this.rollup.build(); 669 this.rollup.share.projectConfig.useNormalizedOHMUrl = true; 670 this.rollup.share.projectConfig.pkgContextInfo = { 671 'pkghar': { 672 'packageName': 'pkghar', 673 'bundleName': '', 674 'moduleName': '', 675 'version': '1.0.1', 676 'entryPath': 'Index.ets', 677 'isSO': false 678 } 679 } 680 const filePath: string = '/testHap/oh_modules/.ohpm/pkghar@test=/oh_modules/pkghar/src/main/ets/utils/Calc.ets'; 681 const indexFilePath: string = '/testHap/oh_modules/.ohpm/pkghar@test=/oh_modules/pkghar/Index.ets'; 682 for (let file of [filePath, indexFilePath]) { 683 const moduleInfo = { 684 id: file, 685 meta: { 686 pkgName: 'pkghar', 687 pkgPath: '/testHap/oh_modules/.ohpm/pkghar@test=/oh_modules/pkghar' 688 } 689 } 690 this.rollup.moduleInfos.push(moduleInfo); 691 } 692 const importerFile: string = '/testHar/entry/src/main/ets/pages/index.ets' 693 const importByPkgName = 'pkghar'; 694 const standardImportPath: string = 'pkghar/src/main/ets/utils/Calc'; 695 const moduleSourceFile: string = new ModuleSourceFile(); 696 ModuleSourceFile.initPluginEnv(this.rollup); 697 const importByPkgNameOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, importByPkgName, indexFilePath, importerFile); 698 const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, 699 importerFile); 700 const importByPkgNameNormalizedOhmUrl: string = '@normalized:N&&&pkghar/Index&1.0.1'; 701 const standardImportPathNormalizedOhmUrl: string = '@normalized:N&&&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 remote source code har self import (inter-app hsp)', function () { 707 this.rollup.build(); 708 this.rollup.share.projectConfig.useNormalizedOHMUrl = true; 709 this.rollup.share.projectConfig.pkgContextInfo = { 710 'pkghar': { 711 'packageName': 'pkghar', 712 'bundleName': 'com.test.testHsp', 713 'moduleName': '', 714 'version': '1.0.1', 715 'entryPath': 'Index.ets', 716 'isSO': false 717 } 718 } 719 const filePath: string = '/testHsp/har/src/main/ets/utils/Calc.ets'; 720 const moduleInfo = { 721 id: filePath, 722 meta: { 723 pkgName: 'pkghar', 724 pkgPath: '/testHsp/har' 725 } 726 } 727 this.rollup.moduleInfos.push(moduleInfo); 728 const importerFile: string = '/testHsp/har/src/main/ets/pages/Index.ets' 729 const relativePath: string = '../utils/Calc'; 730 const etsBasedAbsolutePath: string = 'ets/utils/Calc'; 731 const standardImportPath: string = 'pkghar/src/main/ets/utils/Calc'; 732 const moduleSourceFile: string = new ModuleSourceFile(); 733 ModuleSourceFile.initPluginEnv(this.rollup); 734 const relativePathOhmUrl: string = moduleSourceFile.getOhmUrl(this.rollup, relativePath, filePath, importerFile); 735 const etsBasedAbsolutePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, etsBasedAbsolutePath, filePath, 736 importerFile); 737 const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, 738 importerFile); 739 const expectedNormalizedOhmUrl: string = '@normalized:N&&com.test.testHsp&pkghar/src/main/ets/utils/Calc&1.0.1'; 740 expect(relativePathOhmUrl == expectedNormalizedOhmUrl).to.be.true; 741 expect(etsBasedAbsolutePathOhmUrl == expectedNormalizedOhmUrl).to.be.true; 742 expect(standardImportPathOhmUrl == expectedNormalizedOhmUrl).to.be.true; 743 }); 744 745 mocha.it('NormalizedOHMUrl remote source code har others import (inter-app hsp)', function () { 746 this.rollup.build(); 747 this.rollup.share.projectConfig.useNormalizedOHMUrl = true; 748 this.rollup.share.projectConfig.pkgContextInfo = { 749 'pkghar': { 750 'packageName': 'pkghar', 751 'bundleName': 'com.test.testHsp', 752 'moduleName': '', 753 'version': '1.0.1', 754 'entryPath': 'Index.ets', 755 'isSO': false 756 } 757 } 758 const filePath: string = '/testHsp/har/src/main/ets/utils/Calc.ets'; 759 const indexFilePath: string = '/testHsp/har/Index.ets'; 760 for (let file of [filePath, indexFilePath]) { 761 const moduleInfo = { 762 id: file, 763 meta: { 764 pkgName: 'pkghar', 765 pkgPath: '/testHsp/har' 766 } 767 } 768 this.rollup.moduleInfos.push(moduleInfo); 769 } 770 const importerFile: string = '/testHsp/hsp/src/main/ets/pages/Index.ets' 771 const importByPkgName = 'pkghar'; 772 const standardImportPath: string = 'pkghar/src/main/ets/utils/Calc'; 773 const moduleSourceFile: string = new ModuleSourceFile(); 774 ModuleSourceFile.initPluginEnv(this.rollup); 775 const importByPkgNameOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, importByPkgName, indexFilePath, importerFile); 776 const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, 777 importerFile); 778 const importByPkgNameNormalizedOhmUrl: string = '@normalized:N&&com.test.testHsp&pkghar/Index&1.0.1'; 779 const standardImportPathNormalizedOhmUrl: string = 780 '@normalized:N&&com.test.testHsp&pkghar/src/main/ets/utils/Calc&1.0.1'; 781 expect(importByPkgNameOhmUrl == importByPkgNameNormalizedOhmUrl).to.be.true; 782 expect(standardImportPathOhmUrl == standardImportPathNormalizedOhmUrl).to.be.true; 783 }); 784 785 mocha.it('NormalizedOHMUrl native so others import (hap/in-app hsp)', function () { 786 this.rollup.build(); 787 this.rollup.share.projectConfig.useNormalizedOHMUrl = true; 788 this.rollup.share.projectConfig.pkgContextInfo = { 789 'libproduct.so': { 790 'packageName': 'libproduct.so', 791 'bundleName': '', 792 'moduleName': '', 793 'version': '', 794 'entryPath': '', 795 'isSO': true 796 } 797 } 798 const importerFile: string = '/testHap/hsp/src/main/ets/pages/Index.ets' 799 const moduleRequest = 'libproduct.so'; 800 const moduleSourceFile: string = new ModuleSourceFile(); 801 ModuleSourceFile.initPluginEnv(this.rollup); 802 const moduleRequestOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, moduleRequest, undefined, importerFile); 803 const expectedNormalizedOhmUrl: string = '@normalized:Y&&&libproduct.so&'; 804 expect(moduleRequestOhmUrl == expectedNormalizedOhmUrl).to.be.true; 805 }); 806 807 mocha.it('NormalizedOHMUrl native so others import (inter-app hsp)', function () { 808 this.rollup.build(); 809 this.rollup.share.projectConfig.useNormalizedOHMUrl = true; 810 this.rollup.share.projectConfig.pkgContextInfo = { 811 'libproduct.so': { 812 'packageName': 'libproduct.so', 813 'bundleName': 'com.test.testHsp', 814 'moduleName': '', 815 'version': '', 816 'entryPath': '', 817 'isSO': true 818 } 819 } 820 const importerFile: string = '/testHsp/hsp/src/main/ets/pages/Index.ets' 821 const moduleRequest = 'libproduct.so'; 822 const moduleSourceFile: string = new ModuleSourceFile(); 823 ModuleSourceFile.initPluginEnv(this.rollup); 824 const moduleRequestOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, moduleRequest, undefined, importerFile); 825 const expectedNormalizedOhmUrl: string = '@normalized:Y&&com.test.testHsp&libproduct.so&'; 826 expect(moduleRequestOhmUrl == expectedNormalizedOhmUrl).to.be.true; 827 }); 828 829 mocha.it('NormalizedOHMUrl native so others import (source code har)', function () { 830 this.rollup.build(); 831 this.rollup.share.projectConfig.useNormalizedOHMUrl = true; 832 this.rollup.share.projectConfig.pkgContextInfo = { 833 'libhar.so': { 834 'packageName': 'libhar.so', 835 'bundleName': '', 836 'moduleName': '', 837 'version': '', 838 'entryPath': '', 839 'isSO': true 840 } 841 } 842 const importerFile: string = '/testHap/har/src/main/ets/pages/Index.ets' 843 const moduleRequest = 'libhar.so'; 844 const moduleSourceFile: string = new ModuleSourceFile(); 845 ModuleSourceFile.initPluginEnv(this.rollup); 846 const moduleRequestOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, moduleRequest, undefined, importerFile); 847 const expectedNormalizedOhmUrl: string = '@normalized:Y&&&libhar.so&'; 848 expect(moduleRequestOhmUrl == expectedNormalizedOhmUrl).to.be.true; 849 }); 850 851 mocha.it('NormalizedOHMUrl native so others import (product har)', function () { 852 this.rollup.build(); 853 this.rollup.share.projectConfig.useNormalizedOHMUrl = true; 854 this.rollup.share.projectConfig.pkgContextInfo = { 855 'libhar.so': { 856 'packageName': 'libhar.so', 857 'bundleName': '', 858 'moduleName': '', 859 'version': '', 860 'entryPath': '', 861 'isSO': true 862 } 863 } 864 const importerFile: string = 865 '/testHap/oh_modules/.ohpm/pkghar@test+har=/oh_modules/pkghar/src/main/ets/pages/Index.ets'; 866 const moduleRequest = 'libhar.so'; 867 const moduleSourceFile: string = new ModuleSourceFile(); 868 ModuleSourceFile.initPluginEnv(this.rollup); 869 const moduleRequestOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, moduleRequest, undefined, importerFile); 870 const expectedNormalizedOhmUrl: string = '@normalized:Y&&&libhar.so&'; 871 expect(moduleRequestOhmUrl == expectedNormalizedOhmUrl).to.be.true; 872 }); 873 874 mocha.it('NormalizedOHMUrl ohpm package others import (hap/in-app hsp)', function () { 875 this.rollup.build(); 876 this.rollup.share.projectConfig.useNormalizedOHMUrl = true; 877 this.rollup.share.projectConfig.pkgContextInfo = { 878 '@ohos/Test': { 879 'packageName': '@ohos/Test', 880 'bundleName': '', 881 'moduleName': '', 882 'version': '2.3.1', 883 'entryPath': 'index.ets', 884 'isSO': false 885 } 886 } 887 const filePath: string = 888 '/testHap/oh_modules/.ohpm/@ohos+test@2.3.1/oh_modules/@ohos/test/src/main/ets/utils/Calc.ets' 889 const indexFilePath: string = '/testHap/oh_modules/.ohpm/@ohos+test@2.3.1/oh_modules/@ohos/test/index.ets'; 890 for (let file of [filePath, indexFilePath]) { 891 const moduleInfo = { 892 id: file, 893 meta: { 894 pkgName: '@ohos/Test', 895 pkgPath: '/testHap/oh_modules/.ohpm/@ohos+test@2.3.1/oh_modules/@ohos/test' 896 } 897 } 898 this.rollup.moduleInfos.push(moduleInfo); 899 } 900 const importerFile: string = '/testHap/entry/src/main/ets/pages/index.ets' 901 const importByPkgName = '@ohos/Test'; 902 const standardImportPath: string = '@ohos/Test/src/main/ets/utils/Calc'; 903 const moduleSourceFile: string = new ModuleSourceFile(); 904 ModuleSourceFile.initPluginEnv(this.rollup); 905 const importByPkgNameOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, importByPkgName, indexFilePath, importerFile); 906 const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, 907 importerFile); 908 const importByPkgNameNormalizedOhmUrl: string = '@normalized:N&&&@ohos/Test/index&2.3.1'; 909 const standardImportPathNormalizedOhmUrl: string = '@normalized:N&&&@ohos/Test/src/main/ets/utils/Calc&2.3.1'; 910 expect(importByPkgNameOhmUrl == importByPkgNameNormalizedOhmUrl).to.be.true; 911 expect(standardImportPathOhmUrl == standardImportPathNormalizedOhmUrl).to.be.true; 912 }); 913 914 mocha.it('NormalizedOHMUrl ohpm package others import (inter-app hsp)', function () { 915 this.rollup.build(); 916 this.rollup.share.projectConfig.useNormalizedOHMUrl = true; 917 this.rollup.share.projectConfig.pkgContextInfo = { 918 '@ohos/Test': { 919 'packageName': '@ohos/Test', 920 'bundleName': 'com.test.testHsp', 921 'moduleName': '', 922 'version': '2.3.1', 923 'entryPath': 'index.ets', 924 'isSO': false 925 } 926 } 927 const filePath: string = 928 '/testHsp/oh_modules/.ohpm/@ohos+test@2.3.1/oh_modules/@ohos/test/src/main/ets/utils/Calc.ets' 929 const indexFilePath: string = '/testHsp/oh_modules/.ohpm/@ohos+test@2.3.1/oh_modules/@ohos/test/index.ets'; 930 for (let file of [filePath, indexFilePath]) { 931 const moduleInfo = { 932 id: file, 933 meta: { 934 pkgName: '@ohos/Test', 935 pkgPath: '/testHsp/oh_modules/.ohpm/@ohos+test@2.3.1/oh_modules/@ohos/test' 936 } 937 } 938 this.rollup.moduleInfos.push(moduleInfo); 939 } 940 const importerFile: string = '/testHsp/entry/src/main/ets/pages/index.ets' 941 const importByPkgName = '@ohos/Test'; 942 const standardImportPath: string = '@ohos/Test/src/main/ets/utils/Calc'; 943 const moduleSourceFile: string = new ModuleSourceFile(); 944 ModuleSourceFile.initPluginEnv(this.rollup); 945 const importByPkgNameOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, importByPkgName, indexFilePath, importerFile); 946 const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, 947 importerFile); 948 const importByPkgNameNormalizedOhmUrl: string = '@normalized:N&&com.test.testHsp&@ohos/Test/index&2.3.1'; 949 const standardImportPathNormalizedOhmUrl: string = 950 '@normalized:N&&com.test.testHsp&@ohos/Test/src/main/ets/utils/Calc&2.3.1'; 951 expect(importByPkgNameOhmUrl == importByPkgNameNormalizedOhmUrl).to.be.true; 952 expect(standardImportPathOhmUrl == standardImportPathNormalizedOhmUrl).to.be.true; 953 }); 954 955 mocha.it('the error message of getNormalizedOhmUrlByFilepath', function () { 956 this.rollup.build(); 957 const pkgParams = { 958 pkgName: 'json5', 959 pkgPath: `${projectConfig.projectRootPath}/entry/oh_modules/json5`, 960 isRecordName: false 961 }; 962 projectConfig.pkgContextInfo = { 963 'json5': undefined 964 }; 965 const filePath: string = `${projectConfig.projectRootPath}/entry/oh_modules/json5/dist/index.js`; 966 const moduleName: string = 'entry'; 967 const importerFile: string = 'importTest.ts'; 968 const errInfo: LogData = LogDataFactory.newInstance( 969 ErrorCode.ETS2BUNDLE_EXTERNAL_FAILED_TO_RESOLVE_OHM_URL, 970 ArkTSErrorDescription, 971 'Failed to resolve OhmUrl. ' + 972 'Failed to get a resolved OhmUrl for "/testProjectRootPath/entry/oh_modules/json5/dist/index.js" imported by "importTest.ts".', 973 '', 974 ['Check whether the "json5" module which /testProjectRootPath/entry/oh_modules/json5/dist/index.js belongs to is correctly configured.', 975 'Check the corresponding file name is correct(including case-sensitivity).'] 976 ); 977 const logger = CommonLogger.getInstance(this.rollup); 978 const stub = sinon.stub(logger.getLoggerFromErrorCode(errInfo.code), 'printError'); 979 try { 980 getNormalizedOhmUrlByFilepath(filePath, projectConfig, logger, pkgParams, importerFile); 981 } catch (e) { 982 } 983 expect(stub.calledWith(errInfo)).to.be.true; 984 stub.restore(); 985 }); 986 987 mocha.it('the error message of getNormalizedOhmUrlByFilepath without getHvigorConsoleLogger', function () { 988 this.rollup.build(); 989 const pkgParams = { 990 pkgName: 'json5', 991 pkgPath: `${projectConfig.projectRootPath}/entry/oh_modules/json5`, 992 isRecordName: false 993 }; 994 projectConfig.pkgContextInfo = { 995 'json5': undefined 996 }; 997 const filePath: string = `${projectConfig.projectRootPath}/entry/oh_modules/json5/dist/index.js`; 998 const moduleName: string = 'entry'; 999 const importerFile: string = 'importTest.ts'; 1000 const errInfo: LogData = LogDataFactory.newInstance( 1001 ErrorCode.ETS2BUNDLE_EXTERNAL_FAILED_TO_RESOLVE_OHM_URL, 1002 ArkTSErrorDescription, 1003 'Failed to resolve OhmUrl. ' + 1004 'Failed to get a resolved OhmUrl for "/testProjectRootPath/entry/oh_modules/json5/dist/index.js" imported by "importTest.ts".', 1005 '', 1006 ['Check whether the "json5" module which /testProjectRootPath/entry/oh_modules/json5/dist/index.js belongs to is correctly configured.', 1007 'Check the corresponding file name is correct(including case-sensitivity).'] 1008 ); 1009 CommonLogger.destroyInstance(); 1010 const getHvigorConsoleLogger = this.rollup.share.getHvigorConsoleLogger; 1011 this.rollup.share.getHvigorConsoleLogger = undefined; 1012 const logger = CommonLogger.getInstance(this.rollup); 1013 const stub = sinon.stub(logger.logger, 'error'); 1014 try { 1015 getNormalizedOhmUrlByFilepath(filePath, projectConfig, logger, pkgParams, importerFile); 1016 } catch (e) { 1017 } 1018 expect(stub.calledWith(errInfo.toString())).to.be.true; 1019 CommonLogger.destroyInstance(); 1020 this.rollup.share.getHvigorConsoleLogger = getHvigorConsoleLogger; 1021 stub.restore(); 1022 }); 1023 1024 mocha.it('transform mockConfigInfo', function () { 1025 this.rollup.preview(); 1026 ModuleSourceFile.mockConfigInfo = PRVIEW_MOCK_CONFIG; 1027 this.rollup.share.projectConfig.modulePath = `${projectConfig.projectRootPath}/entry`; 1028 this.rollup.share.projectConfig.mockParams = { 1029 etsSourceRootPath: 'src/main/ets', 1030 mockConfigPath: `${projectConfig.projectRootPath}/entry/src/mock/mock-config.json5` 1031 } 1032 this.rollup.share.projectConfig.entryModuleName = 'entry'; 1033 const importerFile: string = `${projectConfig.projectRootPath}/entry/src/main/ets/pages/index.ets`; 1034 const moduleInfo = { 1035 id: importerFile, 1036 meta: { 1037 moduleName: 'entry', 1038 } 1039 }; 1040 this.rollup.moduleInfos.push(moduleInfo); 1041 for (let moduleRequest in PRVIEW_MOCK_CONFIG) { 1042 let mockPath = PRVIEW_MOCK_CONFIG[moduleRequest] 1043 let filePath: string; 1044 if (Object.prototype.hasOwnProperty.call(MOCK_CONFIG_FILEPATH, moduleRequest)) { 1045 filePath = MOCK_CONFIG_FILEPATH[moduleRequest]; 1046 const moduleInfo = { 1047 id: filePath, 1048 meta: { 1049 moduleName: moduleRequest === 'lib' ? 'lib' : 'entry', 1050 pkgName: moduleRequest === 'lib' ? 'lib' : 'entry', 1051 pkgPath: moduleRequest === 'lib' ? `${projectConfig.projectRootPath}/oh_modules/lib` : 1052 `${projectConfig.projectRootPath}/entry` 1053 } 1054 }; 1055 this.rollup.moduleInfos.push(moduleInfo); 1056 } 1057 const moduleSourceFile: string = new ModuleSourceFile(); 1058 ModuleSourceFile.initPluginEnv(this.rollup); 1059 ModuleSourceFile.setProcessMock(this.rollup); 1060 moduleSourceFile.getOhmUrl(this.rollup, moduleRequest, filePath, importerFile); 1061 } 1062 const expectMockConfig: Object = { 1063 '@ohos:bluetooth': { 1064 source: '@bundle:com.example.app/entry/mock/ohos/bluetooth.mock' 1065 }, 1066 '@bundle:com.example.app/entry/ets/calc': { 1067 source: '@bundle:com.example.app/entry/mock/module/calc.mock' 1068 }, 1069 '@bundle:/testProjectRootPath/oh_modules/lib/dist/index.js': { 1070 source: '@bundle:com.example.app/entry/mock/module/bigInt.mock' 1071 }, 1072 '@app:UtTestApplication/entry/entry': { 1073 source: '@bundle:com.example.app/entry/mock/native/libentry.mock' 1074 } 1075 }; 1076 expect(ModuleSourceFile.newMockConfigInfo.toString() === expectMockConfig.toString()).to.be.true; 1077 ModuleSourceFile.cleanUpObjects(); 1078 }); 1079 1080 mocha.it('NormalizedOHMUrl transform mockConfigInfo', function () { 1081 this.rollup.preview(); 1082 this.rollup.useNormalizedOHMUrl(); 1083 this.rollup.share.projectConfig.pkgContextInfo = { 1084 'entry': { 1085 'packageName': 'entry', 1086 'bundleName': '', 1087 'moduleName': '', 1088 'version': '', 1089 'entryPath': 'index.ets', 1090 'isSO': false 1091 }, 1092 'lib': { 1093 'packageName': 'lib', 1094 'bundleName': '', 1095 'moduleName': 'lib', 1096 'version': '', 1097 'entryPath': 'index.ets', 1098 'isSO': false 1099 }, 1100 'libentry.so': { 1101 'packageName': 'libentry.so', 1102 'bundleName': '', 1103 'moduleName': '', 1104 'version': '', 1105 'entryPath': '', 1106 'isSO': true 1107 } 1108 }; 1109 ModuleSourceFile.mockConfigInfo = PRVIEW_MOCK_CONFIG; 1110 this.rollup.share.projectConfig.modulePath = `${projectConfig.projectRootPath}/entry`; 1111 this.rollup.share.projectConfig.mockParams = { 1112 etsSourceRootPath: 'src/main/ets', 1113 mockConfigPath: `${projectConfig.projectRootPath}/entry/src/mock/mock-config.json5` 1114 } 1115 this.rollup.share.projectConfig.entryModuleName = 'entry'; 1116 1117 const importerFile: string = `${projectConfig.projectRootPath}/entry/src/main/ets/pages/index.ets`; 1118 const moduleInfo = { 1119 id: importerFile, 1120 meta: { 1121 moduleName: 'entry', 1122 pkgName: 'entry', 1123 pkgPath: `${projectConfig.projectRootPath}/entry` 1124 } 1125 } 1126 this.rollup.moduleInfos.push(moduleInfo); 1127 1128 for (let moduleRequest in PRVIEW_MOCK_CONFIG) { 1129 let mockPath = PRVIEW_MOCK_CONFIG[moduleRequest] 1130 let filePath: string; 1131 if (Object.prototype.hasOwnProperty.call(MOCK_CONFIG_FILEPATH, moduleRequest)) { 1132 filePath = MOCK_CONFIG_FILEPATH[moduleRequest]; 1133 const moduleInfo = { 1134 id: filePath, 1135 meta: { 1136 moduleName: moduleRequest === 'lib' ? 'lib' : 'entry', 1137 pkgName: moduleRequest === 'lib' ? 'lib' : 'entry', 1138 pkgPath: moduleRequest === 'lib' ? `${projectConfig.projectRootPath}/oh_modules/lib` : 1139 `${projectConfig.projectRootPath}/entry` 1140 } 1141 } 1142 this.rollup.moduleInfos.push(moduleInfo); 1143 } 1144 const moduleSourceFile: string = new ModuleSourceFile(); 1145 ModuleSourceFile.initPluginEnv(this.rollup); 1146 ModuleSourceFile.setProcessMock(this.rollup); 1147 moduleSourceFile.getOhmUrl(this.rollup, moduleRequest, filePath, importerFile); 1148 } 1149 const expectMockConfig = { 1150 '@ohos:bluetooth': { 1151 source: '@normalized:N&&&entry/src/main/mock/ohos/bluetooth.mock&' 1152 }, 1153 '@normalized:N&&&entry/src/main/ets/calc&': { 1154 source: '@normalized:N&&&entry/src/main/mock/module/calc.mock&' 1155 }, 1156 '@normalized:N&lib&&lib/dist/index&': { 1157 source: '@normalized:N&&&entry/src/main/mock/module/bigInt.mock&' 1158 }, 1159 '@normalized:Y&&&libentry.so&': { 1160 source: '@normalized:N&&&entry/src/main/mock/native/libentry.mock&' 1161 } 1162 }; 1163 expect(ModuleSourceFile.newMockConfigInfo.toString() === expectMockConfig.toString()).to.be.true; 1164 ModuleSourceFile.cleanUpObjects(); 1165 }); 1166 1167 mocha.it('NormalizedOHMUrl bytecode har import', function () { 1168 this.rollup.build(); 1169 this.rollup.share.projectConfig.useNormalizedOHMUrl = true; 1170 this.rollup.share.projectConfig.pkgContextInfo = { 1171 'bytecode_har': { 1172 'packageName': 'bytecode_har', 1173 'bundleName': '', 1174 'moduleName': '', 1175 'version': '1.0.0', 1176 'entryPath': 'Index.ets', 1177 'isSO': false 1178 }, 1179 'bytecode_alias_oh': { 1180 'packageName': 'bytecode_alias_oh', 1181 'bundleName': '', 1182 'moduleName': '', 1183 'version': '1.0.0', 1184 'entryPath': 'Index.ets', 1185 'isSO': false 1186 } 1187 } 1188 this.rollup.share.projectConfig.dependencyAliasMap = new Map([ 1189 ['bytecode_alias', 'bytecode_har', 'bytecode_alias_oh'] 1190 ]); 1191 this.rollup.share.projectConfig.byteCodeHarInfo = { 1192 'bytecode_alias': { 1193 'abcPath':'D:\\projectPath\\bytecode_har\\modules.abc' 1194 }, 1195 'bytecode_alias_oh': { 1196 'abcPath':'D:\\projectPath\\bytecode_alias_oh\\modules.abc' 1197 } 1198 } 1199 const filePath: string = 'bytecode_alias/src/main/ets/utils/Calc'; 1200 const indexFilePath: string = 'bytecode_alias'; 1201 1202 const importerFile: string = '/testHap/entry/src/main/ets/pages/index.ets' 1203 const importByPkgName = 'bytecode_alias'; 1204 const standardImportPath: string = 'bytecode_alias/src/main/ets/utils/Calc'; 1205 const importByPkgNameSlashes = 'bytecode_alias///'; 1206 const importByPkgNameSlashesOh = 'bytecode_alias_oh///'; 1207 const moduleSourceFile: string = new ModuleSourceFile(); 1208 ModuleSourceFile.initPluginEnv(this.rollup); 1209 const importByPkgNameOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, importByPkgName, indexFilePath, importerFile); 1210 const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, 1211 importerFile); 1212 const importByPkgNameOhmUrlSlashes = moduleSourceFile.getOhmUrl(this.rollup, importByPkgNameSlashes, indexFilePath, importerFile); 1213 const importByPkgNameOhmUrlSlashesOh = moduleSourceFile.getOhmUrl(this.rollup, importByPkgNameSlashesOh, indexFilePath, importerFile); 1214 const importByPkgNameNormalizedOhmUrl: string = '@normalized:N&&&bytecode_har/Index&1.0.0'; 1215 const standardImportPathNormalizedOhmUrl: string = '@normalized:N&&&bytecode_har/src/main/ets/utils/Calc&1.0.0'; 1216 const importByPkgNameNormalizedOhmUrlSlashes: string = '@normalized:N&&&bytecode_har/Index&1.0.0'; 1217 const importByPkgNameNormalizedOhmUrlSlashesOh: string = '@normalized:N&&&bytecode_alias_oh/Index&1.0.0'; 1218 expect(importByPkgNameOhmUrl == importByPkgNameNormalizedOhmUrl).to.be.true; 1219 expect(standardImportPathOhmUrl == standardImportPathNormalizedOhmUrl).to.be.true; 1220 expect(importByPkgNameOhmUrlSlashes == importByPkgNameNormalizedOhmUrlSlashes).to.be.true; 1221 expect(importByPkgNameOhmUrlSlashesOh == importByPkgNameNormalizedOhmUrlSlashesOh).to.be.true; 1222 }); 1223 1224 mocha.it('useNormalizedOHMUrl app builtins error message', function () { 1225 this.rollup.build(); 1226 this.rollup.useNormalizedOHMUrl(); 1227 this.rollup.share.projectConfig.pkgContextInfo = {}; 1228 const errInfo: LogData = LogDataFactory.newInstance( 1229 ErrorCode.ETS2BUNDLE_INTERNAL_UNABLE_TO_GET_PKG_CONTENT_INFO, 1230 ArkTSInternalErrorDescription, 1231 "Can not get pkgContextInfo of package 'libapplication.so' which being imported by " + 1232 "'/testHap/oh_modules/.ohpm/pkghar@test+har=/oh_modules/pkghar/src/main/ets/pages/Index.ets'" 1233 ); 1234 const logger = CommonLogger.getInstance(this.rollup); 1235 const loggerStub = sinon.stub(logger.getLoggerFromErrorCode(errInfo.code), 'printError'); 1236 const importerFile: string = 1237 '/testHap/oh_modules/.ohpm/pkghar@test+har=/oh_modules/pkghar/src/main/ets/pages/Index.ets'; 1238 const appSoModuleRequest: string = 'libapplication.so'; 1239 try { 1240 getOhmUrlBySystemApiOrLibRequest(appSoModuleRequest, this.rollup.share.projectConfig, logger, 1241 importerFile, true); 1242 } catch (e) { 1243 } 1244 expect(loggerStub.calledWith(errInfo)).to.be.true; 1245 loggerStub.restore(); 1246 }); 1247 1248 mocha.it('useNormalizedOHMUrl app builtins error message without getHvigorConsoleLogger', function () { 1249 this.rollup.build(); 1250 this.rollup.useNormalizedOHMUrl(); 1251 this.rollup.share.projectConfig.pkgContextInfo = {}; 1252 const errInfo: LogData = LogDataFactory.newInstance( 1253 ErrorCode.ETS2BUNDLE_INTERNAL_UNABLE_TO_GET_PKG_CONTENT_INFO, 1254 ArkTSInternalErrorDescription, 1255 "Can not get pkgContextInfo of package 'libapplication.so' which being imported by " + 1256 "'/testHap/oh_modules/.ohpm/pkghar@test+har=/oh_modules/pkghar/src/main/ets/pages/Index.ets'" 1257 ); 1258 CommonLogger.destroyInstance(); 1259 const getHvigorConsoleLogger = this.rollup.share.getHvigorConsoleLogger; 1260 this.rollup.share.getHvigorConsoleLogger = undefined; 1261 const logger = CommonLogger.getInstance(this.rollup); 1262 const loggerStub = sinon.stub(logger.logger, 'error'); 1263 const importerFile: string = 1264 '/testHap/oh_modules/.ohpm/pkghar@test+har=/oh_modules/pkghar/src/main/ets/pages/Index.ets'; 1265 const appSoModuleRequest: string = 'libapplication.so'; 1266 try { 1267 getOhmUrlBySystemApiOrLibRequest(appSoModuleRequest, this.rollup.share.projectConfig, logger, 1268 importerFile, true); 1269 } catch (e) { 1270 } 1271 expect(loggerStub.calledWith(errInfo.toString())).to.be.true; 1272 CommonLogger.destroyInstance(); 1273 this.rollup.share.getHvigorConsoleLogger = getHvigorConsoleLogger; 1274 loggerStub.restore(); 1275 }); 1276 1277 mocha.it('the error message of getNormalizedOhmUrlByAliasName', function () { 1278 this.rollup.build(); 1279 this.rollup.share.projectConfig.useNormalizedOHMUrl = true; 1280 this.rollup.share.projectConfig.pkgContextInfo = { 1281 'bytecode_har': { 1282 'packageName': 'bytecode_har', 1283 'bundleName': '', 1284 'moduleName': '', 1285 'version': '1.0.0', 1286 'entryPath': 'Index.ets', 1287 'isSO': false 1288 } 1289 } 1290 this.rollup.share.projectConfig.dependencyAliasMap = new Map([ 1291 ['bytecode_alias', 'bytecode_har'] 1292 ]); 1293 this.rollup.share.projectConfig.byteCodeHarInfo = { 1294 'bytecode_alias': { 1295 'abcPath': 'D:\\projectPath\\bytecode_har\\modules.abc' 1296 } 1297 } 1298 const errInfo: LogData = LogDataFactory.newInstance( 1299 ErrorCode.ETS2BUNDLE_INTERNAL_PACKAGE_ENTRY_FILE_NOT_FOUND, 1300 ArkTSInternalErrorDescription, 1301 "Failed to find entry file of 'bytecode_har'. Failed to obtain the entry file " + 1302 "information of 'bytecode_har' from the package context information." 1303 ); 1304 const aliasPkgName = 'bytecode_alias'; 1305 const pkgName = 'bytecode_har'; 1306 const logger = CommonLogger.getInstance(this.rollup); 1307 const loggerStub = sinon.stub(logger.getLoggerFromErrorCode(errInfo.code), 'printError'); 1308 1309 try { 1310 delete this.rollup.share.projectConfig.pkgContextInfo['bytecode_har']['entryPath']; 1311 getNormalizedOhmUrlByAliasName(aliasPkgName, this.rollup.share.projectConfig, logger); 1312 } catch (e) { 1313 } 1314 expect(loggerStub.getCall(0).calledWith(errInfo)).to.be.true; 1315 1316 try { 1317 delete this.rollup.share.projectConfig.pkgContextInfo['bytecode_har']; 1318 getNormalizedOhmUrlByAliasName(aliasPkgName, this.rollup.share.projectConfig, logger); 1319 } catch (e) { 1320 } 1321 const errInfo1: LogData = LogDataFactory.newInstance( 1322 ErrorCode.ETS2BUNDLE_INTERNAL_PACKAGE_NOT_FOUND_IN_CONTEXT_INFO, 1323 ArkTSInternalErrorDescription, 1324 "Failed to find package 'bytecode_har'. Failed to obtain package 'bytecode_har' " + 1325 "from the package context information." 1326 ); 1327 expect(loggerStub.getCall(1).calledWithMatch(errInfo1)).to.be.true; 1328 1329 loggerStub.restore(); 1330 }); 1331 1332 mocha.it('the error message of getNormalizedOhmUrlByAliasName without getHvigorConsoleLogger', function () { 1333 this.rollup.build(); 1334 this.rollup.share.projectConfig.useNormalizedOHMUrl = true; 1335 this.rollup.share.projectConfig.pkgContextInfo = { 1336 'bytecode_har': { 1337 'packageName': 'bytecode_har', 1338 'bundleName': '', 1339 'moduleName': '', 1340 'version': '1.0.0', 1341 'entryPath': 'Index.ets', 1342 'isSO': false 1343 } 1344 } 1345 this.rollup.share.projectConfig.dependencyAliasMap = new Map([ 1346 ['bytecode_alias', 'bytecode_har'] 1347 ]); 1348 this.rollup.share.projectConfig.byteCodeHarInfo = { 1349 'bytecode_alias': { 1350 'abcPath': 'D:\\projectPath\\bytecode_har\\modules.abc' 1351 } 1352 } 1353 const errInfo: LogData = LogDataFactory.newInstance( 1354 ErrorCode.ETS2BUNDLE_INTERNAL_PACKAGE_ENTRY_FILE_NOT_FOUND, 1355 ArkTSInternalErrorDescription, 1356 "Failed to find entry file of 'bytecode_har'. Failed to obtain the entry file " + 1357 "information of 'bytecode_har' from the package context information." 1358 ); 1359 CommonLogger.destroyInstance(); 1360 const getHvigorConsoleLogger = this.rollup.share.getHvigorConsoleLogger; 1361 this.rollup.share.getHvigorConsoleLogger = undefined; 1362 const aliasPkgName = 'bytecode_alias'; 1363 const pkgName = 'bytecode_har'; 1364 const logger = CommonLogger.getInstance(this.rollup); 1365 const loggerStub = sinon.stub(logger.logger, 'error'); 1366 1367 try { 1368 delete this.rollup.share.projectConfig.pkgContextInfo['bytecode_har']['entryPath']; 1369 getNormalizedOhmUrlByAliasName(aliasPkgName, this.rollup.share.projectConfig, logger); 1370 } catch (e) { 1371 } 1372 expect(loggerStub.getCall(0).calledWith(errInfo.toString())).to.be.true; 1373 1374 try { 1375 delete this.rollup.share.projectConfig.pkgContextInfo['bytecode_har']; 1376 getNormalizedOhmUrlByAliasName(aliasPkgName, this.rollup.share.projectConfig, logger); 1377 } catch (e) { 1378 } 1379 const errInfo1: LogData = LogDataFactory.newInstance( 1380 ErrorCode.ETS2BUNDLE_INTERNAL_PACKAGE_NOT_FOUND_IN_CONTEXT_INFO, 1381 ArkTSInternalErrorDescription, 1382 "Failed to find package 'bytecode_har'. Failed to obtain package 'bytecode_har' " + 1383 "from the package context information." 1384 ); 1385 expect(loggerStub.getCall(1).calledWithMatch(errInfo1.toString())).to.be.true; 1386 CommonLogger.destroyInstance(); 1387 this.rollup.share.getHvigorConsoleLogger = getHvigorConsoleLogger; 1388 loggerStub.restore(); 1389 }); 1390});