mirror of
				https://gitcode.com/gh_mirrors/re/react-native-pushy.git
				synced 2025-10-31 21:33:12 +08:00 
			
		
		
		
	react-native-pushy适配harmony (#461)
* init * update * udpate * update * update * update * add pushy build time logic
This commit is contained in:
		
							
								
								
									
										12
									
								
								Example/harmony_use_pushy/harmony/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								Example/harmony_use_pushy/harmony/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | ||||
| /node_modules | ||||
| /oh_modules | ||||
| /local.properties | ||||
| /.idea | ||||
| **/build | ||||
| /.hvigor | ||||
| .cxx | ||||
| /.clangd | ||||
| /.clang-format | ||||
| /.clang-tidy | ||||
| **/.test | ||||
| /.appanalyzer | ||||
							
								
								
									
										10
									
								
								Example/harmony_use_pushy/harmony/AppScope/app.json5
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								Example/harmony_use_pushy/harmony/AppScope/app.json5
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,10 @@ | ||||
| { | ||||
|   "app": { | ||||
|     "bundleName": "com.example.myapplication", | ||||
|     "vendor": "example", | ||||
|     "versionCode": 1000000, | ||||
|     "versionName": "1.0.0", | ||||
|     "icon": "$media:app_icon", | ||||
|     "label": "$string:app_name" | ||||
|   } | ||||
| } | ||||
| @@ -0,0 +1,8 @@ | ||||
| { | ||||
|   "string": [ | ||||
|     { | ||||
|       "name": "app_name", | ||||
|       "value": "harmony_use_pushy" | ||||
|     } | ||||
|   ] | ||||
| } | ||||
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 2.7 KiB | 
							
								
								
									
										49
									
								
								Example/harmony_use_pushy/harmony/build-profile.json5
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								Example/harmony_use_pushy/harmony/build-profile.json5
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,49 @@ | ||||
| { | ||||
|   "app": { | ||||
|     "signingConfigs": [], | ||||
|     "products": [ | ||||
|       { | ||||
|         "name": "default", | ||||
|         "signingConfig": "default", | ||||
|         "compatibleSdkVersion": "5.0.0(12)", | ||||
|         "runtimeOS": "HarmonyOS", | ||||
|         "buildOption": { | ||||
|           "strictMode": { | ||||
|             "caseSensitiveCheck": true, | ||||
|             "useNormalizedOHMUrl": true | ||||
|           } | ||||
|         } | ||||
|       } | ||||
|     ], | ||||
|     "buildModeSet": [ | ||||
|       { | ||||
|         "name": "debug", | ||||
|       }, | ||||
|       { | ||||
|         "name": "release" | ||||
|       } | ||||
|     ] | ||||
|   }, | ||||
|   "modules": [ | ||||
|     { | ||||
|       "name": "entry", | ||||
|       "srcPath": "./entry", | ||||
|       "targets": [ | ||||
|         { | ||||
|           "name": "default", | ||||
|           "applyToProducts": [ | ||||
|             "default" | ||||
|           ] | ||||
|         } | ||||
|       ] | ||||
|     }, | ||||
|     { | ||||
|       name: 'rnoh', | ||||
|       srcPath: '../libs/rnoh', | ||||
|     }, | ||||
|     { | ||||
|       name: 'pushy', | ||||
|       srcPath: '../node_modules/react-native-update/harmony', | ||||
|     } | ||||
|   ] | ||||
| } | ||||
							
								
								
									
										20
									
								
								Example/harmony_use_pushy/harmony/code-linter.json5
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								Example/harmony_use_pushy/harmony/code-linter.json5
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,20 @@ | ||||
| { | ||||
|   "files": [ | ||||
|     "**/*.ets" | ||||
|   ], | ||||
|   "ignore": [ | ||||
|     "**/src/ohosTest/**/*", | ||||
|     "**/src/test/**/*", | ||||
|     "**/src/mock/**/*", | ||||
|     "**/node_modules/**/*", | ||||
|     "**/oh_modules/**/*", | ||||
|     "**/build/**/*", | ||||
|     "**/.preview/**/*" | ||||
|   ], | ||||
|   "ruleSet": [ | ||||
|     "plugin:@performance/recommended", | ||||
|     "plugin:@typescript-eslint/recommended" | ||||
|   ], | ||||
|   "rules": { | ||||
|   } | ||||
| } | ||||
							
								
								
									
										6
									
								
								Example/harmony_use_pushy/harmony/entry/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								Example/harmony_use_pushy/harmony/entry/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | ||||
| /node_modules | ||||
| /oh_modules | ||||
| /.preview | ||||
| /build | ||||
| /.cxx | ||||
| /.test | ||||
							
								
								
									
										33
									
								
								Example/harmony_use_pushy/harmony/entry/build-profile.json5
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								Example/harmony_use_pushy/harmony/entry/build-profile.json5
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,33 @@ | ||||
| { | ||||
|   "apiType": "stageMode", | ||||
|   "buildOption": { | ||||
|     "externalNativeOptions": { | ||||
|       "path": "./src/main/cpp/CMakeLists.txt", | ||||
|       "arguments": "", | ||||
|       "cppFlags": "", | ||||
|     }, | ||||
|   }, | ||||
|   "buildOptionSet": [ | ||||
|     { | ||||
|       "name": "release", | ||||
|       "arkOptions": { | ||||
|         "obfuscation": { | ||||
|           "ruleOptions": { | ||||
|             "enable": false, | ||||
|             "files": [ | ||||
|               "./obfuscation-rules.txt" | ||||
|             ] | ||||
|           } | ||||
|         } | ||||
|       } | ||||
|     }, | ||||
|   ], | ||||
|   "targets": [ | ||||
|     { | ||||
|       "name": "default" | ||||
|     }, | ||||
|     { | ||||
|       "name": "ohosTest", | ||||
|     } | ||||
|   ] | ||||
| } | ||||
							
								
								
									
										32
									
								
								Example/harmony_use_pushy/harmony/entry/hvigorfile.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								Example/harmony_use_pushy/harmony/entry/hvigorfile.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,32 @@ | ||||
| import { hapTasks } from '@ohos/hvigor-ohos-plugin'; | ||||
| import fs from 'fs'; | ||||
| import path from 'path'; | ||||
| export function generatePushyBuildTime(str?: string) { | ||||
|     return { | ||||
|         pluginId: 'PushyBuildTimePlugin', | ||||
|         apply(pluginContext) { | ||||
|             pluginContext.registerTask({ | ||||
|                 name: 'pushy_build_time', | ||||
|                 run: (taskContext) => { | ||||
|                     const metaFilePath = path.resolve(__dirname, 'src/main/resources/rawfile/meta.json'); | ||||
|                     const dirPath = path.dirname(metaFilePath); | ||||
|                     if (!fs.existsSync(dirPath)) { | ||||
|                         fs.mkdirSync(dirPath, { recursive: true }); | ||||
|                     } | ||||
|                     const buildTime = new Date().toISOString(); | ||||
|                     const metaContent = { pushy_build_time : buildTime }; | ||||
|                     fs.writeFileSync(metaFilePath, JSON.stringify(metaContent, null, 4)); | ||||
|                     console.log(`Build time written to ${metaFilePath}`); | ||||
|  | ||||
|                 }, | ||||
|                 dependencies: [], | ||||
|                 postDependencies: ['default@BuildJS'] | ||||
|             }) | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| export default { | ||||
|     system: hapTasks,  /* Built-in plugin of Hvigor. It cannot be modified. */ | ||||
|     plugins:[generatePushyBuildTime()]         /* Custom plugin to extend the functionality of Hvigor. */ | ||||
| } | ||||
| @@ -0,0 +1,23 @@ | ||||
| # Define project specific obfuscation rules here. | ||||
| # You can include the obfuscation configuration files in the current module's build-profile.json5. | ||||
| # | ||||
| # For more details, see | ||||
| #   https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 | ||||
|  | ||||
| # Obfuscation options: | ||||
| # -disable-obfuscation: disable all obfuscations | ||||
| # -enable-property-obfuscation: obfuscate the property names | ||||
| # -enable-toplevel-obfuscation: obfuscate the names in the global scope | ||||
| # -compact: remove unnecessary blank spaces and all line feeds | ||||
| # -remove-log: remove all console.* statements | ||||
| # -print-namecache: print the name cache that contains the mapping from the old names to new names | ||||
| # -apply-namecache: reuse the given cache file | ||||
|  | ||||
| # Keep options: | ||||
| # -keep-property-name: specifies property names that you want to keep | ||||
| # -keep-global-name: specifies names that you want to keep in the global scope | ||||
|  | ||||
| -enable-property-obfuscation | ||||
| -enable-toplevel-obfuscation | ||||
| -enable-filename-obfuscation | ||||
| -enable-export-obfuscation | ||||
| @@ -0,0 +1,28 @@ | ||||
| { | ||||
|   "meta": { | ||||
|     "stableOrder": true | ||||
|   }, | ||||
|   "lockfileVersion": 3, | ||||
|   "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", | ||||
|   "specifiers": { | ||||
|     "pushy@../../node_modules/react-native-update/harmony": "pushy@../../node_modules/react-native-update/harmony", | ||||
|     "rnoh@../../libs/rnoh": "rnoh@../../libs/rnoh" | ||||
|   }, | ||||
|   "packages": { | ||||
|     "pushy@../../node_modules/react-native-update/harmony": { | ||||
|       "name": "pushy", | ||||
|       "version": "3.1.0-0.0.7", | ||||
|       "resolved": "../../node_modules/react-native-update/harmony", | ||||
|       "registryType": "local", | ||||
|       "dependencies": { | ||||
|         "rnoh": "file:../../../libs/rnoh" | ||||
|       } | ||||
|     }, | ||||
|     "rnoh@../../libs/rnoh": { | ||||
|       "name": "rnoh", | ||||
|       "version": "0.72.12", | ||||
|       "resolved": "../../libs/rnoh", | ||||
|       "registryType": "local" | ||||
|     } | ||||
|   } | ||||
| } | ||||
							
								
								
									
										13
									
								
								Example/harmony_use_pushy/harmony/entry/oh-package.json5
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								Example/harmony_use_pushy/harmony/entry/oh-package.json5
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | ||||
| { | ||||
|   "name": "entry", | ||||
|   "version": "1.0.0", | ||||
|   "description": "Please describe the basic information.", | ||||
|   "main": "", | ||||
|   "author": "", | ||||
|   "license": "", | ||||
|   "dependencies": { | ||||
|     "rnoh": "file:../../libs/rnoh", | ||||
|     "pushy": "file:../../node_modules/react-native-update/harmony" | ||||
|   } | ||||
| } | ||||
|  | ||||
							
								
								
									
										1
									
								
								Example/harmony_use_pushy/harmony/entry/src/main/cpp/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								Example/harmony_use_pushy/harmony/entry/src/main/cpp/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | ||||
| jsbundle.h | ||||
| @@ -0,0 +1,15 @@ | ||||
| cmake_minimum_required(VERSION 3.16) | ||||
| project(rnapp) | ||||
| set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}") | ||||
| set(NODE_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../node_modules") | ||||
| set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../libs/rnoh/src/main/cpp") | ||||
| set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules") | ||||
| add_subdirectory("${OH_MODULES}/pushy/src/main/cpp" ./pushy) | ||||
|  | ||||
| add_subdirectory("${RNOH_CPP_DIR}" ./rn) | ||||
| add_library(rnoh_app SHARED | ||||
|     "./PackageProvider.cpp" | ||||
|     "${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp" | ||||
| ) | ||||
| target_link_libraries(rnoh_app PUBLIC rnoh) | ||||
| target_link_libraries(rnoh_app PUBLIC rnoh_pushy) | ||||
| @@ -0,0 +1,9 @@ | ||||
| #include "RNOH/PackageProvider.h" | ||||
| #include "PushyPackage.h" | ||||
| using namespace rnoh; | ||||
|  | ||||
| std::vector<std::shared_ptr<Package>> PackageProvider::getPackages(Package::Context ctx) { | ||||
|     return { | ||||
|          std::make_shared<PushyPackage>(ctx) | ||||
|     }; | ||||
| } | ||||
| @@ -0,0 +1,6 @@ | ||||
| import type {RNPackageContext, RNPackage} from 'rnoh/ts'; | ||||
| import {PushyPackage} from 'pushy/ts'; | ||||
|  | ||||
| export function createRNPackages(ctx: RNPackageContext): RNPackage[] { | ||||
|   return [new PushyPackage(ctx)]; | ||||
| } | ||||
| @@ -0,0 +1,11 @@ | ||||
| import {RNAbility} from 'rnoh/ts'; | ||||
|  | ||||
| export default class EntryAbility extends RNAbility { | ||||
|   getPagePath() { | ||||
|     return 'pages/Index'; | ||||
|   } | ||||
|  | ||||
|   shouldCleanUpRNInstance__hack() { | ||||
|     return true // Used by RNOH devs. If set to true, the app may crash. | ||||
|   } | ||||
| } | ||||
| @@ -0,0 +1,12 @@ | ||||
| import { hilog } from '@kit.PerformanceAnalysisKit'; | ||||
| import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; | ||||
|  | ||||
| export default class EntryBackupAbility extends BackupExtensionAbility { | ||||
|   async onBackup() { | ||||
|     hilog.info(0x0000, 'testTag', 'onBackup ok'); | ||||
|   } | ||||
|  | ||||
|   async onRestore(bundleVersion: BundleVersion) { | ||||
|     hilog.info(0x0000, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); | ||||
|   } | ||||
| } | ||||
| @@ -0,0 +1,61 @@ | ||||
| import { FileJSBundleProvider } from 'pushy/src/main/ets/FileJSBundleProvider'; | ||||
| import { ComponentBuilderContext, JSBundleProvider, RNOHLogger } from 'rnoh'; | ||||
| import { | ||||
|   RNApp, | ||||
|   RNAbility, | ||||
|   AnyJSBundleProvider, | ||||
|   ResourceJSBundleProvider, | ||||
|   TraceJSBundleProviderDecorator, | ||||
| } from 'rnoh' | ||||
| import { createRNPackages } from '../RNPackagesFactory' | ||||
|  | ||||
| @Builder | ||||
| export function CustomComponentBuilder(ctx: ComponentBuilderContext) { | ||||
|  | ||||
| } | ||||
|  | ||||
|  | ||||
| @Entry | ||||
| @Component | ||||
| struct Index { | ||||
|   @StorageLink('RNAbility') private rnAbility: RNAbility | undefined = undefined | ||||
|   @State shouldShow: boolean = false | ||||
|   @State message: string = 'Hello World'; | ||||
|  | ||||
|   aboutToAppear(): void { | ||||
|     this.shouldShow = true | ||||
|   } | ||||
|  | ||||
|   onBackPress(): boolean | undefined { | ||||
|     // NOTE: this is required since `Ability`'s `onBackPressed` function always | ||||
|     // terminates or puts the app in the background, but we want Ark to ignore it completely | ||||
|     // when handled by RN | ||||
|     return this.rnAbility?.onBackPress(); | ||||
|   } | ||||
|  | ||||
|   build() { | ||||
|     Column() { | ||||
|       if (this.rnAbility && this.shouldShow) { | ||||
|         RNApp({ | ||||
|           rnInstanceConfig: { createRNPackages }, | ||||
|           initialProps: { "foo": "bar" } as Record<string, string>, | ||||
|           appKey: "harmony_use_pushy", | ||||
|           buildCustomComponent: CustomComponentBuilder, | ||||
|           onSetUp: (rnInstance) => { | ||||
|             rnInstance.enableFeatureFlag("ENABLE_RN_INSTANCE_CLEAN_UP") | ||||
|           }, | ||||
|           jsBundleProvider: new TraceJSBundleProviderDecorator( | ||||
|             new AnyJSBundleProvider([ | ||||
|               // MetroJSBundleProvider.fromServerIp('127.0.0.1'), | ||||
|               // new ResourceJSBundleProvider(this.rnAbility.context.resourceManager, 'hermes_bundle.hbc'), | ||||
|               new FileJSBundleProvider(this.rnAbility.context), | ||||
|               new ResourceJSBundleProvider(this.rnAbility.context.resourceManager, 'bundle.harmony.js') | ||||
|             ]), | ||||
|             this.rnAbility.getLogger()), | ||||
|         }) | ||||
|       } | ||||
|     } | ||||
|     .height('100%') | ||||
|     .width('100%') | ||||
|   } | ||||
| } | ||||
| @@ -0,0 +1,71 @@ | ||||
| { | ||||
|   "module": { | ||||
|     "name": "entry", | ||||
|     "type": "entry", | ||||
|     "description": "$string:module_desc", | ||||
|     "mainElement": "EntryAbility", | ||||
|     "deviceTypes": [ | ||||
|       "phone", | ||||
|       "tablet", | ||||
|       "2in1" | ||||
|     ], | ||||
|     "deliveryWithInstall": true, | ||||
|     "installationFree": false, | ||||
|     "pages": "$profile:main_pages", | ||||
|     "abilities": [ | ||||
|       { | ||||
|         "name": "EntryAbility", | ||||
|         "srcEntry": "./ets/entryability/EntryAbility.ets", | ||||
|         "description": "$string:EntryAbility_desc", | ||||
|         "icon": "$media:layered_image", | ||||
|         "label": "$string:EntryAbility_label", | ||||
|         "startWindowIcon": "$media:startIcon", | ||||
|         "startWindowBackground": "$color:start_window_background", | ||||
|         "exported": true, | ||||
|         "skills": [ | ||||
|           { | ||||
|             "entities": [ | ||||
|               "entity.system.home" | ||||
|             ], | ||||
|             "actions": [ | ||||
|               "action.system.home" | ||||
|             ] | ||||
|           } | ||||
|         ] | ||||
|       } | ||||
|     ], | ||||
|     "extensionAbilities": [ | ||||
|       { | ||||
|         "name": "EntryBackupAbility", | ||||
|         "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", | ||||
|         "type": "backup", | ||||
|         "exported": false, | ||||
|         "metadata": [ | ||||
|           { | ||||
|             "name": "ohos.extension.backup", | ||||
|             "resource": "$profile:backup_config" | ||||
|           } | ||||
|         ], | ||||
|       } | ||||
|     ], | ||||
|     "requestPermissions": [ | ||||
|       { | ||||
|         "name": "ohos.permission.WRITE_MEDIA", | ||||
|         "reason": "$string:reason_write_media", | ||||
|         "usedScene": { | ||||
|           "when": "always", | ||||
|         } | ||||
|       }, | ||||
|       { | ||||
|         "name": "ohos.permission.READ_MEDIA", | ||||
|         "reason": "$string:reason_read_media", | ||||
|         "usedScene": { | ||||
|           "when": "always", | ||||
|         } | ||||
|       }, | ||||
|       { | ||||
|         "name": "ohos.permission.INTERNET" | ||||
|       } | ||||
|     ] | ||||
|   } | ||||
| } | ||||
| @@ -0,0 +1,8 @@ | ||||
| { | ||||
|   "color": [ | ||||
|     { | ||||
|       "name": "start_window_background", | ||||
|       "value": "#FFFFFF" | ||||
|     } | ||||
|   ] | ||||
| } | ||||
| @@ -0,0 +1,28 @@ | ||||
| { | ||||
|   "string": [ | ||||
|     { | ||||
|       "name": "Access_location", | ||||
|       "value": "access location" | ||||
|     }, | ||||
|     { | ||||
|       "name": "module_desc", | ||||
|       "value": "module description" | ||||
|     }, | ||||
|     { | ||||
|       "name": "EntryAbility_desc", | ||||
|       "value": "description" | ||||
|     }, | ||||
|     { | ||||
|       "name": "EntryAbility_label", | ||||
|       "value": "label" | ||||
|     }, | ||||
|     { | ||||
|       "name": "reason_write_media", | ||||
|       "value": "Write files to internal storage" | ||||
|     }, | ||||
|     { | ||||
|       "name": "reason_read_media", | ||||
|       "value": "Read files to internal storage" | ||||
|     } | ||||
|   ] | ||||
| } | ||||
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 56 KiB | 
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 12 KiB | 
| @@ -0,0 +1,7 @@ | ||||
| { | ||||
|   "layered-image": | ||||
|   { | ||||
|     "background" : "$media:background", | ||||
|     "foreground" : "$media:foreground" | ||||
|   } | ||||
| } | ||||
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 20 KiB | 
| @@ -0,0 +1,3 @@ | ||||
| { | ||||
|   "allowToBackupRestore": true | ||||
| } | ||||
| @@ -0,0 +1,5 @@ | ||||
| { | ||||
|   "src": [ | ||||
|     "pages/Index" | ||||
|   ] | ||||
| } | ||||
| @@ -0,0 +1,16 @@ | ||||
| { | ||||
|   "string": [ | ||||
|     { | ||||
|       "name": "module_desc", | ||||
|       "value": "module description" | ||||
|     }, | ||||
|     { | ||||
|       "name": "EntryAbility_desc", | ||||
|       "value": "description" | ||||
|     }, | ||||
|     { | ||||
|       "name": "EntryAbility_label", | ||||
|       "value": "label" | ||||
|     } | ||||
|   ] | ||||
| } | ||||
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 1.8 KiB | 
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							| @@ -0,0 +1,16 @@ | ||||
| { | ||||
|   "string": [ | ||||
|     { | ||||
|       "name": "module_desc", | ||||
|       "value": "模块描述" | ||||
|     }, | ||||
|     { | ||||
|       "name": "EntryAbility_desc", | ||||
|       "value": "description" | ||||
|     }, | ||||
|     { | ||||
|       "name": "EntryAbility_label", | ||||
|       "value": "label" | ||||
|     } | ||||
|   ] | ||||
| } | ||||
| @@ -0,0 +1,2 @@ | ||||
| { | ||||
| } | ||||
| @@ -0,0 +1,35 @@ | ||||
| import { hilog } from '@kit.PerformanceAnalysisKit'; | ||||
| import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; | ||||
|  | ||||
| export default function abilityTest() { | ||||
|   describe('ActsAbilityTest', () => { | ||||
|     // Defines a test suite. Two parameters are supported: test suite name and test suite function. | ||||
|     beforeAll(() => { | ||||
|       // Presets an action, which is performed only once before all test cases of the test suite start. | ||||
|       // This API supports only one parameter: preset action function. | ||||
|     }) | ||||
|     beforeEach(() => { | ||||
|       // Presets an action, which is performed before each unit test case starts. | ||||
|       // The number of execution times is the same as the number of test cases defined by **it**. | ||||
|       // This API supports only one parameter: preset action function. | ||||
|     }) | ||||
|     afterEach(() => { | ||||
|       // Presets a clear action, which is performed after each unit test case ends. | ||||
|       // The number of execution times is the same as the number of test cases defined by **it**. | ||||
|       // This API supports only one parameter: clear action function. | ||||
|     }) | ||||
|     afterAll(() => { | ||||
|       // Presets a clear action, which is performed after all test cases of the test suite end. | ||||
|       // This API supports only one parameter: clear action function. | ||||
|     }) | ||||
|     it('assertContain', 0, () => { | ||||
|       // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. | ||||
|       hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); | ||||
|       let a = 'abc'; | ||||
|       let b = 'b'; | ||||
|       // Defines a variety of assertion methods, which are used to declare expected boolean conditions. | ||||
|       expect(a).assertContain(b); | ||||
|       expect(a).assertEqual(a); | ||||
|     }) | ||||
|   }) | ||||
| } | ||||
| @@ -0,0 +1,5 @@ | ||||
| import abilityTest from './Ability.test'; | ||||
|  | ||||
| export default function testsuite() { | ||||
|   abilityTest(); | ||||
| } | ||||
| @@ -0,0 +1,13 @@ | ||||
| { | ||||
|   "module": { | ||||
|     "name": "entry_test", | ||||
|     "type": "feature", | ||||
|     "deviceTypes": [ | ||||
|       "phone", | ||||
|       "tablet", | ||||
|       "2in1" | ||||
|     ], | ||||
|     "deliveryWithInstall": true, | ||||
|     "installationFree": false | ||||
|   } | ||||
| } | ||||
| @@ -0,0 +1,5 @@ | ||||
| import localUnitTest from './LocalUnit.test'; | ||||
|  | ||||
| export default function testsuite() { | ||||
|   localUnitTest(); | ||||
| } | ||||
| @@ -0,0 +1,33 @@ | ||||
| import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; | ||||
|  | ||||
| export default function localUnitTest() { | ||||
|   describe('localUnitTest', () => { | ||||
|     // Defines a test suite. Two parameters are supported: test suite name and test suite function. | ||||
|     beforeAll(() => { | ||||
|       // Presets an action, which is performed only once before all test cases of the test suite start. | ||||
|       // This API supports only one parameter: preset action function. | ||||
|     }); | ||||
|     beforeEach(() => { | ||||
|       // Presets an action, which is performed before each unit test case starts. | ||||
|       // The number of execution times is the same as the number of test cases defined by **it**. | ||||
|       // This API supports only one parameter: preset action function. | ||||
|     }); | ||||
|     afterEach(() => { | ||||
|       // Presets a clear action, which is performed after each unit test case ends. | ||||
|       // The number of execution times is the same as the number of test cases defined by **it**. | ||||
|       // This API supports only one parameter: clear action function. | ||||
|     }); | ||||
|     afterAll(() => { | ||||
|       // Presets a clear action, which is performed after all test cases of the test suite end. | ||||
|       // This API supports only one parameter: clear action function. | ||||
|     }); | ||||
|     it('assertContain', 0, () => { | ||||
|       // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. | ||||
|       let a = 'abc'; | ||||
|       let b = 'b'; | ||||
|       // Defines a variety of assertion methods, which are used to declare expected boolean conditions. | ||||
|       expect(a).assertContain(b); | ||||
|       expect(a).assertEqual(a); | ||||
|     }); | ||||
|   }); | ||||
| } | ||||
							
								
								
									
										22
									
								
								Example/harmony_use_pushy/harmony/hvigor/hvigor-config.json5
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								Example/harmony_use_pushy/harmony/hvigor/hvigor-config.json5
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,22 @@ | ||||
| { | ||||
|   "modelVersion": "5.0.0", | ||||
|   "dependencies": { | ||||
|   }, | ||||
|   "execution": { | ||||
|     // "analyze": "normal",                     /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ | ||||
|     // "daemon": true,                          /* Enable daemon compilation. Value: [ true | false ]. Default: true */ | ||||
|     // "incremental": true,                     /* Enable incremental compilation. Value: [ true | false ]. Default: true */ | ||||
|     // "parallel": true,                        /* Enable parallel compilation. Value: [ true | false ]. Default: true */ | ||||
|     // "typeCheck": false,                      /* Enable typeCheck. Value: [ true | false ]. Default: false */ | ||||
|   }, | ||||
|   "logging": { | ||||
|     // "level": "info"                          /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ | ||||
|   }, | ||||
|   "debugging": { | ||||
|     // "stacktrace": false                      /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ | ||||
|   }, | ||||
|   "nodeOptions": { | ||||
|     // "maxOldSpaceSize": 8192                  /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ | ||||
|     // "exposeGC": true                         /* Enable to trigger garbage collection explicitly. Default: true*/ | ||||
|   } | ||||
| } | ||||
							
								
								
									
										6
									
								
								Example/harmony_use_pushy/harmony/hvigorfile.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								Example/harmony_use_pushy/harmony/hvigorfile.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | ||||
| import { appTasks } from '@ohos/hvigor-ohos-plugin'; | ||||
|  | ||||
| export default { | ||||
|     system: appTasks,  /* Built-in plugin of Hvigor. It cannot be modified. */ | ||||
|     plugins:[]         /* Custom plugin to extend the functionality of Hvigor. */ | ||||
| } | ||||
							
								
								
									
										27
									
								
								Example/harmony_use_pushy/harmony/oh-package-lock.json5
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								Example/harmony_use_pushy/harmony/oh-package-lock.json5
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,27 @@ | ||||
| { | ||||
|   "meta": { | ||||
|     "stableOrder": true | ||||
|   }, | ||||
|   "lockfileVersion": 3, | ||||
|   "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", | ||||
|   "specifiers": { | ||||
|     "@ohos/hamock@1.0.0": "@ohos/hamock@1.0.0", | ||||
|     "@ohos/hypium@1.0.19": "@ohos/hypium@1.0.19" | ||||
|   }, | ||||
|   "packages": { | ||||
|     "@ohos/hamock@1.0.0": { | ||||
|       "name": "@ohos/hamock", | ||||
|       "version": "1.0.0", | ||||
|       "integrity": "sha512-K6lDPYc6VkKe6ZBNQa9aoG+ZZMiwqfcR/7yAVFSUGIuOAhPvCJAo9+t1fZnpe0dBRBPxj2bxPPbKh69VuyAtDg==", | ||||
|       "resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/hamock/-/hamock-1.0.0.har", | ||||
|       "registryType": "ohpm" | ||||
|     }, | ||||
|     "@ohos/hypium@1.0.19": { | ||||
|       "name": "@ohos/hypium", | ||||
|       "version": "1.0.19", | ||||
|       "integrity": "sha512-cEjDgLFCm3cWZDeRXk7agBUkPqjWxUo6AQeiu0gEkb3J8ESqlduQLSIXeo3cCsm8U/asL7iKjF85ZyOuufAGSQ==", | ||||
|       "resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/hypium/-/hypium-1.0.19.har", | ||||
|       "registryType": "ohpm" | ||||
|     } | ||||
|   } | ||||
| } | ||||
							
								
								
									
										17
									
								
								Example/harmony_use_pushy/harmony/oh-package.json5
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								Example/harmony_use_pushy/harmony/oh-package.json5
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,17 @@ | ||||
| { | ||||
|   "modelVersion": "5.0.0", | ||||
|   "description": "Please describe the basic information.", | ||||
|   "dependencies": { | ||||
|   }, | ||||
|   "devDependencies": { | ||||
|     "@ohos/hypium": "1.0.19", | ||||
|     "@ohos/hamock": "1.0.0" | ||||
|   }, | ||||
|   "arkTs": { | ||||
|     "compilerOptions": { | ||||
|       "noImplicitAny": false, | ||||
|       "suppressImplicitAnyIndexErrors": true, | ||||
|       "strict": false | ||||
|     } | ||||
|   } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 波仔糕
					波仔糕