fix mock errors

Signed-off-by: sambaby <1337922982@qq.com>
This commit is contained in:
sambaby
2023-09-09 16:36:41 +08:00
parent cda2de8811
commit 36945efba7
2 changed files with 6 additions and 2 deletions
+1 -1
View File
@@ -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');
});
});
@@ -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 = '';