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'; 19 20import RollUpPluginMock from '../mock/rollup_mock/rollup_plugin_mock'; 21import { ModuleHotfixMode } from '../../../lib/fast_build/ark_compiler/module/module_hotfix_mode'; 22import { RELEASE } from '../../../lib/fast_build/ark_compiler/common/ark_define'; 23import { 24 ES2ABC_PATH, 25 DEBUG_INFO, 26 BUILD_INFO, 27 BUILD_NPM, 28 MODULES_ABC, 29 ENTRY_LIST, 30 OUTPUT, 31 FILE_THREADS, 32 MERGE_ABC, 33 TARGET_API_VERSION 34} from '../mock/rollup_mock/path_config'; 35import { cpus } from '../utils/utils'; 36 37function checkCmdArgs(cmdArgs: Array<object>, compatibleSdkVersion: string) : void { 38 const fileThreads: number = cpus(); 39 40 expect(cmdArgs[0].indexOf(BUILD_INFO) > 0).to.be.true; 41 expect(cmdArgs[1] === ENTRY_LIST).to.be.true; 42 expect(cmdArgs[2].indexOf(BUILD_NPM) > 0).to.be.true; 43 expect(cmdArgs[3] === OUTPUT).to.be.true; 44 expect(cmdArgs[4].indexOf(MODULES_ABC) > 0).to.be.true; 45 expect(cmdArgs[5] === FILE_THREADS).to.be.true; 46 expect(cmdArgs[6] === `\"${fileThreads}\"`).to.be.true; 47 expect(cmdArgs[7].indexOf(compatibleSdkVersion) > 0).to.be.true; 48 expect(cmdArgs[8] === MERGE_ABC).to.be.true; 49} 50 51mocha.describe('test module_hotfix_mode file api', function () { 52 mocha.beforeEach(function () { 53 this.rollup = new RollUpPluginMock(); 54 }); 55 56 mocha.afterEach(() => { 57 delete this.rollup; 58 }); 59 60 mocha.it('1-1: test generateEs2AbcCmdForHotfix under hot fix debug', function () { 61 this.rollup.build(); 62 const moduleMode = new ModuleHotfixMode(this.rollup); 63 moduleMode.generateEs2AbcCmdForHotfix(); 64 const compatibleSdkVersion = `${TARGET_API_VERSION}${this.rollup.share.projectConfig.compatibleSdkVersion}`; 65 expect(moduleMode.cmdArgs[0].indexOf(ES2ABC_PATH) > 0).to.be.true; 66 moduleMode.cmdArgs.shift(); 67 expect(moduleMode.cmdArgs[0] === DEBUG_INFO).to.be.true; 68 moduleMode.cmdArgs.shift(); 69 checkCmdArgs(moduleMode.cmdArgs,compatibleSdkVersion); 70 }); 71 72 mocha.it('1-2: test generateEs2AbcCmdForHotfix under hot fix release', function () { 73 this.rollup.build(RELEASE); 74 const moduleMode = new ModuleHotfixMode(this.rollup); 75 moduleMode.generateEs2AbcCmdForHotfix(); 76 const compatibleSdkVersion = `${TARGET_API_VERSION}${this.rollup.share.projectConfig.compatibleSdkVersion}`; 77 expect(moduleMode.cmdArgs[0].indexOf(ES2ABC_PATH) > 0).to.be.true; 78 moduleMode.cmdArgs.shift(); 79 expect(moduleMode.cmdArgs[0] === DEBUG_INFO).to.be.false; 80 checkCmdArgs(moduleMode.cmdArgs,compatibleSdkVersion); 81 }); 82});