From 93be9b43c97eaadee40545bd698816514978f4dc Mon Sep 17 00:00:00 2001 From: sambaby <1337922982@qq.com> Date: Sat, 9 Sep 2023 16:36:41 +0800 Subject: [PATCH] fix mock errors Signed-off-by: sambaby <1337922982@qq.com> --- automock/build_jsmock_system_plugin.js | 2 +- .../mock-generate/src/generate/generateModuleDeclaration.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/automock/build_jsmock_system_plugin.js b/automock/build_jsmock_system_plugin.js index 2066e2a..c540b57 100644 --- a/automock/build_jsmock_system_plugin.js +++ b/automock/build_jsmock_system_plugin.js @@ -83,7 +83,7 @@ rollup.rollup(configJSAPIMockInput).then(bundle => { bundle.write(configJSAPIMockOutput).then(() => { countSize(configJSAPIMockOutput.file); const fileContent = fs.readFileSync(configJSAPIMockOutput.file, 'utf-8'); - fs.writeFileSync(configJSAPIMockOutput.file, fileContent.replace(/\$\d*/g, ''), 'utf-8'); + fs.writeFileSync(configJSAPIMockOutput.file, fileContent.replace(/CommonMethod\$\d*/g, 'CommonMethod'), 'utf-8'); }); }); diff --git a/automock/mock-generate/src/generate/generateModuleDeclaration.ts b/automock/mock-generate/src/generate/generateModuleDeclaration.ts index 4216ef3..cc0f673 100644 --- a/automock/mock-generate/src/generate/generateModuleDeclaration.ts +++ b/automock/mock-generate/src/generate/generateModuleDeclaration.ts @@ -13,6 +13,7 @@ * limitations under the License. */ +import path from 'path'; import { SyntaxKind } from 'typescript'; import type { SourceFile } from 'typescript'; import { firstCharacterToUppercase } from '../common/commonUtils'; @@ -43,7 +44,10 @@ import { generateVariableStatementDelcatation } from './generateVariableStatemen export function generateModuleDeclaration(rootName: string, moduleEntity: ModuleBlockEntity, sourceFile: SourceFile, filename: string): string { let moduleName = moduleEntity.moduleName.replace(/["']/g, ''); let moduleBody = `export function mock${firstCharacterToUppercase(moduleName)}() {\n`; - if (!moduleEntity.exportModifiers.includes(SyntaxKind.DeclareKeyword) && moduleEntity.moduleName.startsWith('"')) { + if (!(moduleEntity.exportModifiers.includes(SyntaxKind.DeclareKeyword) && + (moduleEntity.moduleName.startsWith('"') || moduleEntity.moduleName.startsWith('\''))) && + path.basename(sourceFile.fileName).startsWith('@ohos') + ) { addToIndexArray({ fileName: filename, mockFunctionName: `mock${firstCharacterToUppercase(moduleName)}` }); } let outBody = '';