!3910 Add error message to getOhmUrl

Merge pull request !3910 from 吴海龙/errmsg
This commit is contained in:
openharmony_ci 2024-11-05 13:26:18 +00:00 committed by Gitee
commit a8ec28b486
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 47 additions and 3 deletions

View File

@ -19,7 +19,9 @@ import path from 'path';
import MagicString from 'magic-string';
import {
GEN_ABC_PLUGIN_NAME,
PACKAGES
PACKAGES,
red,
reset
} from '../common/ark_define';
import {
getNormalizedOhmUrlByFilepath,
@ -152,8 +154,6 @@ export class ModuleSourceFile {
ModuleSourceFile.addMockConfig(ModuleSourceFile.transformedHarOrHspMockConfigInfo, transformedMockTarget, src);
return;
}
const red: string = '\u001b[31m';
const reset: string = '\u001b[39m';
if (mockModuleInfo.filePath) {
if (useNormalizedOHMUrl) {
transformedMockTarget = ModuleSourceFile.spliceNormalizedOhmurl(mockModuleInfo, mockModuleInfo.filePath, undefined);
@ -414,6 +414,16 @@ export class ModuleSourceFile {
}
if (filePath) {
const targetModuleInfo: Object = rollupObject.getModuleInfo(filePath);
if (!targetModuleInfo) {
ModuleSourceFile.logger.error(red,
`ArkTS:INTERNAL ERROR: Failed to get module info of file '${filePath}'`, reset);
return undefined;
}
if (!targetModuleInfo.meta) {
ModuleSourceFile.logger.error(red,
`ArkTS:INTERNAL ERROR: Failed to get meta info of file '${filePath}'`, reset);
return undefined;
}
let res: string = '';
if (useNormalizedOHMUrl) {
res = ModuleSourceFile.spliceNormalizedOhmurl(targetModuleInfo, filePath, importerFile);

View File

@ -19,6 +19,7 @@ import mocha from 'mocha';
import path from 'path';
import fs from 'fs';
import ts from 'typescript';
import sinon from 'sinon';
import RollUpPluginMock from '../mock/rollup_mock/rollup_plugin_mock';
import { ModuleSourceFile } from '../../../lib/fast_build/ark_compiler/module/module_source_file';
@ -335,6 +336,39 @@ mocha.describe('test module_source_file file api', function () {
SourceMapGenerator.cleanSourceMapObject();
});
mocha.it('1-4: test the error message of getOhmUrl: module info is undefined', function () {
this.rollup.build();
const filePath: string = 'test.ets';
const red: string = '\u001b[31m';
const reset: string = '\u001b[39m';
const moduleSourceFile = new ModuleSourceFile(filePath, '', undefined);
ModuleSourceFile.initPluginEnv(this.rollup);
const stub = sinon.stub(ModuleSourceFile.logger, 'error');
moduleSourceFile.getOhmUrl(this.rollup, '', filePath, undefined);
expect(stub.calledWith(red,
`ArkTS:INTERNAL ERROR: Failed to get module info of file 'test.ets'`, reset)).to.be.true;
stub.restore();
});
mocha.it('1-5: test the error message of getOhmUrl: meta info is undefined', function () {
this.rollup.build();
const filePath: string = 'test.ets';
const red: string = '\u001b[31m';
const reset: string = '\u001b[39m';
const moduleInfo: Object = {
id: filePath,
meta: null
}
this.rollup.moduleInfos.push(moduleInfo);
const moduleSourceFile = new ModuleSourceFile(filePath, '', undefined);
ModuleSourceFile.initPluginEnv(this.rollup);
const stub = sinon.stub(ModuleSourceFile.logger, 'error');
moduleSourceFile.getOhmUrl(this.rollup, '', filePath, undefined);
expect(stub.calledWith(red,
`ArkTS:INTERNAL ERROR: Failed to get meta info of file 'test.ets'`, reset)).to.be.true;
stub.restore();
});
mocha.it('2-1: test processJsModuleRequest under build debug', function () {
this.rollup.build();
SourceMapGenerator.initInstance(this.rollup);