1/* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { ApiExtractor } from '../../../src/common/ApiExtractor'; 17import { assert, expect } from 'chai'; 18import { initScanProjectConfigByMergeConfig, readProjectPropertiesByCollectedPaths, scanProjectConfig } from '../../../src/common/ApiReader'; 19import { NameGeneratorType } from '../../../src/generator/NameFactory'; 20import { MergedConfig, ProjectCollections } from '../../../src/ArkObfuscator'; 21import { clearProjectWhiteListManager, FileWhiteList, projectWhiteListManager, initProjectWhiteListManager } from '../../../src/utils/ProjectCollections'; 22import { AtKeepCollections } from '../../../src/utils/CommonCollections'; 23import { IOptions } from '../../../src/configs/IOptions'; 24 25function collectApi(apiPath: string, apiType: ApiExtractor.ApiType): void { 26 clearAll(); 27 ApiExtractor.traverseApiFiles(apiPath, apiType); 28} 29 30function clearAll(): void { 31 ApiExtractor.mPropertySet.clear(); 32 ApiExtractor.mSystemExportSet.clear(); 33} 34 35describe('test for ApiExtractor', function () { 36 describe('test for visitExport', function () { 37 it('export {ExportDeclarationClass1, ExportDeclarationClass2}', function () { 38 let exportDeclarationAst: string = 'test/ut/utils/apiTest_visitExport/exportDeclarationAst.d.ts'; 39 collectApi(exportDeclarationAst, ApiExtractor.ApiType.API); 40 assert.strictEqual(ApiExtractor.mSystemExportSet.has('ExportDeclarationClass1'), true); 41 assert.strictEqual(ApiExtractor.mSystemExportSet.has('ExportDeclarationClass2'), true); 42 clearAll(); 43 }); 44 45 it('export {ExportDeclarationClass1 as class1, ExportDeclarationClass2} from `./exportDeclarationFrom`', 46 function () { 47 let exportDeclarationFromAst: string = 'test/ut/utils/apiTest_visitExport/exportDeclarationFrom.d.ts'; 48 collectApi(exportDeclarationFromAst, ApiExtractor.ApiType.API); 49 assert.strictEqual(ApiExtractor.mSystemExportSet.has('ExportDeclarationClass1'), false); 50 assert.strictEqual(ApiExtractor.mSystemExportSet.has('class1'), true); 51 assert.strictEqual(ApiExtractor.mSystemExportSet.has('ExportDeclarationClass2'), true); 52 clearAll(); 53 }); 54 55 it('export {default as name1, ExportDeclarationClass2, exportName} from `./exportDefaultDeclarationAst`', 56 function () { 57 let exportDeclarationDefault: string = 'test/ut/utils/apiTest_visitExport/exportDeclarationDefault.d.ts'; 58 collectApi(exportDeclarationDefault, ApiExtractor.ApiType.API); 59 assert.strictEqual(ApiExtractor.mSystemExportSet.has('default'), false); 60 assert.strictEqual(ApiExtractor.mSystemExportSet.has('name1'), true); 61 assert.strictEqual(ApiExtractor.mSystemExportSet.has('ExportDeclarationClass2'), true); 62 assert.strictEqual(ApiExtractor.mSystemExportSet.has('exportName'), true); 63 clearAll(); 64 }); 65 66 it('export {ExportDeclarationClass1 as exportName, ExportDeclarationClass2, ExportDeclarationClass3 as default}', 67 function () { 68 let exportDefaultDeclarationAst: string = 'test/ut/utils/apiTest_visitExport/exportDefaultDeclarationAst.d.ts'; 69 collectApi(exportDefaultDeclarationAst, ApiExtractor.ApiType.API); 70 assert.strictEqual(ApiExtractor.mSystemExportSet.has('ExportDeclarationClass1'), false); 71 assert.strictEqual(ApiExtractor.mSystemExportSet.has('exportName'), true); 72 assert.strictEqual(ApiExtractor.mSystemExportSet.has('ExportDeclarationClass2'), true); 73 assert.strictEqual(ApiExtractor.mSystemExportSet.has('ExportDeclarationClass3'), false); 74 assert.strictEqual(ApiExtractor.mSystemExportSet.has('default'), true); 75 clearAll(); 76 }); 77 78 it('export * as name1', function () { 79 let exportAllAst: string = 'test/ut/utils/apiTest_visitExport/exportAll.d.ts'; 80 collectApi(exportAllAst, ApiExtractor.ApiType.API); 81 assert.strictEqual(ApiExtractor.mSystemExportSet.has('name1'), true); 82 clearAll(); 83 }); 84 85 it('export * from `export*.ts`', function () { 86 let exportFile: string = 'test/ut/utils/apiTest_visitExport/export.d.ts'; 87 collectApi(exportFile, ApiExtractor.ApiType.API); 88 assert.strictEqual(ApiExtractor.mSystemExportSet.size === 0, true); 89 assert.strictEqual(ApiExtractor.mPropertySet.size === 0, true); 90 clearAll(); 91 }); 92 93 it('doubleUnderscoreTest', function () { 94 let doubleUnderscoreTestAst: string = 'test/ut/utils/apiTest_visitExport/doubleUnderscoreTest.d.ts'; 95 collectApi(doubleUnderscoreTestAst, ApiExtractor.ApiType.API); 96 assert.strictEqual(ApiExtractor.mPropertySet.has('__Admin'), true); 97 assert.strictEqual(ApiExtractor.mPropertySet.has('___Admin'), false); 98 assert.strictEqual(ApiExtractor.mPropertySet.has('__Moderator'), true); 99 assert.strictEqual(ApiExtractor.mPropertySet.has('___Moderator'), false); 100 assert.strictEqual(ApiExtractor.mPropertySet.has('__User'), true); 101 assert.strictEqual(ApiExtractor.mPropertySet.has('___User'), false); 102 assert.strictEqual(ApiExtractor.mPropertySet.has('__name'), true); 103 assert.strictEqual(ApiExtractor.mPropertySet.has('___name'), false); 104 assert.strictEqual(ApiExtractor.mPropertySet.has('__Admin'), true); 105 assert.strictEqual(ApiExtractor.mPropertySet.has('___Admin'), false); 106 assert.strictEqual(ApiExtractor.mPropertySet.has('__age'), true); 107 assert.strictEqual(ApiExtractor.mPropertySet.has('___age'), false); 108 assert.strictEqual(ApiExtractor.mPropertySet.has('__greet'), true); 109 assert.strictEqual(ApiExtractor.mPropertySet.has('___greet'), false); 110 assert.strictEqual(ApiExtractor.mPropertySet.has('__typeProp1'), true); 111 assert.strictEqual(ApiExtractor.mPropertySet.has('___typeProp1'), false); 112 assert.strictEqual(ApiExtractor.mPropertySet.has('__typeProp2'), true); 113 assert.strictEqual(ApiExtractor.mPropertySet.has('___typeProp2'), false); 114 assert.strictEqual(ApiExtractor.mPropertySet.has('__speak'), true); 115 assert.strictEqual(ApiExtractor.mPropertySet.has('___speak'), false); 116 assert.strictEqual(ApiExtractor.mPropertySet.has('__appName'), true); 117 assert.strictEqual(ApiExtractor.mPropertySet.has('___appName'), false); 118 assert.strictEqual(ApiExtractor.mPropertySet.has('__version'), true); 119 assert.strictEqual(ApiExtractor.mPropertySet.has('___version'), false); 120 assert.strictEqual(ApiExtractor.mPropertySet.has('__logDetails'), true); 121 assert.strictEqual(ApiExtractor.mPropertySet.has('___logDetails'), false); 122 clearAll(); 123 }); 124 }); 125 126 describe('test for visitPropertyAndName', function () { 127 it('Class Test', function () { 128 let filePath: string = 'test/ut/utils/apiTest_visitPropertyAndName/classTest.d.ts'; 129 let config: MergedConfig = new MergedConfig(); 130 config.options.stripSystemApiArgs = false; 131 initScanProjectConfigByMergeConfig(config); 132 133 collectApi(filePath, ApiExtractor.ApiType.API); 134 assert.strictEqual(ApiExtractor.mSystemExportSet.has('TestClass1'), true); 135 assert.strictEqual(ApiExtractor.mSystemExportSet.has('TestClass2'), false); 136 assert.strictEqual(ApiExtractor.mSystemExportSet.has('AbstractClass'), false); 137 assert.strictEqual(ApiExtractor.mPropertySet.has('prop1'), true); 138 assert.strictEqual(ApiExtractor.mPropertySet.has('prop2'), true); 139 assert.strictEqual(ApiExtractor.mPropertySet.has('abstractProp'), true); 140 assert.strictEqual(ApiExtractor.mPropertySet.has('foo1'), true); 141 assert.strictEqual(ApiExtractor.mPropertySet.has('foo2'), true); 142 assert.strictEqual(ApiExtractor.mPropertySet.has('param1'), true); 143 assert.strictEqual(ApiExtractor.mPropertySet.has('param2'), false); 144 clearAll(); 145 }); 146 147 it('Interface Test', function () { 148 let filePath: string = 'test/ut/utils/apiTest_visitPropertyAndName/interfaceTest.d.ts'; 149 let config: MergedConfig = new MergedConfig(); 150 config.options.stripSystemApiArgs = false; 151 initScanProjectConfigByMergeConfig(config); 152 153 collectApi(filePath, ApiExtractor.ApiType.API); 154 assert.strictEqual(ApiExtractor.mSystemExportSet.has('TestInterface1'), true); 155 assert.strictEqual(ApiExtractor.mSystemExportSet.has('TestInterface2'), false); 156 assert.strictEqual(ApiExtractor.mPropertySet.has('prop1'), true); 157 assert.strictEqual(ApiExtractor.mPropertySet.has('prop2'), true); 158 assert.strictEqual(ApiExtractor.mPropertySet.has('foo1'), true); 159 assert.strictEqual(ApiExtractor.mPropertySet.has('foo2'), true); 160 assert.strictEqual(ApiExtractor.mPropertySet.has('param1'), true); 161 assert.strictEqual(ApiExtractor.mPropertySet.has('param2'), false); 162 clearAll(); 163 }); 164 165 it('TypeLiteral Test', function () { 166 let filePath: string = 'test/ut/utils/apiTest_visitPropertyAndName/typeLiteralTest.d.ts'; 167 let config: MergedConfig = new MergedConfig(); 168 config.options.stripSystemApiArgs = false; 169 initScanProjectConfigByMergeConfig(config); 170 171 collectApi(filePath, ApiExtractor.ApiType.API); 172 assert.strictEqual(ApiExtractor.mSystemExportSet.has('TestType1'), true); 173 assert.strictEqual(ApiExtractor.mSystemExportSet.has('TestType2'), false); 174 assert.strictEqual(ApiExtractor.mPropertySet.has('collectProp1'), true); 175 assert.strictEqual(ApiExtractor.mPropertySet.has('collectProp2'), true); 176 assert.strictEqual(ApiExtractor.mPropertySet.has('testFunc1'), true); 177 assert.strictEqual(ApiExtractor.mPropertySet.has('testFunc2'), true); 178 assert.strictEqual(ApiExtractor.mPropertySet.has('message1'), true); 179 assert.strictEqual(ApiExtractor.mPropertySet.has('message2'), false); 180 clearAll(); 181 }); 182 183 it('Enum Test', function () { 184 let filePath: string = 'test/ut/utils/apiTest_visitPropertyAndName/enumTest.d.ts'; 185 let config: MergedConfig = new MergedConfig(); 186 config.options.stripSystemApiArgs = false; 187 initScanProjectConfigByMergeConfig(config); 188 189 collectApi(filePath, ApiExtractor.ApiType.API); 190 assert.strictEqual(ApiExtractor.mSystemExportSet.has('TestEnum1'), true); 191 assert.strictEqual(ApiExtractor.mSystemExportSet.has('TestEnum2'), false); 192 assert.strictEqual(ApiExtractor.mPropertySet.has('PARAM1'), true); 193 assert.strictEqual(ApiExtractor.mPropertySet.has('PARAM2'), true); 194 clearAll(); 195 }); 196 197 it('ObjectLiteral Test', function () { 198 let filePath: string = 'test/ut/utils/apiTest_visitPropertyAndName/objectLiteral.d.ts'; 199 let config: MergedConfig = new MergedConfig(); 200 config.options.stripSystemApiArgs = false; 201 initScanProjectConfigByMergeConfig(config); 202 203 collectApi(filePath, ApiExtractor.ApiType.API); 204 assert.strictEqual(ApiExtractor.mSystemExportSet.has('obj1'), true); 205 assert.strictEqual(ApiExtractor.mSystemExportSet.has('obj2'), false); 206 assert.strictEqual(ApiExtractor.mPropertySet.has('prop1'), true); 207 assert.strictEqual(ApiExtractor.mPropertySet.has('prop2'), true); 208 assert.strictEqual(ApiExtractor.mPropertySet.has('prop3'), true); 209 assert.strictEqual(ApiExtractor.mPropertySet.has('prop4'), true); 210 assert.strictEqual(ApiExtractor.mPropertySet.has('innerProp1'), true); 211 assert.strictEqual(ApiExtractor.mPropertySet.has('innerProp2'), true); 212 assert.strictEqual(ApiExtractor.mPropertySet.has('innerProp3'), true); 213 assert.strictEqual(ApiExtractor.mPropertySet.has('innerProp4'), true); 214 clearAll(); 215 }); 216 217 it('Module Test', function () { 218 let filePath: string = 'test/ut/utils/apiTest_visitPropertyAndName/moduleTest.d.ts'; 219 let config: MergedConfig = new MergedConfig(); 220 config.options.stripSystemApiArgs = false; 221 initScanProjectConfigByMergeConfig(config); 222 223 collectApi(filePath, ApiExtractor.ApiType.API); 224 assert.strictEqual(ApiExtractor.mSystemExportSet.has('ns1'), true); 225 assert.strictEqual(ApiExtractor.mSystemExportSet.has('ns2'), false); 226 assert.strictEqual(ApiExtractor.mPropertySet.has('TestClass1'), true); 227 assert.strictEqual(ApiExtractor.mPropertySet.has('TestInterface1'), true); 228 assert.strictEqual(ApiExtractor.mPropertySet.has('prop1'), true); 229 assert.strictEqual(ApiExtractor.mPropertySet.has('prop2'), true); 230 assert.strictEqual(ApiExtractor.mPropertySet.has('prop3'), true); 231 assert.strictEqual(ApiExtractor.mPropertySet.has('TestClass2'), false); 232 assert.strictEqual(ApiExtractor.mPropertySet.has('TestInterface2'), false); 233 assert.strictEqual(ApiExtractor.mPropertySet.has('prop4'), true); 234 assert.strictEqual(ApiExtractor.mPropertySet.has('prop5'), true); 235 clearAll(); 236 }); 237 238 it('When "-extra-options strip-system-api-args" option is enabled, no function parameters are collected', function () { 239 let filePath: string = 'test/ut/utils/apiTest_visitPropertyAndName/systemApiArgsTest.d.ts'; 240 let config: MergedConfig = new MergedConfig(); 241 config.options.stripSystemApiArgs = true; 242 initScanProjectConfigByMergeConfig(config); 243 244 collectApi(filePath, ApiExtractor.ApiType.API); 245 assert.strictEqual(ApiExtractor.mSystemExportSet.has('TestClass1'), true); 246 assert.strictEqual(ApiExtractor.mPropertySet.has('prop1'), true); 247 assert.strictEqual(ApiExtractor.mPropertySet.has('param1'), true); 248 assert.strictEqual(ApiExtractor.mPropertySet.has('param2'), false); 249 assert.strictEqual(ApiExtractor.mPropertySet.has('foo1'), true); 250 assert.strictEqual(ApiExtractor.mPropertySet.has('param5'), false); 251 assert.strictEqual(ApiExtractor.mSystemExportSet.has('TestClass2'), false); 252 assert.strictEqual(ApiExtractor.mPropertySet.has('prop2'), true); 253 assert.strictEqual(ApiExtractor.mPropertySet.has('param3'), true); 254 assert.strictEqual(ApiExtractor.mPropertySet.has('param4'), false); 255 assert.strictEqual(ApiExtractor.mPropertySet.has('foo2'), true); 256 assert.strictEqual(ApiExtractor.mPropertySet.has('param6'), false); 257 clearAll(); 258 }); 259 260 it('When "-extra-options strip-system-api-args" option is not enabled, function parameters are collected', function () { 261 let filePath: string = 'test/ut/utils/apiTest_visitPropertyAndName/systemApiArgsTest.d.ts'; 262 let config: MergedConfig = new MergedConfig(); 263 config.options.stripSystemApiArgs = false; 264 initScanProjectConfigByMergeConfig(config); 265 266 collectApi(filePath, ApiExtractor.ApiType.API); 267 assert.strictEqual(ApiExtractor.mSystemExportSet.has('TestClass1'), true); 268 assert.strictEqual(ApiExtractor.mPropertySet.has('prop1'), true); 269 assert.strictEqual(ApiExtractor.mPropertySet.has('param1'), true); 270 assert.strictEqual(ApiExtractor.mPropertySet.has('param2'), true); 271 assert.strictEqual(ApiExtractor.mPropertySet.has('foo1'), true); 272 assert.strictEqual(ApiExtractor.mPropertySet.has('param5'), true); 273 assert.strictEqual(ApiExtractor.mSystemExportSet.has('TestClass2'), false); 274 assert.strictEqual(ApiExtractor.mPropertySet.has('prop2'), true); 275 assert.strictEqual(ApiExtractor.mPropertySet.has('param3'), true); 276 assert.strictEqual(ApiExtractor.mPropertySet.has('param4'), false); 277 assert.strictEqual(ApiExtractor.mPropertySet.has('foo2'), true); 278 assert.strictEqual(ApiExtractor.mPropertySet.has('param6'), false); 279 clearAll(); 280 }); 281 }); 282 283 describe('test for visitProjectExport', function () { 284 const fileList: Set<string> = new Set([ 285 "test/ut/utils/module_exports_test/exportFile1.js", 286 "test/ut/utils/oh_modules/exportFile.js" 287 ]); 288 it('test for module.exports(property)', function () { 289 let projectAndLibs = readProjectPropertiesByCollectedPaths(fileList, 290 { 291 mNameObfuscation: { 292 mEnable: true, 293 mReservedProperties: [], 294 mRenameProperties: true, 295 mKeepStringProperty: false, 296 mNameGeneratorType: NameGeneratorType.ORDERED, 297 mReservedNames: [], 298 mReservedToplevelNames: [] 299 }, 300 mExportObfuscation: false, 301 mKeepFileSourceCode: { 302 mKeepSourceOfPaths: new Set(), 303 mkeepFilesAndDependencies: new Set(), 304 } 305 }, true); 306 let reservedProperties = projectAndLibs.exportNameAndPropSet == undefined? new Set<string> : projectAndLibs.exportNameAndPropSet; 307 let reservedExportNames = projectAndLibs.exportNameSet == undefined? new Set<string> : projectAndLibs.exportNameSet; 308 assert.strictEqual(reservedProperties.has('projectPropertyAssignment1'), true); 309 assert.strictEqual(reservedProperties.has('projectPropertyAssignment2'), true); 310 assert.strictEqual(reservedProperties.has('projectPropertyAssignment3'), true); 311 assert.strictEqual(reservedProperties.has('projectPropertyAssignment4'), true); 312 assert.strictEqual(reservedProperties.has('projectIndirectObj'), false); 313 assert.strictEqual(reservedProperties.has('indirectProp1'), true); 314 assert.strictEqual(reservedProperties.has('projectShorthand'), true); 315 assert.strictEqual(reservedProperties.has('projectShorthandProp'), true); 316 assert.strictEqual(reservedProperties.has('projectMethod1'), true); 317 assert.strictEqual(reservedProperties.has('projectMethod2'), true); 318 assert.strictEqual(reservedProperties.has('projectMethod3'), true); 319 assert.strictEqual(reservedProperties.has('projectGetProp1'), true); 320 assert.strictEqual(reservedProperties.has('projectGetProp2'), true); 321 assert.strictEqual(reservedProperties.has('projectGetProp3'), true); 322 assert.strictEqual(reservedProperties.has('projectSetProp1'), true); 323 assert.strictEqual(reservedProperties.has('projectSetProp2'), true); 324 assert.strictEqual(reservedProperties.has('projectSetProp3'), true); 325 assert.strictEqual(reservedProperties.has('projectExportElement1'), true); 326 assert.strictEqual(reservedProperties.has('projectExportElement2'), true); 327 assert.strictEqual(reservedProperties.has('indirectClass1'), false); 328 assert.strictEqual(reservedProperties.has('indirectProp2'), true); 329 assert.strictEqual(reservedProperties.has('projectExportElement3'), true); 330 assert.strictEqual(reservedProperties.has('indirectClass2'), false); 331 assert.strictEqual(reservedProperties.has('indirectProp3'), true); 332 assert.strictEqual(reservedProperties.has('projectExportElement4'), true); 333 assert.strictEqual(reservedProperties.has('indirectProp4'), true); 334 assert.strictEqual(reservedProperties.has('projectExportElement5'), true); 335 assert.strictEqual(reservedProperties.has('projectExportElement6'), true); 336 assert.strictEqual(reservedProperties.has('projectExportElement7'), true); 337 assert.strictEqual(reservedProperties.has('indirectClass3'), false); 338 assert.strictEqual(reservedProperties.has('indirectProp5'), true); 339 assert.strictEqual(reservedProperties.has('projectExportElement8'), true); 340 assert.strictEqual(reservedProperties.has('indirectClass4'), false); 341 assert.strictEqual(reservedProperties.has('indirectProp6'), true); 342 assert.strictEqual(reservedProperties.has('projectExportElement9'), true); 343 assert.strictEqual(reservedProperties.has('indirectProp7'), true); 344 assert.strictEqual(reservedProperties.has('ohPropertyAssignment1'), true); 345 assert.strictEqual(reservedProperties.has('ohPropertyAssignment2'), true); 346 assert.strictEqual(reservedProperties.has('ohPropertyAssignment3'), true); 347 assert.strictEqual(reservedProperties.has('ohPropertyAssignment4'), true); 348 assert.strictEqual(reservedProperties.has('ohIndirectObj'), false); 349 assert.strictEqual(reservedProperties.has('ohIndirectProp1'), true); 350 assert.strictEqual(reservedProperties.has('ohShorthand'), true); 351 assert.strictEqual(reservedProperties.has('ohShorthandProp'), true); 352 assert.strictEqual(reservedProperties.has('ohMethod1'), true); 353 assert.strictEqual(reservedProperties.has('ohMethod2'), true); 354 assert.strictEqual(reservedProperties.has('ohMethod3'), true); 355 assert.strictEqual(reservedProperties.has('ohGetProp1'), true); 356 assert.strictEqual(reservedProperties.has('ohGetProp2'), true); 357 assert.strictEqual(reservedProperties.has('ohGetProp3'), true); 358 assert.strictEqual(reservedProperties.has('ohSetProp1'), true); 359 assert.strictEqual(reservedProperties.has('ohSetProp2'), true); 360 assert.strictEqual(reservedProperties.has('ohSetProp3'), true); 361 assert.strictEqual(reservedProperties.has('ohExportElement1'), true); 362 assert.strictEqual(reservedProperties.has('ohExportElement2'), true); 363 assert.strictEqual(reservedProperties.has('ohIndirectClass1'), false); 364 assert.strictEqual(reservedProperties.has('ohIndirectProp2'), true); 365 assert.strictEqual(reservedProperties.has('ohExportElement3'), true); 366 assert.strictEqual(reservedProperties.has('ohIndirectClass2'), false); 367 assert.strictEqual(reservedProperties.has('ohIndirectProp3'), true); 368 assert.strictEqual(reservedProperties.has('ohExportElement4'), true); 369 assert.strictEqual(reservedProperties.has('ohIndirectProp4'), true); 370 assert.strictEqual(reservedProperties.has('ohExportElement5'), true); 371 assert.strictEqual(reservedProperties.has('ohExportElement6'), true); 372 assert.strictEqual(reservedProperties.has('ohExportElement7'), true); 373 assert.strictEqual(reservedProperties.has('ohIndirectClass3'), false); 374 assert.strictEqual(reservedProperties.has('ohIndirectProp5'), true); 375 assert.strictEqual(reservedProperties.has('ohExportElement8'), true); 376 assert.strictEqual(reservedProperties.has('ohIndirectClass4'), false); 377 assert.strictEqual(reservedProperties.has('ohIndirectProp6'), true); 378 assert.strictEqual(reservedExportNames.size === 0, true); 379 }); 380 381 it('test for module.exports(export)', function () { 382 let projectAndLibs = readProjectPropertiesByCollectedPaths(fileList, 383 { 384 mNameObfuscation: { 385 mEnable: true, 386 mReservedProperties: [], 387 mRenameProperties: false, 388 mKeepStringProperty: false, 389 mNameGeneratorType: NameGeneratorType.ORDERED, 390 mReservedNames: [], 391 mReservedToplevelNames: [] 392 }, 393 mExportObfuscation: true, 394 mKeepFileSourceCode: { 395 mKeepSourceOfPaths: new Set(), 396 mkeepFilesAndDependencies: new Set(["test/ut/utils/module_exports_test/exportFile3.js"]), 397 } 398 }, true); 399 let reservedProperties = projectAndLibs.exportNameAndPropSet == undefined? new Set<string> : projectAndLibs.exportNameAndPropSet; 400 let reservedExportNames = projectAndLibs.exportNameSet == undefined? new Set<string> : projectAndLibs.exportNameSet; 401 assert.strictEqual(reservedExportNames.has('projectPropertyAssignment1'), false); 402 assert.strictEqual(reservedExportNames.has('projectPropertyAssignment2'), false); 403 assert.strictEqual(reservedExportNames.has('projectPropertyAssignment3'), false); 404 assert.strictEqual(reservedExportNames.has('projectPropertyAssignment4'), false); 405 assert.strictEqual(reservedExportNames.has('projectIndirectObj'), false); 406 assert.strictEqual(reservedExportNames.has('indirectProp1'), false); 407 assert.strictEqual(reservedExportNames.has('projectShorthand'), false); 408 assert.strictEqual(reservedExportNames.has('projectShorthandProp'), false); 409 assert.strictEqual(reservedExportNames.has('projectMethod1'), false); 410 assert.strictEqual(reservedExportNames.has('projectMethod2'), false); 411 assert.strictEqual(reservedExportNames.has('projectMethod3'), false); 412 assert.strictEqual(reservedExportNames.has('projectGetProp1'), false); 413 assert.strictEqual(reservedExportNames.has('projectGetProp2'), false); 414 assert.strictEqual(reservedExportNames.has('projectGetProp3'), false); 415 assert.strictEqual(reservedExportNames.has('projectSetProp1'), false); 416 assert.strictEqual(reservedExportNames.has('projectSetProp2'), false); 417 assert.strictEqual(reservedExportNames.has('projectSetProp3'), false); 418 assert.strictEqual(reservedExportNames.has('projectExportElement1'), false); 419 assert.strictEqual(reservedExportNames.has('projectExportElement2'), false); 420 assert.strictEqual(reservedExportNames.has('indirectClass1'), false); 421 assert.strictEqual(reservedExportNames.has('indirectProp2'), false); 422 assert.strictEqual(reservedExportNames.has('projectExportElement3'), false); 423 assert.strictEqual(reservedExportNames.has('indirectClass2'), false); 424 assert.strictEqual(reservedExportNames.has('indirectProp3'), false); 425 assert.strictEqual(reservedExportNames.has('projectExportElement4'), false); 426 assert.strictEqual(reservedExportNames.has('indirectProp4'), false); 427 assert.strictEqual(reservedExportNames.has('projectExportElement5'), false); 428 assert.strictEqual(reservedExportNames.has('projectExportElement6'), false); 429 assert.strictEqual(reservedExportNames.has('projectExportElement7'), false); 430 assert.strictEqual(reservedExportNames.has('indirectClass3'), false); 431 assert.strictEqual(reservedExportNames.has('indirectProp5'), false); 432 assert.strictEqual(reservedExportNames.has('projectExportElement8'), false); 433 assert.strictEqual(reservedExportNames.has('indirectClass4'), false); 434 assert.strictEqual(reservedExportNames.has('indirectProp6'), false); 435 assert.strictEqual(reservedExportNames.has('projectExportElement9'), false); 436 assert.strictEqual(reservedExportNames.has('indirectProp7'), false); 437 assert.strictEqual(reservedExportNames.has('ohPropertyAssignment1'), true); 438 assert.strictEqual(reservedExportNames.has('ohPropertyAssignment2'), true); 439 assert.strictEqual(reservedExportNames.has('ohPropertyAssignment3'), true); 440 assert.strictEqual(reservedExportNames.has('ohPropertyAssignment4'), true); 441 assert.strictEqual(reservedExportNames.has('ohIndirectObj'), false); 442 assert.strictEqual(reservedExportNames.has('ohIndirectProp1'), false); 443 assert.strictEqual(reservedExportNames.has('ohShorthand'), true); 444 assert.strictEqual(reservedExportNames.has('ohShorthandProp'), false); 445 assert.strictEqual(reservedExportNames.has('ohMethod1'), true); 446 assert.strictEqual(reservedExportNames.has('ohMethod2'), true); 447 assert.strictEqual(reservedExportNames.has('ohMethod3'), true); 448 assert.strictEqual(reservedExportNames.has('ohGetProp1'), true); 449 assert.strictEqual(reservedExportNames.has('ohGetProp2'), true); 450 assert.strictEqual(reservedExportNames.has('ohGetProp3'), true); 451 assert.strictEqual(reservedExportNames.has('ohSetProp1'), true); 452 assert.strictEqual(reservedExportNames.has('ohSetProp2'), true); 453 assert.strictEqual(reservedExportNames.has('ohSetProp3'), true); 454 assert.strictEqual(reservedExportNames.has('ohExportElement1'), true); 455 assert.strictEqual(reservedExportNames.has('ohExportElement2'), true); 456 assert.strictEqual(reservedExportNames.has('ohIndirectClass1'), true); 457 assert.strictEqual(reservedExportNames.has('ohIndirectProp2'), false); 458 assert.strictEqual(reservedExportNames.has('ohExportElement3'), true); 459 assert.strictEqual(reservedExportNames.has('ohIndirectClass2'), false); 460 assert.strictEqual(reservedExportNames.has('ohIndirectProp3'), false); 461 assert.strictEqual(reservedExportNames.has('ohExportElement4'), true); 462 assert.strictEqual(reservedExportNames.has('ohIndirectProp4'), false); 463 assert.strictEqual(reservedExportNames.has('ohExportElement5'), true); 464 assert.strictEqual(reservedExportNames.has('ohExportElement6'), true); 465 assert.strictEqual(reservedExportNames.has('ohExportElement7'), true); 466 assert.strictEqual(reservedExportNames.has('ohIndirectClass3'), true); 467 assert.strictEqual(reservedExportNames.has('ohIndirectProp5'), false); 468 assert.strictEqual(reservedExportNames.has('ohExportElement8'), true); 469 assert.strictEqual(reservedExportNames.has('ohIndirectClass4'), false); 470 assert.strictEqual(reservedExportNames.has('ohIndirectProp6'), false); 471 assert.strictEqual(reservedExportNames.has('ohExportElement9'), true); 472 assert.strictEqual(reservedExportNames.has('ohIndirectProp7'), false); 473 assert.strictEqual(reservedProperties.size === 0, true); 474 }); 475 476 it('test for module.exports(property + export)', function () { 477 let projectAndLibs = readProjectPropertiesByCollectedPaths(fileList, 478 { 479 mNameObfuscation: { 480 mEnable: true, 481 mReservedProperties: [], 482 mRenameProperties: true, 483 mKeepStringProperty: false, 484 mNameGeneratorType: NameGeneratorType.ORDERED, 485 mReservedNames: [], 486 mReservedToplevelNames: [] 487 }, 488 mExportObfuscation: true, 489 mKeepFileSourceCode: { 490 mKeepSourceOfPaths: new Set(), 491 mkeepFilesAndDependencies: new Set(["test/ut/utils/module_exports_test/exportFile3.js"]), 492 } 493 }, true); 494 let reservedProperties = projectAndLibs.exportNameAndPropSet == undefined? new Set<string> : projectAndLibs.exportNameAndPropSet; 495 let reservedExportNames = projectAndLibs.exportNameSet == undefined? new Set<string> : projectAndLibs.exportNameSet; 496 assert.strictEqual(reservedProperties.has('projectPropertyAssignment1'), false); 497 assert.strictEqual(reservedProperties.has('projectPropertyAssignment2'), false); 498 assert.strictEqual(reservedProperties.has('projectPropertyAssignment3'), false); 499 assert.strictEqual(reservedProperties.has('projectPropertyAssignment4'), false); 500 assert.strictEqual(reservedProperties.has('projectIndirectObj'), false); 501 assert.strictEqual(reservedProperties.has('indirectProp1'), false); 502 assert.strictEqual(reservedProperties.has('projectShorthand'), false); 503 assert.strictEqual(reservedProperties.has('projectShorthandProp'), false); 504 assert.strictEqual(reservedProperties.has('projectMethod1'), false); 505 assert.strictEqual(reservedProperties.has('projectMethod2'), false); 506 assert.strictEqual(reservedProperties.has('projectMethod3'), false); 507 assert.strictEqual(reservedProperties.has('projectGetProp1'), false); 508 assert.strictEqual(reservedProperties.has('projectGetProp2'), false); 509 assert.strictEqual(reservedProperties.has('projectGetProp3'), false); 510 assert.strictEqual(reservedProperties.has('projectSetProp1'), false); 511 assert.strictEqual(reservedProperties.has('projectSetProp2'), false); 512 assert.strictEqual(reservedProperties.has('projectSetProp3'), false); 513 assert.strictEqual(reservedProperties.has('projectExportElement1'), false); 514 assert.strictEqual(reservedProperties.has('projectExportElement2'), false); 515 assert.strictEqual(reservedProperties.has('indirectClass1'), false); 516 assert.strictEqual(reservedProperties.has('indirectProp2'), false); 517 assert.strictEqual(reservedProperties.has('projectExportElement3'), false); 518 assert.strictEqual(reservedProperties.has('indirectClass2'), false); 519 assert.strictEqual(reservedProperties.has('indirectProp3'), false); 520 assert.strictEqual(reservedProperties.has('projectExportElement4'), false); 521 assert.strictEqual(reservedProperties.has('indirectProp4'), false); 522 assert.strictEqual(reservedProperties.has('projectExportElement5'), false); 523 assert.strictEqual(reservedProperties.has('projectExportElement6'), false); 524 assert.strictEqual(reservedProperties.has('projectExportElement7'), false); 525 assert.strictEqual(reservedProperties.has('indirectClass3'), false); 526 assert.strictEqual(reservedProperties.has('indirectProp5'), false); 527 assert.strictEqual(reservedProperties.has('projectExportElement8'), false); 528 assert.strictEqual(reservedProperties.has('indirectClass4'), false); 529 assert.strictEqual(reservedProperties.has('indirectProp6'), false); 530 assert.strictEqual(reservedProperties.has('projectExportElement9'), false); 531 assert.strictEqual(reservedProperties.has('indirectProp7'), false); 532 assert.strictEqual(reservedProperties.has('ohPropertyAssignment1'), true); 533 assert.strictEqual(reservedProperties.has('ohPropertyAssignment2'), true); 534 assert.strictEqual(reservedProperties.has('ohPropertyAssignment3'), true); 535 assert.strictEqual(reservedProperties.has('ohPropertyAssignment4'), true); 536 assert.strictEqual(reservedProperties.has('ohIndirectObj'), false); 537 assert.strictEqual(reservedProperties.has('ohIndirectProp1'), true); 538 assert.strictEqual(reservedProperties.has('ohShorthand'), true); 539 assert.strictEqual(reservedProperties.has('ohShorthandProp'), true); 540 assert.strictEqual(reservedProperties.has('ohMethod1'), true); 541 assert.strictEqual(reservedProperties.has('ohMethod2'), true); 542 assert.strictEqual(reservedProperties.has('ohMethod3'), true); 543 assert.strictEqual(reservedProperties.has('ohGetProp1'), true); 544 assert.strictEqual(reservedProperties.has('ohGetProp2'), true); 545 assert.strictEqual(reservedProperties.has('ohGetProp3'), true); 546 assert.strictEqual(reservedProperties.has('ohSetProp1'), true); 547 assert.strictEqual(reservedProperties.has('ohSetProp2'), true); 548 assert.strictEqual(reservedProperties.has('ohSetProp3'), true); 549 assert.strictEqual(reservedProperties.has('ohExportElement1'), true); 550 assert.strictEqual(reservedProperties.has('ohExportElement2'), true); 551 assert.strictEqual(reservedProperties.has('ohIndirectClass1'), false); 552 assert.strictEqual(reservedProperties.has('ohIndirectProp2'), true); 553 assert.strictEqual(reservedProperties.has('ohExportElement3'), true); 554 assert.strictEqual(reservedProperties.has('ohIndirectClass2'), false); 555 assert.strictEqual(reservedProperties.has('ohIndirectProp3'), true); 556 assert.strictEqual(reservedProperties.has('ohExportElement4'), true); 557 assert.strictEqual(reservedProperties.has('ohIndirectProp4'), true); 558 assert.strictEqual(reservedProperties.has('ohExportElement5'), true); 559 assert.strictEqual(reservedProperties.has('ohExportElement6'), true); 560 assert.strictEqual(reservedProperties.has('ohExportElement7'), true); 561 assert.strictEqual(reservedProperties.has('ohIndirectClass3'), false); 562 assert.strictEqual(reservedProperties.has('ohIndirectProp5'), true); 563 assert.strictEqual(reservedProperties.has('ohExportElement8'), true); 564 assert.strictEqual(reservedProperties.has('ohIndirectClass4'), false); 565 assert.strictEqual(reservedProperties.has('ohIndirectProp6'), true); 566 assert.strictEqual(reservedExportNames.has('projectPropertyAssignment1'), false); 567 assert.strictEqual(reservedExportNames.has('projectPropertyAssignment2'), false); 568 assert.strictEqual(reservedExportNames.has('projectPropertyAssignment3'), false); 569 assert.strictEqual(reservedExportNames.has('projectPropertyAssignment4'), false); 570 assert.strictEqual(reservedExportNames.has('projectIndirectObj'), false); 571 assert.strictEqual(reservedExportNames.has('indirectProp1'), false); 572 assert.strictEqual(reservedExportNames.has('projectShorthand'), false); 573 assert.strictEqual(reservedExportNames.has('projectShorthandProp'), false); 574 assert.strictEqual(reservedExportNames.has('projectMethod1'), false); 575 assert.strictEqual(reservedExportNames.has('projectMethod2'), false); 576 assert.strictEqual(reservedExportNames.has('projectMethod3'), false); 577 assert.strictEqual(reservedExportNames.has('projectGetProp1'), false); 578 assert.strictEqual(reservedExportNames.has('projectGetProp2'), false); 579 assert.strictEqual(reservedExportNames.has('projectGetProp3'), false); 580 assert.strictEqual(reservedExportNames.has('projectSetProp1'), false); 581 assert.strictEqual(reservedExportNames.has('projectSetProp2'), false); 582 assert.strictEqual(reservedExportNames.has('projectSetProp3'), false); 583 assert.strictEqual(reservedExportNames.has('projectExportElement1'), false); 584 assert.strictEqual(reservedExportNames.has('projectExportElement2'), false); 585 assert.strictEqual(reservedExportNames.has('indirectClass1'), false); 586 assert.strictEqual(reservedExportNames.has('indirectProp2'), false); 587 assert.strictEqual(reservedExportNames.has('projectExportElement3'), false); 588 assert.strictEqual(reservedExportNames.has('indirectClass2'), false); 589 assert.strictEqual(reservedExportNames.has('indirectProp3'), false); 590 assert.strictEqual(reservedExportNames.has('projectExportElement4'), false); 591 assert.strictEqual(reservedExportNames.has('indirectProp4'), false); 592 assert.strictEqual(reservedExportNames.has('projectExportElement5'), false); 593 assert.strictEqual(reservedExportNames.has('projectExportElement6'), false); 594 assert.strictEqual(reservedExportNames.has('projectExportElement7'), false); 595 assert.strictEqual(reservedExportNames.has('indirectClass3'), false); 596 assert.strictEqual(reservedExportNames.has('indirectProp5'), false); 597 assert.strictEqual(reservedExportNames.has('projectExportElement8'), false); 598 assert.strictEqual(reservedExportNames.has('indirectClass4'), false); 599 assert.strictEqual(reservedExportNames.has('indirectProp6'), false); 600 assert.strictEqual(reservedExportNames.has('projectExportElement9'), false); 601 assert.strictEqual(reservedExportNames.has('indirectProp7'), false); 602 assert.strictEqual(reservedExportNames.has('ohPropertyAssignment1'), true); 603 assert.strictEqual(reservedExportNames.has('ohPropertyAssignment2'), true); 604 assert.strictEqual(reservedExportNames.has('ohPropertyAssignment3'), true); 605 assert.strictEqual(reservedExportNames.has('ohPropertyAssignment4'), true); 606 assert.strictEqual(reservedExportNames.has('ohIndirectObj'), false); 607 assert.strictEqual(reservedExportNames.has('ohIndirectProp1'), false); 608 assert.strictEqual(reservedExportNames.has('ohShorthand'), true); 609 assert.strictEqual(reservedExportNames.has('ohShorthandProp'), false); 610 assert.strictEqual(reservedExportNames.has('ohMethod1'), true); 611 assert.strictEqual(reservedExportNames.has('ohMethod2'), true); 612 assert.strictEqual(reservedExportNames.has('ohMethod3'), true); 613 assert.strictEqual(reservedExportNames.has('ohGetProp1'), true); 614 assert.strictEqual(reservedExportNames.has('ohGetProp2'), true); 615 assert.strictEqual(reservedExportNames.has('ohGetProp3'), true); 616 assert.strictEqual(reservedExportNames.has('ohSetProp1'), true); 617 assert.strictEqual(reservedExportNames.has('ohSetProp2'), true); 618 assert.strictEqual(reservedExportNames.has('ohSetProp3'), true); 619 assert.strictEqual(reservedExportNames.has('ohExportElement1'), true); 620 assert.strictEqual(reservedExportNames.has('ohExportElement2'), true); 621 assert.strictEqual(reservedExportNames.has('ohIndirectClass1'), true); 622 assert.strictEqual(reservedExportNames.has('ohIndirectProp2'), false); 623 assert.strictEqual(reservedExportNames.has('ohExportElement3'), true); 624 assert.strictEqual(reservedExportNames.has('ohIndirectClass2'), false); 625 assert.strictEqual(reservedExportNames.has('ohIndirectProp3'), false); 626 assert.strictEqual(reservedExportNames.has('ohExportElement4'), true); 627 assert.strictEqual(reservedExportNames.has('ohIndirectProp4'), false); 628 assert.strictEqual(reservedExportNames.has('ohExportElement5'), true); 629 assert.strictEqual(reservedExportNames.has('ohExportElement6'), true); 630 assert.strictEqual(reservedExportNames.has('ohExportElement7'), true); 631 assert.strictEqual(reservedExportNames.has('ohIndirectClass3'), true); 632 assert.strictEqual(reservedExportNames.has('ohIndirectProp5'), false); 633 assert.strictEqual(reservedExportNames.has('ohExportElement8'), true); 634 assert.strictEqual(reservedExportNames.has('ohIndirectClass4'), false); 635 assert.strictEqual(reservedExportNames.has('ohIndirectProp6'), false); 636 assert.strictEqual(reservedExportNames.has('ohExportElement9'), true); 637 assert.strictEqual(reservedExportNames.has('ohIndirectProp7'), false); 638 }); 639 }); 640 641 describe('test for visitNodeForConstructorProperty', function () { 642 it('should collect constructor properties', function () { 643 ApiExtractor.mConstructorPropertySet = new Set(); 644 let constructorPropertyAst: string = 'test/ut/utils/apiTest_visitConstructorProperty/constructorProperty.ts'; 645 let cachePath = 'test/ut/utils/obfuscation'; 646 initProjectWhiteListManager(cachePath, false, false); 647 collectApi(constructorPropertyAst, ApiExtractor.ApiType.CONSTRUCTOR_PROPERTY); 648 const fileWhiteList: FileWhiteList | undefined = projectWhiteListManager?.getFileWhiteListMap().get(constructorPropertyAst); 649 projectWhiteListManager?.createOrUpdateWhiteListCaches(); 650 expect(fileWhiteList!.fileReservedInfo.propertyParams.has('para1')).to.be.true; 651 expect(fileWhiteList!.fileReservedInfo.propertyParams.has('para2')).to.be.true; 652 expect(fileWhiteList!.fileReservedInfo.propertyParams.has('para3')).to.be.true; 653 expect(fileWhiteList!.fileReservedInfo.propertyParams.has('para4')).to.be.true; 654 expect(ApiExtractor.mConstructorPropertySet.has('para1')).to.be.true; 655 expect(ApiExtractor.mConstructorPropertySet.has('para2')).to.be.true; 656 expect(ApiExtractor.mConstructorPropertySet.has('para3')).to.be.true; 657 expect(ApiExtractor.mConstructorPropertySet.has('para4')).to.be.true; 658 clearAll(); 659 ApiExtractor.mConstructorPropertySet.clear(); 660 }) 661 }) 662 663 describe('test for visitEnumMembers', function () { 664 it('should collect enum members', function () { 665 let enumMembersAst: string = 'test/ut/utils/apiTest_visitEnumMembers/enumMembers.ts'; 666 let cachePath = 'test/ut/utils/obfuscation'; 667 initProjectWhiteListManager(cachePath, false, false); 668 collectApi(enumMembersAst, ApiExtractor.ApiType.PROJECT); 669 const fileWhiteList: FileWhiteList | undefined = projectWhiteListManager?.getFileWhiteListMap().get(enumMembersAst); 670 projectWhiteListManager?.createOrUpdateWhiteListCaches(); 671 expect(fileWhiteList!.fileReservedInfo.enumProperties.has('A1')).to.be.false; 672 expect(fileWhiteList!.fileReservedInfo.enumProperties.has('A2')).to.be.false; 673 expect(fileWhiteList!.fileReservedInfo.enumProperties.has('A3')).to.be.false; 674 expect(fileWhiteList!.fileReservedInfo.enumProperties.has('B1')).to.be.true; 675 expect(fileWhiteList!.fileReservedInfo.enumProperties.has('B2')).to.be.true; 676 expect(fileWhiteList!.fileReservedInfo.enumProperties.has('B3')).to.be.true; 677 expect(fileWhiteList!.fileReservedInfo.enumProperties.has('C1')).to.be.true; 678 expect(fileWhiteList!.fileReservedInfo.enumProperties.has('C2')).to.be.true; 679 expect(fileWhiteList!.fileReservedInfo.enumProperties.has('C3')).to.be.true; 680 expect(ApiExtractor.mEnumMemberSet.has('A1')).to.be.false; 681 expect(ApiExtractor.mEnumMemberSet.has('A2')).to.be.false; 682 expect(ApiExtractor.mEnumMemberSet.has('A3')).to.be.false; 683 expect(ApiExtractor.mEnumMemberSet.has('B1')).to.be.true; 684 expect(ApiExtractor.mEnumMemberSet.has('B2')).to.be.true; 685 expect(ApiExtractor.mEnumMemberSet.has('B3')).to.be.true; 686 expect(ApiExtractor.mEnumMemberSet.has('C1')).to.be.true; 687 expect(ApiExtractor.mEnumMemberSet.has('C2')).to.be.true; 688 expect(ApiExtractor.mEnumMemberSet.has('C3')).to.be.true; 689 clearAll(); 690 ApiExtractor.mEnumMemberSet.clear(); 691 }) 692 it('should not collect enum members of js file', function () { 693 let enumMembersAst: string = 'test/ut/utils/apiTest_visitEnumMembers/enumMembers.js'; 694 collectApi(enumMembersAst, ApiExtractor.ApiType.PROJECT); 695 expect(ApiExtractor.mEnumMemberSet.size === 0).to.be.true; 696 }) 697 }) 698 699 describe('test for collectNamesWithAtKeep', function () { 700 beforeEach(() => { 701 let cachePath = 'test/ut/utils/obfuscation'; 702 initProjectWhiteListManager(cachePath, false, true); 703 }) 704 afterEach(() => { 705 clearProjectWhiteListManager(); 706 }) 707 708 it('should not collect atKeepNames if not enabled', function () { 709 let filePath: string = 'test/ut/utils/apiTest_visitAtKeepNames/atKeepClass01.ts'; 710 AtKeepCollections.clear(); 711 scanProjectConfig.mEnableAtKeep = false; 712 collectApi(filePath, ApiExtractor.ApiType.PROJECT); 713 expect(AtKeepCollections.keepSymbol.globalNames.size).to.be.equal(0); 714 expect(AtKeepCollections.keepSymbol.propertyNames.size).to.be.equal(0); 715 expect(AtKeepCollections.keepAsConsumer.globalNames.size).to.be.equal(0); 716 expect(AtKeepCollections.keepAsConsumer.propertyNames.size).to.be.equal(0); 717 }) 718 it('should collect keepSymbol names from class if enabled', function () { 719 let filePath: string = 'test/ut/utils/apiTest_visitAtKeepNames/atKeepClass01.ts'; 720 AtKeepCollections.clear(); 721 scanProjectConfig.mEnableAtKeep = true; 722 collectApi(filePath, ApiExtractor.ApiType.PROJECT); 723 expect(AtKeepCollections.keepSymbol.globalNames.size).to.be.equal(7); 724 expect(AtKeepCollections.keepSymbol.globalNames.has('MyClass01')).to.be.true; 725 expect(AtKeepCollections.keepSymbol.globalNames.has('MyClass02')).to.be.true; 726 expect(AtKeepCollections.keepSymbol.globalNames.has('MyClass03')).to.be.true; 727 expect(AtKeepCollections.keepSymbol.globalNames.has('MyClass04')).to.be.true; 728 expect(AtKeepCollections.keepSymbol.globalNames.has('MyClass05')).to.be.true; 729 expect(AtKeepCollections.keepSymbol.globalNames.has('MyClass06')).to.be.true; 730 expect(AtKeepCollections.keepSymbol.globalNames.has('MyClass07')).to.be.true; 731 expect(AtKeepCollections.keepSymbol.globalNames.has('MyClass08')).to.be.false; 732 expect(AtKeepCollections.keepSymbol.propertyNames.size).to.be.equal(22); 733 expect(AtKeepCollections.keepSymbol.propertyNames.has('staticProperty01')).to.be.true; 734 expect(AtKeepCollections.keepSymbol.propertyNames.has('property02')).to.be.true; 735 expect(AtKeepCollections.keepSymbol.propertyNames.has('property03')).to.be.true; 736 expect(AtKeepCollections.keepSymbol.propertyNames.has('myMethod01')).to.be.true; 737 expect(AtKeepCollections.keepSymbol.propertyNames.has('myStaticMethod')).to.be.true; 738 expect(AtKeepCollections.keepSymbol.propertyNames.has('myGetter')).to.be.true; 739 expect(AtKeepCollections.keepSymbol.propertyNames.has('mySetter')).to.be.true; 740 expect(AtKeepCollections.keepSymbol.propertyNames.has('MyClass04')).to.be.true; 741 expect(AtKeepCollections.keepSymbol.propertyNames.has('staticProperty05_01')).to.be.true; 742 expect(AtKeepCollections.keepSymbol.propertyNames.has('property05_02')).to.be.true; 743 expect(AtKeepCollections.keepSymbol.propertyNames.has('myMethod05_01')).to.be.true; 744 expect(AtKeepCollections.keepSymbol.propertyNames.has('myStaticMethod05')).to.be.true; 745 expect(AtKeepCollections.keepSymbol.propertyNames.has('myGetter05')).to.be.true; 746 expect(AtKeepCollections.keepSymbol.propertyNames.has('mySetter05')).to.be.true; 747 expect(AtKeepCollections.keepSymbol.propertyNames.has('MyClass06')).to.be.true; 748 expect(AtKeepCollections.keepSymbol.propertyNames.has('property06')).to.be.true; 749 expect(AtKeepCollections.keepSymbol.propertyNames.has('MyClass07')).to.be.true; 750 expect(AtKeepCollections.keepSymbol.propertyNames.has('property07_01')).to.be.false; 751 expect(AtKeepCollections.keepSymbol.propertyNames.has('property07_02')).to.be.false; 752 expect(AtKeepCollections.keepSymbol.propertyNames.has('property07_03')).to.be.false; 753 expect(AtKeepCollections.keepSymbol.propertyNames.has('property07_04')).to.be.false; 754 expect(AtKeepCollections.keepSymbol.propertyNames.has('property07_05')).to.be.true; 755 expect(AtKeepCollections.keepSymbol.propertyNames.has('property07_06')).to.be.true; 756 expect(AtKeepCollections.keepSymbol.propertyNames.has('property07_07')).to.be.true; 757 expect(AtKeepCollections.keepSymbol.propertyNames.has('property07_08')).to.be.true; 758 expect(AtKeepCollections.keepSymbol.propertyNames.has('aa')).to.be.false; 759 expect(AtKeepCollections.keepSymbol.propertyNames.has('11')).to.be.false; 760 expect(AtKeepCollections.keepSymbol.propertyNames.has('myMethod')).to.be.false; 761 expect(AtKeepCollections.keepAsConsumer.globalNames.size).to.be.equal(0); 762 expect(AtKeepCollections.keepAsConsumer.propertyNames.size).to.be.equal(0); 763 }) 764 it('should collect keepAsConsumer names from class if enabled', function () { 765 let filePath: string = 'test/ut/utils/apiTest_visitAtKeepNames/atKeepClass02.ts'; 766 AtKeepCollections.clear(); 767 scanProjectConfig.mEnableAtKeep = true; 768 collectApi(filePath, ApiExtractor.ApiType.PROJECT); 769 expect(AtKeepCollections.keepAsConsumer.globalNames.size).to.be.equal(6); 770 expect(AtKeepCollections.keepAsConsumer.globalNames.has('MyClass01')).to.be.true; 771 expect(AtKeepCollections.keepAsConsumer.globalNames.has('MyClass02')).to.be.true; 772 expect(AtKeepCollections.keepAsConsumer.globalNames.has('MyClass03')).to.be.true; 773 expect(AtKeepCollections.keepAsConsumer.globalNames.has('MyClass04')).to.be.true; 774 expect(AtKeepCollections.keepAsConsumer.globalNames.has('MyClass05')).to.be.true; 775 expect(AtKeepCollections.keepAsConsumer.globalNames.has('MyClass06')).to.be.true; 776 expect(AtKeepCollections.keepAsConsumer.propertyNames.size).to.be.equal(17); 777 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('staticProperty01')).to.be.true; 778 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('property02')).to.be.true; 779 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('property03')).to.be.true; 780 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('myMethod01')).to.be.true; 781 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('myStaticMethod')).to.be.true; 782 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('myGetter')).to.be.true; 783 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('mySetter')).to.be.true; 784 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('MyClass04')).to.be.true; 785 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('staticProperty05_01')).to.be.true; 786 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('property05_02')).to.be.true; 787 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('myMethod05_01')).to.be.true; 788 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('myStaticMethod05')).to.be.true; 789 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('myGetter05')).to.be.true; 790 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('mySetter05')).to.be.true; 791 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('MyClass06')).to.be.true; 792 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('property06')).to.be.true; 793 expect(AtKeepCollections.keepSymbol.globalNames.size).to.be.equal(0); 794 expect(AtKeepCollections.keepSymbol.propertyNames.size).to.be.equal(0); 795 }) 796 it('should collect keepSymbol names from interface if enabled', function () { 797 let filePath: string = 'test/ut/utils/apiTest_visitAtKeepNames/atKeepInterface01.ts'; 798 AtKeepCollections.clear(); 799 scanProjectConfig.mEnableAtKeep = true; 800 collectApi(filePath, ApiExtractor.ApiType.PROJECT); 801 expect(AtKeepCollections.keepSymbol.globalNames.size).to.be.equal(4); 802 expect(AtKeepCollections.keepSymbol.globalNames.has('MyInterface01')).to.be.true; 803 expect(AtKeepCollections.keepSymbol.globalNames.has('MyInterface02')).to.be.true; 804 expect(AtKeepCollections.keepSymbol.globalNames.has('MyInterface03')).to.be.true; 805 expect(AtKeepCollections.keepSymbol.globalNames.has('MyInterface04')).to.be.true; 806 expect(AtKeepCollections.keepSymbol.propertyNames.size).to.be.equal(10); 807 expect(AtKeepCollections.keepSymbol.propertyNames.has('interfaceProperty01')).to.be.true; 808 expect(AtKeepCollections.keepSymbol.propertyNames.has('interfaceMethod01')).to.be.true; 809 expect(AtKeepCollections.keepSymbol.propertyNames.has('interfaceProperty02')).to.be.true; 810 expect(AtKeepCollections.keepSymbol.propertyNames.has('interfaceMethod02')).to.be.true; 811 expect(AtKeepCollections.keepSymbol.propertyNames.has('MyInterface02')).to.be.true; 812 expect(AtKeepCollections.keepSymbol.propertyNames.has('interfaceProperty03')).to.be.true; 813 expect(AtKeepCollections.keepSymbol.propertyNames.has('interfaceMethod03')).to.be.true; 814 expect(AtKeepCollections.keepSymbol.propertyNames.has('interfaceProperty04')).to.be.true; 815 expect(AtKeepCollections.keepSymbol.propertyNames.has('interfaceMethod04')).to.be.true; 816 expect(AtKeepCollections.keepSymbol.propertyNames.has('MyInterface04')).to.be.true; 817 expect(AtKeepCollections.keepAsConsumer.globalNames.size).to.be.equal(0); 818 expect(AtKeepCollections.keepAsConsumer.propertyNames.size).to.be.equal(0); 819 }) 820 it('should collect keepAsConsumer names from interface if enabled', function () { 821 let filePath: string = 'test/ut/utils/apiTest_visitAtKeepNames/atKeepInterface02.ts'; 822 AtKeepCollections.clear(); 823 scanProjectConfig.mEnableAtKeep = true; 824 collectApi(filePath, ApiExtractor.ApiType.PROJECT); 825 expect(AtKeepCollections.keepAsConsumer.globalNames.size).to.be.equal(4); 826 expect(AtKeepCollections.keepAsConsumer.globalNames.has('MyInterface01')).to.be.true; 827 expect(AtKeepCollections.keepAsConsumer.globalNames.has('MyInterface02')).to.be.true; 828 expect(AtKeepCollections.keepAsConsumer.globalNames.has('MyInterface03')).to.be.true; 829 expect(AtKeepCollections.keepAsConsumer.globalNames.has('MyInterface04')).to.be.true; 830 expect(AtKeepCollections.keepAsConsumer.propertyNames.size).to.be.equal(10); 831 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('interfaceProperty01')).to.be.true; 832 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('interfaceMethod01')).to.be.true; 833 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('interfaceProperty02')).to.be.true; 834 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('interfaceMethod02')).to.be.true; 835 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('MyInterface02')).to.be.true; 836 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('interfaceProperty03')).to.be.true; 837 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('interfaceMethod03')).to.be.true; 838 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('interfaceProperty04')).to.be.true; 839 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('interfaceMethod04')).to.be.true; 840 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('MyInterface04')).to.be.true; 841 expect(AtKeepCollections.keepSymbol.globalNames.size).to.be.equal(0); 842 expect(AtKeepCollections.keepSymbol.propertyNames.size).to.be.equal(0); 843 }) 844 it('should collect keepSymbol names from enum if enabled', function () { 845 let filePath: string = 'test/ut/utils/apiTest_visitAtKeepNames/atKeepEnum01.ts'; 846 AtKeepCollections.clear(); 847 scanProjectConfig.mEnableAtKeep = true; 848 collectApi(filePath, ApiExtractor.ApiType.PROJECT); 849 expect(AtKeepCollections.keepSymbol.globalNames.size).to.be.equal(4); 850 expect(AtKeepCollections.keepSymbol.globalNames.has('Color01')).to.be.true; 851 expect(AtKeepCollections.keepSymbol.globalNames.has('Color02')).to.be.true; 852 expect(AtKeepCollections.keepSymbol.globalNames.has('Color03')).to.be.true; 853 expect(AtKeepCollections.keepSymbol.globalNames.has('Color04')).to.be.true; 854 expect(AtKeepCollections.keepSymbol.globalNames.has('Color05')).to.be.false; 855 expect(AtKeepCollections.keepSymbol.propertyNames.size).to.be.equal(6); 856 expect(AtKeepCollections.keepSymbol.propertyNames.has('RED01')).to.be.true; 857 expect(AtKeepCollections.keepSymbol.propertyNames.has('RED02')).to.be.true; 858 expect(AtKeepCollections.keepSymbol.propertyNames.has('Color02')).to.be.true; 859 expect(AtKeepCollections.keepSymbol.propertyNames.has('RED03')).to.be.true; 860 expect(AtKeepCollections.keepSymbol.propertyNames.has('BLUE04')).to.be.true; 861 expect(AtKeepCollections.keepSymbol.propertyNames.has('Color04')).to.be.true; 862 expect(AtKeepCollections.keepSymbol.propertyNames.has('RED05')).to.be.false; 863 expect(AtKeepCollections.keepAsConsumer.globalNames.size).to.be.equal(0); 864 expect(AtKeepCollections.keepAsConsumer.propertyNames.size).to.be.equal(0); 865 }) 866 it('should collect keepAsConsumer names from enum if enabled', function () { 867 let filePath: string = 'test/ut/utils/apiTest_visitAtKeepNames/atKeepEnum02.ts'; 868 AtKeepCollections.clear(); 869 scanProjectConfig.mEnableAtKeep = true; 870 collectApi(filePath, ApiExtractor.ApiType.PROJECT); 871 expect(AtKeepCollections.keepAsConsumer.globalNames.size).to.be.equal(4); 872 expect(AtKeepCollections.keepAsConsumer.globalNames.has('Color01')).to.be.true; 873 expect(AtKeepCollections.keepAsConsumer.globalNames.has('Color02')).to.be.true; 874 expect(AtKeepCollections.keepAsConsumer.globalNames.has('Color03')).to.be.true; 875 expect(AtKeepCollections.keepAsConsumer.globalNames.has('Color04')).to.be.true; 876 expect(AtKeepCollections.keepAsConsumer.propertyNames.size).to.be.equal(6); 877 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('RED01')).to.be.true; 878 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('RED02')).to.be.true; 879 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('Color02')).to.be.true; 880 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('RED03')).to.be.true; 881 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('BLUE04')).to.be.true; 882 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('Color04')).to.be.true; 883 expect(AtKeepCollections.keepSymbol.globalNames.size).to.be.equal(0); 884 expect(AtKeepCollections.keepSymbol.propertyNames.size).to.be.equal(0); 885 }) 886 it('should collect atKeep names from function if enabled', function () { 887 let filePath: string = 'test/ut/utils/apiTest_visitAtKeepNames/atKeepFunction.ts'; 888 AtKeepCollections.clear(); 889 scanProjectConfig.mEnableAtKeep = true; 890 collectApi(filePath, ApiExtractor.ApiType.PROJECT); 891 expect(AtKeepCollections.keepSymbol.globalNames.size).to.be.equal(2); 892 expect(AtKeepCollections.keepSymbol.globalNames.has('addNumbers01')).to.be.true; 893 expect(AtKeepCollections.keepSymbol.globalNames.has('addNumbers02')).to.be.true; 894 expect(AtKeepCollections.keepSymbol.propertyNames.size).to.be.equal(1); 895 expect(AtKeepCollections.keepSymbol.propertyNames.has('addNumbers02')).to.be.true; 896 expect(AtKeepCollections.keepAsConsumer.globalNames.size).to.be.equal(2); 897 expect(AtKeepCollections.keepAsConsumer.globalNames.has('addNumbers03')).to.be.true; 898 expect(AtKeepCollections.keepAsConsumer.globalNames.has('addNumbers04')).to.be.true; 899 expect(AtKeepCollections.keepAsConsumer.propertyNames.size).to.be.equal(1); 900 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('addNumbers04')).to.be.true; 901 }) 902 it('should collect keepSymbol names from namespace if enabled', function () { 903 let filePath: string = 'test/ut/utils/apiTest_visitAtKeepNames/atKeepNamespace01.ts'; 904 AtKeepCollections.clear(); 905 scanProjectConfig.mEnableAtKeep = true; 906 collectApi(filePath, ApiExtractor.ApiType.PROJECT); 907 // globalNames: 908 expect(AtKeepCollections.keepSymbol.globalNames.size).to.be.equal(26); 909 // from MyNamespace01 910 expect(AtKeepCollections.keepSymbol.globalNames.has('MyNamespace01')).to.be.true; 911 expect(AtKeepCollections.keepSymbol.globalNames.has('nsConstValue01')).to.be.true; 912 expect(AtKeepCollections.keepSymbol.globalNames.has('nsFunction01')).to.be.true; 913 expect(AtKeepCollections.keepSymbol.globalNames.has('nsClass01')).to.be.true; 914 expect(AtKeepCollections.keepSymbol.globalNames.has('nsInterface01')).to.be.true; 915 expect(AtKeepCollections.keepSymbol.globalNames.has('nsEnum01')).to.be.true; 916 expect(AtKeepCollections.keepSymbol.globalNames.has('InnerNamespace01')).to.be.true; 917 expect(AtKeepCollections.keepSymbol.globalNames.has('innerConstValue01')).to.be.true; 918 expect(AtKeepCollections.keepSymbol.globalNames.has('nsType01')).to.be.true; 919 // from MyNamespace02 920 expect(AtKeepCollections.keepSymbol.globalNames.has('nsConstValue02')).to.be.true; 921 expect(AtKeepCollections.keepSymbol.globalNames.has('nsFunction02')).to.be.true; 922 expect(AtKeepCollections.keepSymbol.globalNames.has('nsClass02')).to.be.true; 923 expect(AtKeepCollections.keepSymbol.globalNames.has('nsClass02_01')).to.be.true; 924 expect(AtKeepCollections.keepSymbol.globalNames.has('nsClass02_02')).to.be.true; 925 expect(AtKeepCollections.keepSymbol.globalNames.has('nsInterface02')).to.be.true; 926 expect(AtKeepCollections.keepSymbol.globalNames.has('nsInterface02_01')).to.be.true; 927 expect(AtKeepCollections.keepSymbol.globalNames.has('nsEnum02')).to.be.true; 928 expect(AtKeepCollections.keepSymbol.globalNames.has('nsEnum02_01')).to.be.true; 929 expect(AtKeepCollections.keepSymbol.globalNames.has('InnerNamespace02')).to.be.true; 930 expect(AtKeepCollections.keepSymbol.globalNames.has('innerConstValue02')).to.be.true; 931 // from MyNamespace04 932 expect(AtKeepCollections.keepSymbol.globalNames.has('MyNamespace04')).to.be.true; 933 expect(AtKeepCollections.keepSymbol.globalNames.has('MyNamespace05')).to.be.true; 934 expect(AtKeepCollections.keepSymbol.globalNames.has('MyNamespace06')).to.be.true; 935 expect(AtKeepCollections.keepSymbol.globalNames.has('MyNamespace08Class')).to.be.true; 936 expect(AtKeepCollections.keepSymbol.globalNames.has('MyNamespace09')).to.be.true; 937 expect(AtKeepCollections.keepSymbol.globalNames.has('MyNamespace09Class')).to.be.true; 938 // propertyNames: 939 expect(AtKeepCollections.keepSymbol.propertyNames.size).to.be.equal(37); 940 // from MyNamespace01 941 expect(AtKeepCollections.keepSymbol.propertyNames.has('nsConstValue01')).to.be.true; 942 expect(AtKeepCollections.keepSymbol.propertyNames.has('nsFunction01')).to.be.true; 943 expect(AtKeepCollections.keepSymbol.propertyNames.has('nsClass01')).to.be.true; 944 expect(AtKeepCollections.keepSymbol.propertyNames.has('nsInterface01')).to.be.true; 945 expect(AtKeepCollections.keepSymbol.propertyNames.has('nsEnum01')).to.be.true; 946 expect(AtKeepCollections.keepSymbol.propertyNames.has('InnerNamespace01')).to.be.true; 947 expect(AtKeepCollections.keepSymbol.propertyNames.has('innerConstValue01')).to.be.true; 948 expect(AtKeepCollections.keepSymbol.propertyNames.has('nsType01')).to.be.true; 949 // from MyNamespace02 950 expect(AtKeepCollections.keepSymbol.propertyNames.has('nsConstValue02')).to.be.true; 951 expect(AtKeepCollections.keepSymbol.propertyNames.has('nsFunction02')).to.be.true; 952 expect(AtKeepCollections.keepSymbol.propertyNames.has('nsClass02')).to.be.true; 953 expect(AtKeepCollections.keepSymbol.propertyNames.has('classProp02')).to.be.true; 954 expect(AtKeepCollections.keepSymbol.propertyNames.has('nsClass02_01')).to.be.true; 955 expect(AtKeepCollections.keepSymbol.propertyNames.has('nsClass02_02')).to.be.true; 956 expect(AtKeepCollections.keepSymbol.propertyNames.has('classProp02_02')).to.be.true; 957 expect(AtKeepCollections.keepSymbol.propertyNames.has('nsInterface02')).to.be.true; 958 expect(AtKeepCollections.keepSymbol.propertyNames.has('interfaceProp02')).to.be.true; 959 expect(AtKeepCollections.keepSymbol.propertyNames.has('nsInterface02_01')).to.be.true; 960 expect(AtKeepCollections.keepSymbol.propertyNames.has('interfaceProp02_01')).to.be.true; 961 expect(AtKeepCollections.keepSymbol.propertyNames.has('nsEnum02')).to.be.true; 962 expect(AtKeepCollections.keepSymbol.propertyNames.has('nsEnum02_01')).to.be.true; 963 expect(AtKeepCollections.keepSymbol.propertyNames.has('RED02')).to.be.true; 964 expect(AtKeepCollections.keepSymbol.propertyNames.has('RED02_01')).to.be.true; 965 expect(AtKeepCollections.keepSymbol.propertyNames.has('InnerNamespace02')).to.be.true; 966 expect(AtKeepCollections.keepSymbol.propertyNames.has('innerConstValue02')).to.be.true; 967 // from MyNamespace03 968 expect(AtKeepCollections.keepSymbol.propertyNames.has('classProp03')).to.be.true; 969 expect(AtKeepCollections.keepSymbol.propertyNames.has('classProp03_02')).to.be.true; 970 expect(AtKeepCollections.keepSymbol.propertyNames.has('interfaceProp03')).to.be.true; 971 expect(AtKeepCollections.keepSymbol.propertyNames.has('interfaceProp03_01')).to.be.true; 972 expect(AtKeepCollections.keepSymbol.propertyNames.has('RED03')).to.be.true; 973 expect(AtKeepCollections.keepSymbol.propertyNames.has('RED03_01')).to.be.true; 974 // from MyNamespace04 975 expect(AtKeepCollections.keepSymbol.propertyNames.has('MyNamespace04')).to.be.true; 976 expect(AtKeepCollections.keepSymbol.propertyNames.has('MyNamespace05')).to.be.true; 977 expect(AtKeepCollections.keepSymbol.propertyNames.has('MyNamespace06')).to.be.true; 978 expect(AtKeepCollections.keepSymbol.propertyNames.has('MyNamespace08Class')).to.be.true; 979 expect(AtKeepCollections.keepSymbol.propertyNames.has('MyNamespace09')).to.be.true; 980 expect(AtKeepCollections.keepSymbol.propertyNames.has('MyNamespace09Class')).to.be.true; 981 expect(AtKeepCollections.keepAsConsumer.globalNames.size).to.be.equal(0); 982 expect(AtKeepCollections.keepAsConsumer.propertyNames.size).to.be.equal(0); 983 }) 984 it('should collect keepAsConsumer names from namespace if enabled', function () { 985 let filePath: string = 'test/ut/utils/apiTest_visitAtKeepNames/atKeepNamespace02.ts'; 986 AtKeepCollections.clear(); 987 scanProjectConfig.mEnableAtKeep = true; 988 collectApi(filePath, ApiExtractor.ApiType.PROJECT); 989 // globalNames: 990 expect(AtKeepCollections.keepAsConsumer.globalNames.size).to.be.equal(26); 991 // from MyNamespace01 992 expect(AtKeepCollections.keepAsConsumer.globalNames.has('MyNamespace01')).to.be.true; 993 expect(AtKeepCollections.keepAsConsumer.globalNames.has('nsConstValue01')).to.be.true; 994 expect(AtKeepCollections.keepAsConsumer.globalNames.has('nsFunction01')).to.be.true; 995 expect(AtKeepCollections.keepAsConsumer.globalNames.has('nsClass01')).to.be.true; 996 expect(AtKeepCollections.keepAsConsumer.globalNames.has('nsInterface01')).to.be.true; 997 expect(AtKeepCollections.keepAsConsumer.globalNames.has('nsEnum01')).to.be.true; 998 expect(AtKeepCollections.keepAsConsumer.globalNames.has('InnerNamespace01')).to.be.true; 999 expect(AtKeepCollections.keepAsConsumer.globalNames.has('innerConstValue01')).to.be.true; 1000 expect(AtKeepCollections.keepAsConsumer.globalNames.has('nsType01')).to.be.true; 1001 // from MyNamespace02 1002 expect(AtKeepCollections.keepAsConsumer.globalNames.has('nsConstValue02')).to.be.true; 1003 expect(AtKeepCollections.keepAsConsumer.globalNames.has('nsFunction02')).to.be.true; 1004 expect(AtKeepCollections.keepAsConsumer.globalNames.has('nsClass02')).to.be.true; 1005 expect(AtKeepCollections.keepAsConsumer.globalNames.has('nsClass02_01')).to.be.true; 1006 expect(AtKeepCollections.keepAsConsumer.globalNames.has('nsClass02_02')).to.be.true; 1007 expect(AtKeepCollections.keepAsConsumer.globalNames.has('nsInterface02')).to.be.true; 1008 expect(AtKeepCollections.keepAsConsumer.globalNames.has('nsInterface02_01')).to.be.true; 1009 expect(AtKeepCollections.keepAsConsumer.globalNames.has('nsEnum02')).to.be.true; 1010 expect(AtKeepCollections.keepAsConsumer.globalNames.has('nsEnum02_01')).to.be.true; 1011 expect(AtKeepCollections.keepAsConsumer.globalNames.has('InnerNamespace02')).to.be.true; 1012 expect(AtKeepCollections.keepAsConsumer.globalNames.has('innerConstValue02')).to.be.true; 1013 // from MyNamespace04 1014 expect(AtKeepCollections.keepAsConsumer.globalNames.has('MyNamespace04')).to.be.true; 1015 expect(AtKeepCollections.keepAsConsumer.globalNames.has('MyNamespace05')).to.be.true; 1016 expect(AtKeepCollections.keepAsConsumer.globalNames.has('MyNamespace06')).to.be.true; 1017 expect(AtKeepCollections.keepAsConsumer.globalNames.has('MyNamespace08Class')).to.be.true; 1018 expect(AtKeepCollections.keepAsConsumer.globalNames.has('MyNamespace09')).to.be.true; 1019 expect(AtKeepCollections.keepAsConsumer.globalNames.has('MyNamespace09Class')).to.be.true; 1020 // propertyNames: 1021 expect(AtKeepCollections.keepAsConsumer.propertyNames.size).to.be.equal(37); 1022 // from MyNamespace01 1023 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('nsConstValue01')).to.be.true; 1024 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('nsFunction01')).to.be.true; 1025 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('nsClass01')).to.be.true; 1026 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('nsInterface01')).to.be.true; 1027 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('nsEnum01')).to.be.true; 1028 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('InnerNamespace01')).to.be.true; 1029 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('innerConstValue01')).to.be.true; 1030 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('nsType01')).to.be.true; 1031 // from MyNamespace02 1032 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('nsConstValue02')).to.be.true; 1033 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('nsFunction02')).to.be.true; 1034 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('nsClass02')).to.be.true; 1035 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('classProp02')).to.be.true; 1036 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('nsClass02_01')).to.be.true; 1037 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('nsClass02_02')).to.be.true; 1038 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('classProp02_02')).to.be.true; 1039 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('nsInterface02')).to.be.true; 1040 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('interfaceProp02')).to.be.true; 1041 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('nsInterface02_01')).to.be.true; 1042 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('interfaceProp02_01')).to.be.true; 1043 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('nsEnum02')).to.be.true; 1044 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('nsEnum02_01')).to.be.true; 1045 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('RED02')).to.be.true; 1046 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('RED02_01')).to.be.true; 1047 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('InnerNamespace02')).to.be.true; 1048 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('innerConstValue02')).to.be.true; 1049 // from MyNamespace03 1050 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('classProp03')).to.be.true; 1051 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('classProp03_02')).to.be.true; 1052 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('interfaceProp03')).to.be.true; 1053 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('interfaceProp03_01')).to.be.true; 1054 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('RED03')).to.be.true; 1055 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('RED03_01')).to.be.true; 1056 // from MyNamespace04 1057 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('MyNamespace04')).to.be.true; 1058 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('MyNamespace05')).to.be.true; 1059 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('MyNamespace06')).to.be.true; 1060 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('MyNamespace08Class')).to.be.true; 1061 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('MyNamespace09')).to.be.true; 1062 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('MyNamespace09Class')).to.be.true; 1063 expect(AtKeepCollections.keepSymbol.globalNames.size).to.be.equal(0); 1064 expect(AtKeepCollections.keepSymbol.propertyNames.size).to.be.equal(0); 1065 }) 1066 it('should collect atKeep names from global variable if enabled', function () { 1067 let filePath: string = 'test/ut/utils/apiTest_visitAtKeepNames/atKeepGlobalVar.ts'; 1068 AtKeepCollections.clear(); 1069 scanProjectConfig.mEnableAtKeep = true; 1070 collectApi(filePath, ApiExtractor.ApiType.PROJECT); 1071 expect(AtKeepCollections.keepSymbol.globalNames.size).to.be.equal(6); 1072 expect(AtKeepCollections.keepSymbol.globalNames.has('globalVar01')).to.be.true; 1073 expect(AtKeepCollections.keepSymbol.globalNames.has('globalFunc01')).to.be.true; 1074 expect(AtKeepCollections.keepSymbol.globalNames.has('globalMyClass01')).to.be.true; 1075 expect(AtKeepCollections.keepSymbol.globalNames.has('globalVar02')).to.be.true; 1076 expect(AtKeepCollections.keepSymbol.globalNames.has('globalFunc02')).to.be.true; 1077 expect(AtKeepCollections.keepSymbol.globalNames.has('globalMyClass02')).to.be.true; 1078 expect(AtKeepCollections.keepSymbol.propertyNames.size).to.be.equal(3); 1079 expect(AtKeepCollections.keepSymbol.propertyNames.has('globalVar02')).to.be.true; 1080 expect(AtKeepCollections.keepSymbol.propertyNames.has('globalFunc02')).to.be.true; 1081 expect(AtKeepCollections.keepSymbol.propertyNames.has('globalMyClass02')).to.be.true; 1082 expect(AtKeepCollections.keepAsConsumer.globalNames.size).to.be.equal(6); 1083 expect(AtKeepCollections.keepAsConsumer.globalNames.has('globalVar03')).to.be.true; 1084 expect(AtKeepCollections.keepAsConsumer.globalNames.has('globalFunc03')).to.be.true; 1085 expect(AtKeepCollections.keepAsConsumer.globalNames.has('globalMyClass03')).to.be.true; 1086 expect(AtKeepCollections.keepAsConsumer.globalNames.has('globalVar04')).to.be.true; 1087 expect(AtKeepCollections.keepAsConsumer.globalNames.has('globalFunc04')).to.be.true; 1088 expect(AtKeepCollections.keepAsConsumer.globalNames.has('globalMyClass04')).to.be.true; 1089 expect(AtKeepCollections.keepAsConsumer.propertyNames.size).to.be.equal(3); 1090 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('globalVar04')).to.be.true; 1091 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('globalFunc04')).to.be.true; 1092 expect(AtKeepCollections.keepAsConsumer.propertyNames.has('globalMyClass04')).to.be.true; 1093 }) 1094 it('should collect atKeep names from .ets', function () { 1095 let filePath: string = 'test/ut/utils/apiTest_visitAtKeepNames/atKeepTest01.ets'; 1096 AtKeepCollections.clear(); 1097 scanProjectConfig.mEnableAtKeep = true; 1098 collectApi(filePath, ApiExtractor.ApiType.PROJECT); 1099 expect(AtKeepCollections.keepSymbol.globalNames.size).to.be.equal(1); 1100 expect(AtKeepCollections.keepSymbol.globalNames.has('MyClass01')).to.be.true; 1101 expect(AtKeepCollections.keepSymbol.propertyNames.size).to.be.equal(2); 1102 expect(AtKeepCollections.keepSymbol.propertyNames.has('property01')).to.be.true; 1103 expect(AtKeepCollections.keepSymbol.propertyNames.has('MyClass01')).to.be.true; 1104 expect(AtKeepCollections.keepAsConsumer.globalNames.size).to.be.equal(2); 1105 expect(AtKeepCollections.keepAsConsumer.globalNames.has('MyVar01')).to.be.true; 1106 expect(AtKeepCollections.keepAsConsumer.globalNames.has('MyVar02')).to.be.true; 1107 expect(AtKeepCollections.keepAsConsumer.propertyNames.size).to.be.equal(0); 1108 }) 1109 it('should not collect atKeep names from .js', function () { 1110 let filePath: string = 'test/ut/utils/apiTest_visitAtKeepNames/atKeepTest02.js'; 1111 AtKeepCollections.clear(); 1112 scanProjectConfig.mEnableAtKeep = true; 1113 collectApi(filePath, ApiExtractor.ApiType.PROJECT); 1114 expect(AtKeepCollections.keepSymbol.globalNames.size).to.be.equal(0); 1115 expect(AtKeepCollections.keepSymbol.propertyNames.size).to.be.equal(0); 1116 expect(AtKeepCollections.keepAsConsumer.globalNames.size).to.be.equal(0); 1117 expect(AtKeepCollections.keepAsConsumer.propertyNames.size).to.be.equal(0); 1118 }) 1119 it('should not collect atKeep names from .d.ts', function () { 1120 let filePath: string = 'test/ut/utils/apiTest_visitAtKeepNames/atKeepTest03.d.ts'; 1121 AtKeepCollections.clear(); 1122 scanProjectConfig.mEnableAtKeep = true; 1123 collectApi(filePath, ApiExtractor.ApiType.PROJECT); 1124 expect(AtKeepCollections.keepSymbol.globalNames.size).to.be.equal(0); 1125 expect(AtKeepCollections.keepSymbol.propertyNames.size).to.be.equal(0); 1126 expect(AtKeepCollections.keepAsConsumer.globalNames.size).to.be.equal(0); 1127 expect(AtKeepCollections.keepAsConsumer.propertyNames.size).to.be.equal(0); 1128 }) 1129 it('should not collect atKeep names from .d.ets', function () { 1130 let filePath: string = 'test/ut/utils/apiTest_visitAtKeepNames/atKeepTest04.d.ets'; 1131 AtKeepCollections.clear(); 1132 scanProjectConfig.mEnableAtKeep = true; 1133 collectApi(filePath, ApiExtractor.ApiType.PROJECT); 1134 expect(AtKeepCollections.keepSymbol.globalNames.size).to.be.equal(0); 1135 expect(AtKeepCollections.keepSymbol.propertyNames.size).to.be.equal(0); 1136 expect(AtKeepCollections.keepAsConsumer.globalNames.size).to.be.equal(0); 1137 expect(AtKeepCollections.keepAsConsumer.propertyNames.size).to.be.equal(0); 1138 }) 1139 }) 1140 1141 describe('test for collect fileWhiteList', function () { 1142 beforeEach(() => { 1143 let cachePath = 'test/ut/utils/obfuscation'; 1144 initProjectWhiteListManager(cachePath, false, true); 1145 }) 1146 1147 afterEach(() => { 1148 clearProjectWhiteListManager(); 1149 }) 1150 1151 it('should collect structProperties, stringProperties, enumProperties if propertyObf is enabled', function () { 1152 let filePath: string = 'test/ut/utils/apiTest_collectFileWhiteList/collectFileWhiteList01.ets'; 1153 scanProjectConfig.mPropertyObfuscation = true; 1154 scanProjectConfig.mKeepStringProperty = true; 1155 scanProjectConfig.isHarCompiled = true; 1156 collectApi(filePath, ApiExtractor.ApiType.PROJECT); 1157 const fileWhiteList: FileWhiteList = projectWhiteListManager?.getFileWhiteListMap().get(filePath)!; 1158 expect(fileWhiteList.fileKeepInfo.enumProperties.has('RED01')).to.be.true; 1159 expect(fileWhiteList.fileKeepInfo.enumProperties.has('RED02')).to.be.true; 1160 expect(fileWhiteList.fileKeepInfo.enumProperties.has('BLUE02')).to.be.true; 1161 expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('MyEnum')).to.be.true; 1162 expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('MyClass')).to.be.true; 1163 expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('obj01')).to.be.true; 1164 expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('RED01')).to.be.true; 1165 expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('myProp01')).to.be.true; 1166 expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('objProp')).to.be.true; 1167 expect(fileWhiteList.fileKeepInfo.stringProperties.has('name')).to.be.true; 1168 expect(fileWhiteList.fileKeepInfo.stringProperties.has('age')).to.be.true; 1169 expect(fileWhiteList.fileKeepInfo.structProperties.has('myStructProp')).to.be.true; 1170 }) 1171 it('should not collect stringProperties if mKeepStringProperty is not enabled', function () { 1172 let filePath: string = 'test/ut/utils/apiTest_collectFileWhiteList/collectFileWhiteList01.ets'; 1173 scanProjectConfig.mPropertyObfuscation = true; 1174 scanProjectConfig.mKeepStringProperty = false; 1175 scanProjectConfig.isHarCompiled = true; 1176 collectApi(filePath, ApiExtractor.ApiType.PROJECT); 1177 const fileWhiteList: FileWhiteList = projectWhiteListManager?.getFileWhiteListMap().get(filePath)!; 1178 expect(fileWhiteList.fileKeepInfo.enumProperties.has('RED01')).to.be.true; 1179 expect(fileWhiteList.fileKeepInfo.enumProperties.has('RED02')).to.be.true; 1180 expect(fileWhiteList.fileKeepInfo.enumProperties.has('BLUE02')).to.be.true; 1181 expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('MyEnum')).to.be.true; 1182 expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('MyClass')).to.be.true; 1183 expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('obj01')).to.be.true; 1184 expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('RED01')).to.be.true; 1185 expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('myProp01')).to.be.true; 1186 expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('objProp')).to.be.true; 1187 expect(fileWhiteList.fileKeepInfo.stringProperties.has('name')).to.be.false; 1188 expect(fileWhiteList.fileKeepInfo.stringProperties.has('age')).to.be.false; 1189 expect(fileWhiteList.fileKeepInfo.structProperties.has('myStructProp')).to.be.true; 1190 }) 1191 it('should not collect structProperties, stringProperties, enumProperties if propertyObf is not enabled', function () { 1192 let filePath: string = 'test/ut/utils/apiTest_collectFileWhiteList/collectFileWhiteList01.ets'; 1193 scanProjectConfig.mPropertyObfuscation = false; 1194 scanProjectConfig.mKeepStringProperty = true; 1195 scanProjectConfig.isHarCompiled = true; 1196 collectApi(filePath, ApiExtractor.ApiType.PROJECT); 1197 const fileWhiteList: FileWhiteList = projectWhiteListManager?.getFileWhiteListMap().get(filePath)!; 1198 expect(fileWhiteList.fileKeepInfo.enumProperties.size).to.be.equal(0); 1199 expect(fileWhiteList.fileKeepInfo.exported.propertyNames.size).to.be.equal(0); 1200 expect(fileWhiteList.fileKeepInfo.stringProperties.size).to.be.equal(0); 1201 expect(fileWhiteList.fileKeepInfo.structProperties.size).to.be.equal(0); 1202 }) 1203 }) 1204});