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 16 17import { expect } from 'chai'; 18import mocha from 'mocha'; 19import fs from 'fs'; 20import path from 'path'; 21import sinon from 'sinon'; 22import os from "os"; 23 24import { 25 OBFUSCATION_TOOL, 26 ESMODULE, 27 RELEASE, 28 TS2ABC 29} from '../../../lib/fast_build/ark_compiler/common/ark_define'; 30import { 31 NODE, 32 BUNDLE_NAME_DEFAULT, 33 ENTRY_MODULE_NAME_DEFAULT, 34 NODE_JS_PATH, 35 LOADER_AOTMODE 36} from '../mock/rollup_mock/common'; 37import { 38 ES2ABC_PATH, 39 TS2ABC_PATH, 40 MERGERABC_PATH, 41 JS2ABC_PATH, 42 AOTCOMPILER_PATH, 43 WIN_ES2ABC_PATH, 44 WIN_TS2ABC_PATH, 45 WIN_MERGERABC_PATH, 46 WIN_JS2ABC_PATH, 47 WIN_AOTCOMPILER_PATH, 48 MAC_ES2ABC_PATH, 49 MAC_TS2ABC_PATH, 50 MAC_MERGERABC_PATH, 51 MAC_JS2ABC_PATH, 52 MAC_AOTCOMPILER_PATH, 53 ARKROOT_PATH, 54 ARKCONFIG_TS2ABC_PATH 55} from '../mock/rollup_mock/path_config'; 56import RollUpPluginMock from '../mock/rollup_mock/rollup_plugin_mock'; 57import { 58 initArkConfig, 59 initArkProjectConfig, 60 utProcessArkConfig, 61 readProjectAndLibsSource 62} from '../../../lib/fast_build/ark_compiler/common/process_ark_config'; 63import { 64 ObConfigResolver, 65 MergedConfig 66} from '../../../lib/fast_build/ark_compiler/common/ob_config_resolver'; 67import { ArkObfuscator } from 'arkguard'; 68 69const WINDOWS: string = 'Windows_NT'; 70const LINUX: string = 'Linux'; 71const MAC: string = 'Darwin'; 72const HARMONYOS: string = 'HarmonyOS'; 73 74mocha.describe('test process_ark_config file api', function () { 75 mocha.before(function () { 76 this.rollup = new RollUpPluginMock(); 77 }); 78 79 mocha.after(() => { 80 delete this.rollup; 81 }); 82 83 mocha.it('1-1: test initArkConfig under build debug', function () { 84 this.rollup.build(); 85 this.rollup.share.projectConfig.arkFrontendDir = this.rollup.share.projectConfig.projectTopDir; 86 this.rollup.share.projectConfig.nodeJs = true; 87 this.rollup.share.projectConfig.nodePath = NODE_JS_PATH; 88 const arkConfig = initArkConfig(this.rollup.share.projectConfig); 89 90 expect(arkConfig.nodePath === NODE_JS_PATH).to.be.true; 91 expect(arkConfig.es2abcPath.indexOf(ES2ABC_PATH) > 0).to.be.true; 92 expect(arkConfig.ts2abcPath.indexOf(TS2ABC_PATH) > 0).to.be.true; 93 expect(arkConfig.mergeAbcPath.indexOf(MERGERABC_PATH) > 0).to.be.true; 94 expect(arkConfig.js2abcPath.indexOf(JS2ABC_PATH) > 0).to.be.true; 95 expect(arkConfig.aotCompilerPath.indexOf(AOTCOMPILER_PATH) > 0).to.be.true; 96 expect(arkConfig.isDebug === true).to.be.true; 97 expect(arkConfig.arkRootPath === this.rollup.share.projectConfig.arkFrontendDir).to.be.true; 98 }); 99 100 mocha.it('1-2: test initArkConfig under build release', function () { 101 this.rollup.build(RELEASE); 102 this.rollup.share.projectConfig.arkFrontendDir = this.rollup.share.projectConfig.projectTopDir; 103 const arkConfig = initArkConfig(this.rollup.share.projectConfig); 104 105 expect(arkConfig.nodePath === NODE).to.be.true; 106 expect(arkConfig.es2abcPath.indexOf(ES2ABC_PATH) > 0).to.be.true; 107 expect(arkConfig.ts2abcPath.indexOf(TS2ABC_PATH) > 0).to.be.true; 108 expect(arkConfig.mergeAbcPath.indexOf(MERGERABC_PATH) > 0).to.be.true; 109 expect(arkConfig.js2abcPath.indexOf(JS2ABC_PATH) > 0).to.be.true; 110 expect(arkConfig.aotCompilerPath.indexOf(AOTCOMPILER_PATH) > 0).to.be.true; 111 expect(arkConfig.isDebug === false).to.be.true; 112 expect(arkConfig.arkRootPath === this.rollup.share.projectConfig.arkFrontendDir).to.be.true; 113 }); 114 115 mocha.it('1-3: test initArkConfig under preview debug', function () { 116 this.rollup.preview(); 117 this.rollup.share.projectConfig.arkFrontendDir = this.rollup.share.projectConfig.projectTopDir; 118 const arkConfig = initArkConfig(this.rollup.share.projectConfig); 119 120 expect(arkConfig.nodePath === NODE).to.be.true; 121 expect(arkConfig.es2abcPath.indexOf(ES2ABC_PATH) > 0).to.be.true; 122 expect(arkConfig.ts2abcPath.indexOf(TS2ABC_PATH) > 0).to.be.true; 123 expect(arkConfig.mergeAbcPath.indexOf(MERGERABC_PATH) > 0).to.be.true; 124 expect(arkConfig.js2abcPath.indexOf(JS2ABC_PATH) > 0).to.be.true; 125 expect(arkConfig.aotCompilerPath.indexOf(AOTCOMPILER_PATH) > 0).to.be.true; 126 expect(arkConfig.isDebug === true).to.be.true; 127 expect(arkConfig.arkRootPath === this.rollup.share.projectConfig.arkFrontendDir).to.be.true; 128 }); 129 130 mocha.it('1-4: test initArkConfig under hot reload debug', function () { 131 this.rollup.hotReload(); 132 this.rollup.share.projectConfig.arkFrontendDir = this.rollup.share.projectConfig.projectTopDir; 133 const arkConfig = initArkConfig(this.rollup.share.projectConfig); 134 135 expect(arkConfig.nodePath === NODE).to.be.true; 136 expect(arkConfig.es2abcPath.indexOf(ES2ABC_PATH) > 0).to.be.true; 137 expect(arkConfig.ts2abcPath.indexOf(TS2ABC_PATH) > 0).to.be.true; 138 expect(arkConfig.mergeAbcPath.indexOf(MERGERABC_PATH) > 0).to.be.true; 139 expect(arkConfig.js2abcPath.indexOf(JS2ABC_PATH) > 0).to.be.true; 140 expect(arkConfig.aotCompilerPath.indexOf(AOTCOMPILER_PATH) > 0).to.be.true; 141 expect(arkConfig.isDebug === true).to.be.true; 142 expect(arkConfig.arkRootPath === this.rollup.share.projectConfig.arkFrontendDir).to.be.true; 143 }); 144 145 mocha.it('2-1-1: test initArkProjectConfig under build debug: moduleJsonInfo exists', function () { 146 this.rollup.build(); 147 const arkConfig = initArkProjectConfig(this.rollup.share); 148 const buildJsonInfo = 149 JSON.parse(fs.readFileSync(this.rollup.share.projectConfig.aceBuildJson).toString()); 150 const moduleJsonInfo = 151 JSON.parse(fs.readFileSync(this.rollup.share.projectConfig.aceModuleJsonPath).toString()); 152 153 expect(arkConfig.nodeModulesPath === buildJsonInfo.nodeModulesPath).to.be.true; 154 expect(arkConfig.minPlatformVersion === moduleJsonInfo.app.minAPIVersion).to.be.true; 155 expect(arkConfig.processTs === false).to.be.true; 156 expect(arkConfig.moduleName === ENTRY_MODULE_NAME_DEFAULT).to.be.true; 157 expect(arkConfig.bundleName === BUNDLE_NAME_DEFAULT).to.be.true; 158 expect(arkConfig.compileMode === ESMODULE).to.be.true; 159 }); 160 161 mocha.it('2-1-2: test initArkProjectConfig under build debug: buildJsonInfo.patchConfig is true', function () { 162 this.rollup.build(); 163 this.rollup.share.projectConfig.aceBuildJson = 164 `${this.rollup.share.projectConfig.aceModuleBuild}/${LOADER_AOTMODE}`; 165 const arkConfig = initArkProjectConfig(this.rollup.share); 166 const buildJsonInfo = 167 JSON.parse(fs.readFileSync(this.rollup.share.projectConfig.aceBuildJson).toString()); 168 169 expect(arkConfig.oldMapFilePath === buildJsonInfo.patchConfig.oldMapFilePath).to.be.true; 170 expect(arkConfig.pandaMode === TS2ABC).to.be.true; 171 expect(arkConfig.processTs === true).to.be.true; 172 expect(arkConfig.anBuildOutPut === buildJsonInfo.anBuildOutPut).to.be.true; 173 expect(arkConfig.anBuildMode === buildJsonInfo.anBuildMode).to.be.true; 174 expect(arkConfig.apPath === buildJsonInfo.apPath).to.be.true; 175 expect(arkConfig.moduleName === ENTRY_MODULE_NAME_DEFAULT).to.be.true; 176 expect(arkConfig.bundleName === BUNDLE_NAME_DEFAULT).to.be.true; 177 expect(arkConfig.compileMode === ESMODULE).to.be.true; 178 }); 179 180 mocha.it('2-2: test initArkProjectConfig under build release', function () { 181 this.rollup.build(RELEASE); 182 const arkConfig = initArkProjectConfig(this.rollup.share); 183 const buildJsonInfo = 184 JSON.parse(fs.readFileSync(this.rollup.share.projectConfig.aceBuildJson).toString()); 185 const moduleJsonInfo = 186 JSON.parse(fs.readFileSync(this.rollup.share.projectConfig.aceModuleJsonPath).toString()); 187 188 expect(arkConfig.nodeModulesPath === buildJsonInfo.nodeModulesPath).to.be.true; 189 expect(arkConfig.minPlatformVersion === moduleJsonInfo.app.minAPIVersion).to.be.true; 190 expect(arkConfig.processTs === false).to.be.true; 191 expect(arkConfig.moduleName === ENTRY_MODULE_NAME_DEFAULT).to.be.true; 192 expect(arkConfig.bundleName === BUNDLE_NAME_DEFAULT).to.be.true; 193 expect(arkConfig.compileMode === ESMODULE).to.be.true; 194 }); 195 196 mocha.it('2-3: test initArkProjectConfig under preview debug', function () { 197 this.rollup.preview(); 198 const arkConfig = initArkProjectConfig(this.rollup.share); 199 const buildJsonInfo = 200 JSON.parse(fs.readFileSync(this.rollup.share.projectConfig.aceBuildJson).toString()); 201 const moduleJsonInfo = 202 JSON.parse(fs.readFileSync(this.rollup.share.projectConfig.aceModuleJsonPath).toString()); 203 204 expect(arkConfig.nodeModulesPath === buildJsonInfo.nodeModulesPath).to.be.true; 205 expect(arkConfig.minPlatformVersion === moduleJsonInfo.app.minAPIVersion).to.be.true; 206 expect(arkConfig.processTs === false).to.be.true; 207 expect(arkConfig.moduleName === ENTRY_MODULE_NAME_DEFAULT).to.be.true; 208 expect(arkConfig.bundleName === BUNDLE_NAME_DEFAULT).to.be.true; 209 expect(arkConfig.compileMode === ESMODULE).to.be.true; 210 }); 211 212 mocha.it('2-4: test initArkProjectConfig under hot reload debug', function () { 213 this.rollup.hotReload(); 214 const arkConfig = initArkProjectConfig(this.rollup.share); 215 const buildJsonInfo = 216 JSON.parse(fs.readFileSync(this.rollup.share.projectConfig.aceBuildJson).toString()); 217 const moduleJsonInfo = 218 JSON.parse(fs.readFileSync(this.rollup.share.projectConfig.aceModuleJsonPath).toString()); 219 220 expect(arkConfig.nodeModulesPath === buildJsonInfo.nodeModulesPath).to.be.true; 221 expect(arkConfig.minPlatformVersion === moduleJsonInfo.app.minAPIVersion).to.be.true; 222 expect(arkConfig.processTs === false).to.be.true; 223 expect(arkConfig.moduleName === ENTRY_MODULE_NAME_DEFAULT).to.be.true; 224 expect(arkConfig.bundleName === BUNDLE_NAME_DEFAULT).to.be.true; 225 expect(arkConfig.compileMode === ESMODULE).to.be.true; 226 }); 227 228 mocha.it('3-1: test initTerserConfig under build debug', function () { 229 this.rollup.build(); 230 const logger: object = this.rollup.share.getLogger(OBFUSCATION_TOOL); 231 const obConfig: ObConfigResolver = new ObConfigResolver(this.rollup.share.projectConfig, logger, true); 232 const mergedObConfig: MergedConfig = obConfig.resolveObfuscationConfigs(); 233 const isHarCompiled: boolean = this.rollup.share.projectConfig.compileHar; 234 const minifyOptions = 235 utProcessArkConfig.initTerserConfig(this.rollup.share.projectConfig, logger, mergedObConfig, isHarCompiled); 236 237 expect(minifyOptions.format.beautify === true).to.be.true; 238 expect(minifyOptions.format.indent_level === 2).to.be.true; 239 expect(minifyOptions.compress.join_vars === false).to.be.true; 240 expect(minifyOptions.compress.sequences === 0).to.be.true; 241 expect(minifyOptions.compress.directives === false).to.be.true; 242 expect(minifyOptions.compress.drop_console === false).to.be.true; 243 expect(minifyOptions.mangle.toplevel === false).to.be.true; 244 }); 245 246 mocha.it('3-2: test initTerserConfig under build release', function () { 247 this.rollup.build(RELEASE); 248 const logger: object = this.rollup.share.getLogger(OBFUSCATION_TOOL); 249 const obConfig: ObConfigResolver = new ObConfigResolver(this.rollup.share.projectConfig, logger, true); 250 const mergedObConfig: MergedConfig = obConfig.resolveObfuscationConfigs(); 251 const isHarCompiled: boolean = this.rollup.share.projectConfig.compileHar; 252 const minifyOptions = 253 utProcessArkConfig.initTerserConfig(this.rollup.share.projectConfig, logger, mergedObConfig, isHarCompiled); 254 255 expect(minifyOptions.format.beautify === true).to.be.true; 256 expect(minifyOptions.format.indent_level === 2).to.be.true; 257 expect(minifyOptions.compress.join_vars === false).to.be.true; 258 expect(minifyOptions.compress.sequences === 0).to.be.true; 259 expect(minifyOptions.compress.directives === false).to.be.true; 260 expect(minifyOptions.compress.drop_console === false).to.be.true; 261 expect(minifyOptions.mangle.toplevel === false).to.be.true; 262 }); 263 264 mocha.it('3-3: test initTerserConfig under preview debug', function () { 265 this.rollup.preview(); 266 const logger: object = this.rollup.share.getLogger(OBFUSCATION_TOOL); 267 const obConfig: ObConfigResolver = new ObConfigResolver(this.rollup.share.projectConfig, logger, true); 268 const mergedObConfig: MergedConfig = obConfig.resolveObfuscationConfigs(); 269 const isHarCompiled: boolean = this.rollup.share.projectConfig.compileHar; 270 const minifyOptions = 271 utProcessArkConfig.initTerserConfig(this.rollup.share.projectConfig, logger, mergedObConfig, isHarCompiled); 272 273 expect(minifyOptions.format.beautify === true).to.be.true; 274 expect(minifyOptions.format.indent_level === 2).to.be.true; 275 expect(minifyOptions.compress.join_vars === false).to.be.true; 276 expect(minifyOptions.compress.sequences === 0).to.be.true; 277 expect(minifyOptions.compress.directives === false).to.be.true; 278 expect(minifyOptions.compress.drop_console === false).to.be.true; 279 expect(minifyOptions.mangle.toplevel === false).to.be.true; 280 }); 281 282 mocha.it('3-4: test initTerserConfig under hot reload debug', function () { 283 this.rollup.hotReload(); 284 const logger: object = this.rollup.share.getLogger(OBFUSCATION_TOOL); 285 const obConfig: ObConfigResolver = new ObConfigResolver(this.rollup.share.projectConfig, logger, true); 286 const mergedObConfig: MergedConfig = obConfig.resolveObfuscationConfigs(); 287 const isHarCompiled: boolean = this.rollup.share.projectConfig.compileHar; 288 const minifyOptions = 289 utProcessArkConfig.initTerserConfig(this.rollup.share.projectConfig, logger, mergedObConfig, isHarCompiled); 290 291 expect(minifyOptions.format.beautify === true).to.be.true; 292 expect(minifyOptions.format.indent_level === 2).to.be.true; 293 expect(minifyOptions.compress.join_vars === false).to.be.true; 294 expect(minifyOptions.compress.sequences === 0).to.be.true; 295 expect(minifyOptions.compress.directives === false).to.be.true; 296 expect(minifyOptions.compress.drop_console === false).to.be.true; 297 expect(minifyOptions.mangle.toplevel === false).to.be.true; 298 }); 299 300 mocha.it('4-1: test processCompatibleVersion under build debug', function () { 301 this.rollup.build(); 302 const arkConfig = initArkConfig(this.rollup.share.projectConfig); 303 utProcessArkConfig.processCompatibleVersion(this.rollup.share.projectConfig, arkConfig); 304 expect(this.rollup.share.projectConfig.pandaMode === undefined).to.be.true; 305 expect(arkConfig.ts2abcPath.indexOf(TS2ABC_PATH) > 0).to.be.true; 306 307 this.rollup.share.projectConfig.minPlatformVersion = 8; 308 utProcessArkConfig.processCompatibleVersion(this.rollup.share.projectConfig, arkConfig); 309 expect(this.rollup.share.projectConfig.pandaMode === TS2ABC).to.be.true; 310 expect(arkConfig.ts2abcPath.indexOf(ARKCONFIG_TS2ABC_PATH) > 0).to.be.true; 311 }); 312 313 mocha.it('4-2: test processCompatibleVersion under build release', function () { 314 this.rollup.build(RELEASE); 315 const arkConfig = initArkConfig(this.rollup.share.projectConfig); 316 utProcessArkConfig.processCompatibleVersion(this.rollup.share.projectConfig, arkConfig); 317 expect(this.rollup.share.projectConfig.pandaMode === undefined).to.be.true; 318 expect(arkConfig.ts2abcPath.indexOf(TS2ABC_PATH) > 0).to.be.true; 319 320 this.rollup.share.projectConfig.minPlatformVersion = 8; 321 utProcessArkConfig.processCompatibleVersion(this.rollup.share.projectConfig, arkConfig); 322 expect(this.rollup.share.projectConfig.pandaMode === TS2ABC).to.be.true; 323 expect(arkConfig.ts2abcPath.indexOf(ARKCONFIG_TS2ABC_PATH) > 0).to.be.true; 324 }); 325 326 mocha.it('4-3: test processCompatibleVersion under preview debug', function () { 327 this.rollup.preview(); 328 const arkConfig = initArkConfig(this.rollup.share.projectConfig); 329 utProcessArkConfig.processCompatibleVersion(this.rollup.share.projectConfig, arkConfig); 330 expect(this.rollup.share.projectConfig.pandaMode === undefined).to.be.true; 331 expect(arkConfig.ts2abcPath.indexOf(TS2ABC_PATH) > 0).to.be.true; 332 333 this.rollup.share.projectConfig.minPlatformVersion = 8; 334 utProcessArkConfig.processCompatibleVersion(this.rollup.share.projectConfig, arkConfig); 335 expect(this.rollup.share.projectConfig.pandaMode === TS2ABC).to.be.true; 336 expect(arkConfig.ts2abcPath.indexOf(ARKCONFIG_TS2ABC_PATH) > 0).to.be.true; 337 }); 338 339 mocha.it('4-4: test processCompatibleVersion under hot reload debug', function () { 340 this.rollup.hotReload(); 341 const arkConfig = initArkConfig(this.rollup.share.projectConfig); 342 utProcessArkConfig.processCompatibleVersion(this.rollup.share.projectConfig, arkConfig); 343 expect(this.rollup.share.projectConfig.pandaMode === undefined).to.be.true; 344 expect(arkConfig.ts2abcPath.indexOf(TS2ABC_PATH) > 0).to.be.true; 345 346 this.rollup.share.projectConfig.minPlatformVersion = 8; 347 utProcessArkConfig.processCompatibleVersion(this.rollup.share.projectConfig, arkConfig); 348 expect(this.rollup.share.projectConfig.pandaMode === TS2ABC).to.be.true; 349 expect(arkConfig.ts2abcPath.indexOf(ARKCONFIG_TS2ABC_PATH) > 0).to.be.true; 350 }); 351 352 mocha.describe('5: test readProjectAndLibsSource api', function () { 353 let mergedObConfig: MergedConfig = {}; 354 let keepFilesAndDependencies: Set<string> = new Set(); 355 const targetFile: string = path.join(__dirname, '../../../test/ark_compiler_ut/testdata/obfuscation/third_package/oh_modules/Index.ts'); 356 const allFiles: Set<string> = new Set([targetFile]); 357 let arkguardConfig: Object = {}; 358 const languageWhiteListNum = 7900; 359 mocha.before(function () { 360 this.rollup = new RollUpPluginMock(); 361 mergedObConfig = { 362 options: { 363 disableObfuscation: false, 364 enablePropertyObfuscation: false, 365 enableStringPropertyObfuscation: false, 366 enableToplevelObfuscation: false, 367 enableFileNameObfuscation: false, 368 enableExportObfuscation: true, 369 removeComments: false, 370 compact:false, 371 removeLog: false, 372 printNameCache: '', 373 applyNameCache: '' 374 } 375 }; 376 arkguardConfig = { 377 mNameObfuscation: { 378 mEnable: true, 379 mNameGeneratorType: 1, 380 mRenameProperties: false, 381 mReservedProperties: [], 382 mTopLevel: true, 383 mReservedToplevelNames:[], 384 }, 385 mExportObfuscation: true, 386 mPerformancePrinter: [] 387 }; 388 }); 389 390 mocha.it('5-1: test readProjectAndLibsSource with export obfuscation', function () { 391 let arkObfuscator: ArkObfuscator = new ArkObfuscator(); 392 arkObfuscator.init(arkguardConfig); 393 readProjectAndLibsSource(allFiles, mergedObConfig, arkObfuscator, false, keepFilesAndDependencies); 394 expect(arkObfuscator.customProfiles.mNameObfuscation.mReservedToplevelNames.toString() === 'foo1,foo2,ts,foo5,foo6').to.be.true; 395 expect(arkObfuscator.customProfiles.mNameObfuscation.mReservedProperties.length > languageWhiteListNum).to.be.true; 396 expect(arkObfuscator.customProfiles.mNameObfuscation.mReservedNames.toString() === 'foo1,foo2,ts,foo5,foo6').to.be.true; 397 }); 398 399 mocha.it('5-2: test readProjectAndLibsSource with export & toplevel obfuscation', function () { 400 let arkObfuscator: ArkObfuscator = new ArkObfuscator(); 401 mergedObConfig.options.enableToplevelObfuscation = true; 402 arkObfuscator.init(arkguardConfig); 403 readProjectAndLibsSource(allFiles, mergedObConfig, arkObfuscator, false, keepFilesAndDependencies); 404 expect(arkObfuscator.customProfiles.mNameObfuscation.mReservedToplevelNames.toString() === 'foo1,foo2,ts,foo5,foo6').to.be.true; 405 expect(arkObfuscator.customProfiles.mNameObfuscation.mReservedProperties.length > languageWhiteListNum).to.be.true; 406 expect(arkObfuscator.customProfiles.mNameObfuscation.mReservedNames.toString() === 'foo1,foo2,ts,foo5,foo6').to.be.true; 407 }); 408 409 mocha.it('5-3: test readProjectAndLibsSource with property obfuscation', function () { 410 arkguardConfig.mNameObfuscation.mRenameProperties = true; 411 arkguardConfig.mExportObfuscation = false; 412 let arkObfuscator: ArkObfuscator = new ArkObfuscator(); 413 arkObfuscator.init(arkguardConfig); 414 mergedObConfig.options.enableToplevelObfuscation = false; 415 mergedObConfig.options.enablePropertyObfuscation = true; 416 readProjectAndLibsSource(allFiles, mergedObConfig, arkObfuscator, false, keepFilesAndDependencies); 417 expect(arkObfuscator.customProfiles.mNameObfuscation.mReservedToplevelNames.toString() === 'foo1,foo2,ts,foo5,foo6').to.be.true; 418 expect(arkObfuscator.customProfiles.mNameObfuscation.mReservedProperties.length > languageWhiteListNum).to.be.true; 419 expect(arkObfuscator.customProfiles.mNameObfuscation.mReservedNames.toString() === 'foo1,foo2,ts,foo5,foo6').to.be.true; 420 }); 421 422 mocha.it('5-4: test readProjectAndLibsSource with export & property & toplevel obfuscation', function () { 423 arkguardConfig.mNameObfuscation.mRenameProperties = true; 424 arkguardConfig.mExportObfuscation = true; 425 arkguardConfig.mNameObfuscation.mTopLevel = true; 426 let arkObfuscator: ArkObfuscator = new ArkObfuscator(); 427 arkObfuscator.init(arkguardConfig); 428 mergedObConfig.options.enableToplevelObfuscation = true; 429 mergedObConfig.options.enablePropertyObfuscation = true; 430 readProjectAndLibsSource(allFiles, mergedObConfig, arkObfuscator, false, keepFilesAndDependencies); 431 expect(arkObfuscator.customProfiles.mNameObfuscation.mReservedToplevelNames.toString() === 'foo1,foo2,ts,foo5,foo6').to.be.true; 432 expect(arkObfuscator.customProfiles.mNameObfuscation.mReservedProperties.length > languageWhiteListNum).to.be.true; 433 expect(arkObfuscator.customProfiles.mNameObfuscation.mReservedNames.toString() === 'foo1,foo2,ts,foo5,foo6').to.be.true; 434 }); 435 }); 436 437 mocha.it('6-1: test processPlatformInfo on windows', function () { 438 this.rollup.build(); 439 const stub = sinon.stub(os, 'type').returns(WINDOWS); 440 const arkConfig = initArkConfig(this.rollup.share.projectConfig); 441 const expectEs2abcPath = path.join(ARKROOT_PATH, WIN_ES2ABC_PATH); 442 const expectTs2abcPath = path.join(ARKROOT_PATH, WIN_TS2ABC_PATH); 443 const expectMergeAbcPath = path.join(ARKROOT_PATH, WIN_MERGERABC_PATH); 444 const expectJs2abcPath = path.join(ARKROOT_PATH, WIN_JS2ABC_PATH); 445 const expectAotCompilerPath = path.join(ARKROOT_PATH, WIN_AOTCOMPILER_PATH); 446 expect(arkConfig.es2abcPath === expectEs2abcPath).to.be.true; 447 expect(arkConfig.ts2abcPath === expectTs2abcPath).to.be.true; 448 expect(arkConfig.mergeAbcPath === expectMergeAbcPath).to.be.true; 449 expect(arkConfig.js2abcPath === expectJs2abcPath).to.be.true; 450 expect(arkConfig.aotCompilerPath === expectAotCompilerPath).to.be.true; 451 stub.restore(); 452 }); 453 454 mocha.it('6-2: test processPlatformInfo on linux', function () { 455 this.rollup.build(); 456 const stub = sinon.stub(os, 'type').returns(LINUX); 457 const arkConfig = initArkConfig(this.rollup.share.projectConfig); 458 const expectEs2abcPath = path.join(ARKROOT_PATH, ES2ABC_PATH); 459 const expectTs2abcPath = path.join(ARKROOT_PATH, TS2ABC_PATH); 460 const expectMergeAbcPath = path.join(ARKROOT_PATH, MERGERABC_PATH); 461 const expectJs2abcPath = path.join(ARKROOT_PATH, JS2ABC_PATH); 462 const expectAotCompilerPath = path.join(ARKROOT_PATH, AOTCOMPILER_PATH); 463 expect(arkConfig.es2abcPath === expectEs2abcPath).to.be.true; 464 expect(arkConfig.ts2abcPath === expectTs2abcPath).to.be.true; 465 expect(arkConfig.mergeAbcPath === expectMergeAbcPath).to.be.true; 466 expect(arkConfig.js2abcPath === expectJs2abcPath).to.be.true; 467 expect(arkConfig.aotCompilerPath === expectAotCompilerPath).to.be.true; 468 stub.restore(); 469 }); 470 471 mocha.it('6-3: test processPlatformInfo on mac', function () { 472 this.rollup.build(); 473 const stub = sinon.stub(os, 'type').returns(MAC); 474 const arkConfig = initArkConfig(this.rollup.share.projectConfig); 475 const expectEs2abcPath = path.join(ARKROOT_PATH, MAC_ES2ABC_PATH); 476 const expectTs2abcPath = path.join(ARKROOT_PATH, MAC_TS2ABC_PATH); 477 const expectMergeAbcPath = path.join(ARKROOT_PATH, MAC_MERGERABC_PATH); 478 const expectJs2abcPath = path.join(ARKROOT_PATH, MAC_JS2ABC_PATH); 479 const expectAotCompilerPath = path.join(ARKROOT_PATH, MAC_AOTCOMPILER_PATH); 480 expect(arkConfig.es2abcPath === expectEs2abcPath).to.be.true; 481 expect(arkConfig.ts2abcPath === expectTs2abcPath).to.be.true; 482 expect(arkConfig.mergeAbcPath === expectMergeAbcPath).to.be.true; 483 expect(arkConfig.js2abcPath === expectJs2abcPath).to.be.true; 484 expect(arkConfig.aotCompilerPath === expectAotCompilerPath).to.be.true; 485 stub.restore(); 486 }); 487 488 mocha.it('6-4: test processPlatformInfo on harmonyos', function () { 489 this.rollup.build(); 490 const stub = sinon.stub(os, 'type').returns(HARMONYOS); 491 const arkConfig = initArkConfig(this.rollup.share.projectConfig); 492 const expectEs2abcPath = path.join(ARKROOT_PATH, ES2ABC_PATH); 493 expect(arkConfig.es2abcPath === expectEs2abcPath).to.be.true; 494 stub.restore(); 495 }); 496});