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 ENABLE_RELEASE_COLUMN, 30 ENTRY_LIST, 31 OUTPUT, 32 FILE_THREADS, 33 MERGE_ABC, 34 TARGET_API_VERSION 35} from '../mock/rollup_mock/path_config'; 36import { cpus } from '../utils/utils'; 37 38function checkCmdArgs(cmdArgs: Array<object>, compatibleSdkVersion: string) : void { 39 const fileThreads: number = cpus(); 40 41 expect(cmdArgs[0].indexOf(BUILD_INFO) > 0).to.be.true; 42 expect(cmdArgs[1] === ENTRY_LIST).to.be.true; 43 expect(cmdArgs[2].indexOf(BUILD_NPM) > 0).to.be.true; 44 expect(cmdArgs[3] === OUTPUT).to.be.true; 45 expect(cmdArgs[4].indexOf(MODULES_ABC) > 0).to.be.true; 46 expect(cmdArgs[5] === FILE_THREADS).to.be.true; 47 expect(cmdArgs[6] === `\"${fileThreads}\"`).to.be.true; 48 expect(cmdArgs[7].indexOf(compatibleSdkVersion) > 0).to.be.true; 49 expect(cmdArgs[8] === ENABLE_RELEASE_COLUMN).to.be.true; 50 expect(cmdArgs[9] === MERGE_ABC).to.be.true; 51} 52 53mocha.describe('test module_hotfix_mode file api', function () { 54 mocha.beforeEach(function () { 55 this.rollup = new RollUpPluginMock(); 56 }); 57 58 mocha.afterEach(() => { 59 delete this.rollup; 60 }); 61 62 mocha.it('1-1: test generateEs2AbcCmdForHotfix under hot fix debug', function () { 63 this.rollup.build(); 64 const moduleMode = new ModuleHotfixMode(this.rollup); 65 moduleMode.generateEs2AbcCmdForHotfix(); 66 const compatibleSdkVersion = `${TARGET_API_VERSION}${this.rollup.share.projectConfig.compatibleSdkVersion}`; 67 expect(moduleMode.cmdArgs[0].indexOf(ES2ABC_PATH) > 0).to.be.true; 68 moduleMode.cmdArgs.shift(); 69 expect(moduleMode.cmdArgs[0] === DEBUG_INFO).to.be.true; 70 moduleMode.cmdArgs.shift(); 71 checkCmdArgs(moduleMode.cmdArgs,compatibleSdkVersion); 72 }); 73 74 mocha.it('1-2: test generateEs2AbcCmdForHotfix under hot fix release', function () { 75 this.rollup.build(RELEASE); 76 const moduleMode = new ModuleHotfixMode(this.rollup); 77 moduleMode.generateEs2AbcCmdForHotfix(); 78 const compatibleSdkVersion = `${TARGET_API_VERSION}${this.rollup.share.projectConfig.compatibleSdkVersion}`; 79 expect(moduleMode.cmdArgs[0].indexOf(ES2ABC_PATH) > 0).to.be.true; 80 moduleMode.cmdArgs.shift(); 81 expect(moduleMode.cmdArgs[0] === DEBUG_INFO).to.be.false; 82 checkCmdArgs(moduleMode.cmdArgs,compatibleSdkVersion); 83 }); 84 85 mocha.it('1-3: test generateEs2AbcCmdForHotfix enable column under hot fix release', function () { 86 this.rollup.build(RELEASE); 87 this.rollup.share.projectConfig.enableColumnNum = true; 88 const moduleMode = new ModuleHotfixMode(this.rollup); 89 moduleMode.generateEs2AbcCmdForHotfix(); 90 expect(moduleMode.cmdArgs.includes('--enable-release-column')).to.be.true; 91 }); 92 93 mocha.it('1-4: test generateEs2AbcCmdForHotfix disable column under hot fix release', function () { 94 this.rollup.build(RELEASE); 95 this.rollup.share.projectConfig.enableColumnNum = false; 96 const moduleMode = new ModuleHotfixMode(this.rollup); 97 moduleMode.generateEs2AbcCmdForHotfix(); 98 expect(moduleMode.cmdArgs.includes('--enable-release-column')).to.be.false; 99 }); 100});