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 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 path from "path"; 20import fs from "fs"; 21import sinon from 'sinon'; 22import childProcess from 'child_process'; 23 24import RollUpPluginMock from '../mock/rollup_mock/rollup_plugin_mock'; 25import { 26 generateAot, 27} from '../../../lib/gen_aot'; 28import { ModuleMode } from '../../../lib/fast_build/ark_compiler/module/module_mode'; 29import { TEMPORARY } from '../../../lib/pre_define'; 30 31mocha.describe('test gen_aot file api', function () { 32 mocha.before(function () { 33 this.rollup = new RollUpPluginMock(); 34 }); 35 36 mocha.after(() => { 37 delete this.rollup; 38 }); 39 40 mocha.it('1-1: test the error message of generateAot (full)', function () { 41 this.rollup.build(); 42 const moduleMode = new ModuleMode(this.rollup); 43 const loggerStub = sinon.stub(moduleMode.logger, 'debug'); 44 const stub = sinon.stub(moduleMode, 'throwArkTsCompilerError'); 45 const faultHandler = ((error: string) => { moduleMode.throwArkTsCompilerError(error); }) 46 try { 47 generateAot(moduleMode.arkConfig.arkRootPath, moduleMode.moduleAbcPath, 48 moduleMode.projectConfig, moduleMode.logger, faultHandler); 49 } catch (e) { 50 } 51 expect(stub.calledWithMatch('ArkTS:ERROR GenerateAot failed. AppAbc not found in ')).to.be.true; 52 expect(stub.calledWithMatch('ArkTS:ERROR GenerateAot failed. unknown anBuildMode: ')).to.be.true; 53 loggerStub.restore(); 54 stub.restore(); 55 }); 56 57 mocha.it('1-2: test the error message of generateAot (partial)', function () { 58 this.rollup.build(); 59 const moduleMode = new ModuleMode(this.rollup); 60 const loggerStub = sinon.stub(moduleMode.logger, 'debug'); 61 const stub = sinon.stub(moduleMode, 'throwArkTsCompilerError'); 62 const faultHandler = ((error: string) => { moduleMode.throwArkTsCompilerError(error); }); 63 moduleMode.projectConfig.anBuildMode = 'partial'; 64 moduleMode.projectConfig.apPath = ''; 65 try { 66 generateAot(moduleMode.arkConfig.arkRootPath, moduleMode.moduleAbcPath, 67 moduleMode.projectConfig, moduleMode.logger, faultHandler); 68 } catch (e) { 69 } 70 expect(stub.calledWith('ArkTS:ERROR GenerateAot failed. Invalid profile file path.')).to.be.true; 71 expect(stub.calledWithMatch('ArkTS:ERROR GenerateAot failed. Partial mode lost profile in "')).to.be.true; 72 loggerStub.restore(); 73 stub.restore(); 74 }); 75});