@thelacanians/vue-native-cli 0.4.2 → 0.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +43 -23
- package/native/android/README.md +205 -0
- package/native/android/VueNativeCore/build.gradle.kts +100 -0
- package/native/android/VueNativeCore/consumer-rules.pro +12 -0
- package/native/android/VueNativeCore/proguard-rules.pro +33 -0
- package/native/android/VueNativeCore/src/main/AndroidManifest.xml +17 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Bridge/ErrorOverlayView.kt +94 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Bridge/HotReloadManager.kt +105 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Bridge/JSPolyfills.kt +652 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Bridge/JSRuntime.kt +207 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Bridge/NativeBridge.kt +417 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/ComponentRegistry.kt +76 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VActionSheetFactory.kt +78 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VActivityIndicatorFactory.kt +46 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VAlertDialogFactory.kt +84 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VButtonFactory.kt +73 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VCheckboxFactory.kt +93 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VDropdownFactory.kt +125 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VImageFactory.kt +75 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VInputFactory.kt +210 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VKeyboardAvoidingFactory.kt +31 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VListFactory.kt +183 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VModalFactory.kt +105 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VPickerFactory.kt +57 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VPressableFactory.kt +109 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VProgressBarFactory.kt +43 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VRadioFactory.kt +103 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VRefreshControlFactory.kt +73 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VRootFactory.kt +39 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VSafeAreaFactory.kt +48 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VScrollViewFactory.kt +105 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VSectionListFactory.kt +144 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VSegmentedControlFactory.kt +77 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VSliderFactory.kt +74 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VStatusBarFactory.kt +52 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VSwitchFactory.kt +62 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VTextFactory.kt +53 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VVideoFactory.kt +191 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VViewFactory.kt +48 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VWebViewFactory.kt +90 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/NativeComponentFactory.kt +40 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/VTextNodeView.kt +23 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Helpers/GestureHelper.kt +16 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Helpers/TouchableView.kt +105 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/AnimationModule.kt +292 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/AppStateModule.kt +41 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/AsyncStorageModule.kt +59 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/AudioModule.kt +331 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/BackgroundTaskModule.kt +166 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/BiometryModule.kt +56 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/BluetoothModule.kt +302 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/CalendarModule.kt +198 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/CameraModule.kt +64 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/ClipboardModule.kt +36 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/ContactsModule.kt +288 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/DatabaseModule.kt +229 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/DeviceInfoModule.kt +39 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/FileSystemModule.kt +193 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/GeolocationModule.kt +68 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/HapticsModule.kt +61 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/HttpModule.kt +111 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/IAPModule.kt +302 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/KeyboardModule.kt +26 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/LinkingModule.kt +43 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/NativeModule.kt +27 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/NativeModuleRegistry.kt +92 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/NetworkModule.kt +75 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/NotificationsModule.kt +181 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/OTAModule.kt +255 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/PerformanceModule.kt +147 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/PermissionsModule.kt +126 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/SecureStorageModule.kt +51 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/SensorsModule.kt +134 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/ShareModule.kt +36 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/SocialAuthModule.kt +160 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/WebSocketModule.kt +155 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Styling/StyleEngine.kt +802 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Tags.kt +43 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/VueNativeActivity.kt +169 -0
- package/native/android/VueNativeCore/src/main/res/values/ids.xml +8 -0
- package/native/android/app/build.gradle.kts +45 -0
- package/native/android/app/proguard-rules.pro +5 -0
- package/native/android/app/src/main/AndroidManifest.xml +25 -0
- package/native/android/app/src/main/assets/.gitkeep +0 -0
- package/native/android/app/src/main/kotlin/com/vuenative/example/counter/MainActivity.kt +14 -0
- package/native/android/app/src/main/res/layout/activity_main.xml +6 -0
- package/native/android/app/src/main/res/values/strings.xml +3 -0
- package/native/android/app/src/main/res/values/themes.xml +9 -0
- package/native/android/app/src/main/res/xml/network_security_config.xml +8 -0
- package/native/android/build.gradle.kts +6 -0
- package/native/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/native/android/gradle/wrapper/gradle-wrapper.properties +7 -0
- package/native/android/gradle.properties +4 -0
- package/native/android/gradlew +87 -0
- package/native/android/gradlew.bat +48 -0
- package/native/android/settings.gradle.kts +20 -0
- package/native/ios/VueNativeCore/Package.resolved +23 -0
- package/native/ios/VueNativeCore/Package.swift +32 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Bridge/CertificatePinning.swift +132 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Bridge/ErrorOverlayView.swift +92 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Bridge/HotReloadManager.swift +147 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Bridge/JSPolyfills.swift +711 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Bridge/JSRuntime.swift +421 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Bridge/NativeBridge.swift +891 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Bridge/VueNativeViewController.swift +88 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/ComponentRegistry.swift +193 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VActionSheetFactory.swift +91 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VActivityIndicatorFactory.swift +74 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VAlertDialogFactory.swift +150 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VButtonFactory.swift +93 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VCheckboxFactory.swift +114 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VDropdownFactory.swift +112 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VImageFactory.swift +172 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VInputFactory.swift +357 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VKeyboardAvoidingFactory.swift +99 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VListFactory.swift +250 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VModalFactory.swift +112 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VPickerFactory.swift +96 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VPressableFactory.swift +168 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VProgressBarFactory.swift +39 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VRadioFactory.swift +167 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VRefreshControlFactory.swift +153 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VSafeAreaFactory.swift +56 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VScrollViewFactory.swift +240 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VSectionListFactory.swift +248 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VSegmentedControlFactory.swift +73 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VSliderFactory.swift +63 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VStatusBarFactory.swift +50 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VSwitchFactory.swift +108 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VTextFactory.swift +290 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VVideoFactory.swift +246 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VViewFactory.swift +157 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VWebViewFactory.swift +172 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/NativeComponentFactory.swift +53 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Helpers/GestureWrapper.swift +107 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Helpers/TouchableView.swift +136 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Helpers/UIColor+Hex.swift +80 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/AnimationModule.swift +291 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/AppStateModule.swift +65 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/AsyncStorageModule.swift +68 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/AudioModule.swift +366 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/BackgroundTaskModule.swift +135 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/BiometryModule.swift +61 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/BluetoothModule.swift +387 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/CalendarModule.swift +161 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/CameraModule.swift +318 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/ClipboardModule.swift +33 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/ContactsModule.swift +173 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/DatabaseModule.swift +259 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/DeviceInfoModule.swift +34 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/FileSystemModule.swift +233 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/GeolocationModule.swift +147 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/HapticsModule.swift +50 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/IAPModule.swift +194 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/KeyboardModule.swift +31 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/LinkingModule.swift +42 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/NativeModule.swift +28 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/NativeModuleRegistry.swift +78 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/NetworkModule.swift +62 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/NotificationsModule.swift +215 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/OTAModule.swift +281 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/PerformanceModule.swift +138 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/PermissionsModule.swift +190 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/SecureStorageModule.swift +118 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/SensorsModule.swift +103 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/ShareModule.swift +49 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/SocialAuthModule.swift +240 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/WebSocketModule.swift +213 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Resources/vue-native-placeholder.js +8 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Styling/StyleEngine.swift +885 -0
- package/native/ios/VueNativeCore/Tests/VueNativeCoreTests/JSRuntimeTests.swift +362 -0
- package/package.json +3 -2
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
#if canImport(UIKit)
|
|
2
|
+
import XCTest
|
|
3
|
+
import JavaScriptCore
|
|
4
|
+
@testable import VueNativeCore
|
|
5
|
+
|
|
6
|
+
final class JSRuntimeTests: XCTestCase {
|
|
7
|
+
|
|
8
|
+
// MARK: - Properties
|
|
9
|
+
|
|
10
|
+
/// We create a fresh JSContext for each test rather than using JSRuntime.shared,
|
|
11
|
+
/// so tests are fully isolated and don't depend on singleton state.
|
|
12
|
+
private var context: JSContext!
|
|
13
|
+
|
|
14
|
+
// MARK: - Setup / Teardown
|
|
15
|
+
|
|
16
|
+
override func setUp() {
|
|
17
|
+
super.setUp()
|
|
18
|
+
context = JSContext()
|
|
19
|
+
context.exceptionHandler = { _, exception in
|
|
20
|
+
guard let exception = exception else { return }
|
|
21
|
+
XCTFail("JS Exception: \(exception.toString() ?? "unknown")")
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
override func tearDown() {
|
|
26
|
+
context = nil
|
|
27
|
+
super.tearDown()
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// MARK: - Test: JSContext Creation
|
|
31
|
+
|
|
32
|
+
func testJSContextCreation() {
|
|
33
|
+
XCTAssertNotNil(context, "JSContext should be created successfully")
|
|
34
|
+
|
|
35
|
+
// Test basic evaluation
|
|
36
|
+
let result = context.evaluateScript("1 + 2")
|
|
37
|
+
XCTAssertEqual(result?.toInt32(), 3, "JSContext should evaluate basic arithmetic")
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
func testJSContextStringEvaluation() {
|
|
41
|
+
let result = context.evaluateScript("'Hello' + ' ' + 'Vue Native'")
|
|
42
|
+
XCTAssertEqual(result?.toString(), "Hello Vue Native")
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
func testJSContextObjectCreation() {
|
|
46
|
+
context.evaluateScript("var obj = { name: 'test', value: 42 };")
|
|
47
|
+
let name = context.objectForKeyedSubscript("obj")?.objectForKeyedSubscript("name")?.toString()
|
|
48
|
+
let value = context.objectForKeyedSubscript("obj")?.objectForKeyedSubscript("value")?.toInt32()
|
|
49
|
+
XCTAssertEqual(name, "test")
|
|
50
|
+
XCTAssertEqual(value, 42)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// MARK: - Test: Function Registration
|
|
54
|
+
|
|
55
|
+
func testSwiftFunctionRegistration() {
|
|
56
|
+
let expectation = self.expectation(description: "Swift function called from JS")
|
|
57
|
+
|
|
58
|
+
let nativeFunction: @convention(block) (JSValue) -> Void = { value in
|
|
59
|
+
XCTAssertEqual(value.toString(), "hello from JS")
|
|
60
|
+
expectation.fulfill()
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
context.setObject(nativeFunction, forKeyedSubscript: "nativeCallback" as NSString)
|
|
64
|
+
context.evaluateScript("nativeCallback('hello from JS');")
|
|
65
|
+
|
|
66
|
+
waitForExpectations(timeout: 1.0)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
func testObjectForKeyedSubscriptCall() {
|
|
70
|
+
// Test that objectForKeyedSubscript().call() works correctly
|
|
71
|
+
// This is the pattern used by JSRuntime.callFunction() for performance
|
|
72
|
+
context.evaluateScript("""
|
|
73
|
+
function add(a, b) { return a + b; }
|
|
74
|
+
""")
|
|
75
|
+
|
|
76
|
+
let addFn = context.objectForKeyedSubscript("add")
|
|
77
|
+
XCTAssertNotNil(addFn)
|
|
78
|
+
XCTAssertFalse(addFn!.isUndefined)
|
|
79
|
+
|
|
80
|
+
let result = addFn?.call(withArguments: [3, 4])
|
|
81
|
+
XCTAssertEqual(result?.toInt32(), 7)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// MARK: - Test: Console Polyfills
|
|
85
|
+
|
|
86
|
+
func testConsolePolyfills() {
|
|
87
|
+
// Register console polyfills
|
|
88
|
+
registerConsolePolyfills()
|
|
89
|
+
|
|
90
|
+
// These should not crash
|
|
91
|
+
context.evaluateScript("console.log('test log');")
|
|
92
|
+
context.evaluateScript("console.warn('test warn');")
|
|
93
|
+
context.evaluateScript("console.error('test error');")
|
|
94
|
+
|
|
95
|
+
// Verify console object exists
|
|
96
|
+
let consoleObj = context.objectForKeyedSubscript("console")
|
|
97
|
+
XCTAssertNotNil(consoleObj)
|
|
98
|
+
XCTAssertFalse(consoleObj!.isUndefined)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// MARK: - Test: setTimeout Polyfill
|
|
102
|
+
|
|
103
|
+
func testSetTimeoutPolyfill() {
|
|
104
|
+
let expectation = self.expectation(description: "setTimeout fires")
|
|
105
|
+
|
|
106
|
+
// Simple setTimeout implementation for testing
|
|
107
|
+
let setTimeout: @convention(block) (JSValue, JSValue) -> JSValue = { callback, delay in
|
|
108
|
+
let delayMs = delay.toDouble()
|
|
109
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + delayMs / 1000.0) {
|
|
110
|
+
callback.call(withArguments: [])
|
|
111
|
+
}
|
|
112
|
+
return JSValue(int32: 1, in: JSContext.current())
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
context.setObject(setTimeout, forKeyedSubscript: "setTimeout" as NSString)
|
|
116
|
+
|
|
117
|
+
let fulfilled: @convention(block) () -> Void = {
|
|
118
|
+
expectation.fulfill()
|
|
119
|
+
}
|
|
120
|
+
context.setObject(fulfilled, forKeyedSubscript: "testFulfill" as NSString)
|
|
121
|
+
|
|
122
|
+
context.evaluateScript("setTimeout(testFulfill, 50);")
|
|
123
|
+
|
|
124
|
+
waitForExpectations(timeout: 2.0)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// MARK: - Test: queueMicrotask Polyfill
|
|
128
|
+
|
|
129
|
+
func testQueueMicrotaskPolyfill() {
|
|
130
|
+
// queueMicrotask uses Promise.resolve().then()
|
|
131
|
+
context.evaluateScript("""
|
|
132
|
+
function queueMicrotask(callback) {
|
|
133
|
+
Promise.resolve().then(callback);
|
|
134
|
+
}
|
|
135
|
+
""")
|
|
136
|
+
|
|
137
|
+
// Verify the function exists
|
|
138
|
+
let fn = context.objectForKeyedSubscript("queueMicrotask")
|
|
139
|
+
XCTAssertNotNil(fn)
|
|
140
|
+
XCTAssertFalse(fn!.isUndefined)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// MARK: - Test: Microtask Drain (CRITICAL for Vue's scheduler)
|
|
144
|
+
|
|
145
|
+
func testMicrotaskDrain() {
|
|
146
|
+
// This is the CRITICAL test that validates Vue's scheduler will work.
|
|
147
|
+
// Vue uses Promise.resolve().then() for async batching.
|
|
148
|
+
// After evaluateScript returns, microtasks should have drained.
|
|
149
|
+
|
|
150
|
+
context.evaluateScript("""
|
|
151
|
+
var result = [];
|
|
152
|
+
Promise.resolve().then(function() { result.push('micro1'); });
|
|
153
|
+
result.push('sync');
|
|
154
|
+
Promise.resolve().then(function() { result.push('micro2'); });
|
|
155
|
+
""")
|
|
156
|
+
|
|
157
|
+
// Force microtask drain
|
|
158
|
+
context.evaluateScript("void 0;")
|
|
159
|
+
|
|
160
|
+
let result = context.objectForKeyedSubscript("result")?.toArray() as? [String]
|
|
161
|
+
|
|
162
|
+
// After evaluation + drain, the result should include both sync and microtask items
|
|
163
|
+
// The exact order depends on when JSC drains the microtask queue.
|
|
164
|
+
// Expected: ["sync", "micro1", "micro2"]
|
|
165
|
+
XCTAssertNotNil(result, "result array should exist")
|
|
166
|
+
|
|
167
|
+
if let result = result {
|
|
168
|
+
XCTAssertTrue(result.contains("sync"), "Synchronous code should have run")
|
|
169
|
+
// Microtasks should drain after evaluateScript
|
|
170
|
+
XCTAssertTrue(result.contains("micro1"), "First microtask should have drained")
|
|
171
|
+
XCTAssertTrue(result.contains("micro2"), "Second microtask should have drained")
|
|
172
|
+
|
|
173
|
+
// sync should be first
|
|
174
|
+
if let syncIdx = result.firstIndex(of: "sync"),
|
|
175
|
+
let micro1Idx = result.firstIndex(of: "micro1") {
|
|
176
|
+
XCTAssertLessThan(syncIdx, micro1Idx, "sync should run before microtasks")
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
func testMicrotaskChaining() {
|
|
182
|
+
// Test that chained microtasks also drain
|
|
183
|
+
context.evaluateScript("""
|
|
184
|
+
var order = [];
|
|
185
|
+
Promise.resolve()
|
|
186
|
+
.then(function() {
|
|
187
|
+
order.push('first');
|
|
188
|
+
return Promise.resolve();
|
|
189
|
+
})
|
|
190
|
+
.then(function() {
|
|
191
|
+
order.push('second');
|
|
192
|
+
});
|
|
193
|
+
order.push('sync');
|
|
194
|
+
""")
|
|
195
|
+
|
|
196
|
+
// Force drain
|
|
197
|
+
context.evaluateScript("void 0;")
|
|
198
|
+
|
|
199
|
+
let order = context.objectForKeyedSubscript("order")?.toArray() as? [String]
|
|
200
|
+
XCTAssertNotNil(order)
|
|
201
|
+
|
|
202
|
+
if let order = order {
|
|
203
|
+
XCTAssertEqual(order.first, "sync", "Sync should run first")
|
|
204
|
+
XCTAssertTrue(order.contains("first"), "First chained microtask should drain")
|
|
205
|
+
XCTAssertTrue(order.contains("second"), "Second chained microtask should drain")
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
func testAsyncAwaitMicrotasks() {
|
|
210
|
+
// Test async/await (which compiles to Promise chains in JSC)
|
|
211
|
+
context.evaluateScript("""
|
|
212
|
+
var asyncResult = [];
|
|
213
|
+
async function runAsync() {
|
|
214
|
+
asyncResult.push('before await');
|
|
215
|
+
await Promise.resolve();
|
|
216
|
+
asyncResult.push('after await');
|
|
217
|
+
}
|
|
218
|
+
runAsync();
|
|
219
|
+
asyncResult.push('after call');
|
|
220
|
+
""")
|
|
221
|
+
|
|
222
|
+
// Force drain
|
|
223
|
+
context.evaluateScript("void 0;")
|
|
224
|
+
|
|
225
|
+
let asyncResult = context.objectForKeyedSubscript("asyncResult")?.toArray() as? [String]
|
|
226
|
+
XCTAssertNotNil(asyncResult)
|
|
227
|
+
|
|
228
|
+
if let asyncResult = asyncResult {
|
|
229
|
+
XCTAssertTrue(asyncResult.contains("before await"))
|
|
230
|
+
XCTAssertTrue(asyncResult.contains("after call"))
|
|
231
|
+
// "after await" should drain as a microtask
|
|
232
|
+
XCTAssertTrue(asyncResult.contains("after await"), "Post-await code should drain as microtask")
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// MARK: - Test: Performance.now Polyfill
|
|
237
|
+
|
|
238
|
+
func testPerformanceNowPolyfill() {
|
|
239
|
+
// Register a simple performance.now
|
|
240
|
+
let startTime = CFAbsoluteTimeGetCurrent()
|
|
241
|
+
let performanceNow: @convention(block) () -> Double = {
|
|
242
|
+
return (CFAbsoluteTimeGetCurrent() - startTime) * 1000.0
|
|
243
|
+
}
|
|
244
|
+
context.evaluateScript("var performance = {};")
|
|
245
|
+
let perfObj = context.objectForKeyedSubscript("performance")!
|
|
246
|
+
perfObj.setObject(performanceNow, forKeyedSubscript: "now" as NSString)
|
|
247
|
+
|
|
248
|
+
let result = context.evaluateScript("performance.now()")
|
|
249
|
+
XCTAssertNotNil(result)
|
|
250
|
+
|
|
251
|
+
let time = result?.toDouble() ?? -1
|
|
252
|
+
XCTAssertGreaterThanOrEqual(time, 0, "performance.now() should return non-negative value")
|
|
253
|
+
XCTAssertLessThan(time, 1000, "performance.now() should return a reasonable value (< 1s)")
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// MARK: - Test: globalThis
|
|
257
|
+
|
|
258
|
+
func testGlobalThis() {
|
|
259
|
+
context.evaluateScript("var globalThis = this;")
|
|
260
|
+
|
|
261
|
+
let result = context.evaluateScript("globalThis === this")
|
|
262
|
+
XCTAssertTrue(result?.toBool() ?? false, "globalThis should equal the global object")
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// MARK: - Test: JSRuntime Singleton (Integration)
|
|
266
|
+
|
|
267
|
+
func testJSRuntimeInitialize() {
|
|
268
|
+
let expectation = self.expectation(description: "JSRuntime initializes")
|
|
269
|
+
|
|
270
|
+
let runtime = JSRuntime.shared
|
|
271
|
+
|
|
272
|
+
runtime.initialize {
|
|
273
|
+
XCTAssertTrue(runtime.isInitialized, "Runtime should be initialized")
|
|
274
|
+
expectation.fulfill()
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
waitForExpectations(timeout: 5.0)
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
func testJSRuntimeEvaluateScript() {
|
|
281
|
+
let expectation = self.expectation(description: "evaluateScript completes")
|
|
282
|
+
|
|
283
|
+
let runtime = JSRuntime.shared
|
|
284
|
+
|
|
285
|
+
runtime.initialize {
|
|
286
|
+
runtime.evaluateScript("1 + 1") { result in
|
|
287
|
+
XCTAssertEqual(result?.toInt32(), 2)
|
|
288
|
+
expectation.fulfill()
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
waitForExpectations(timeout: 5.0)
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
func testJSRuntimeCallFunction() {
|
|
296
|
+
let expectation = self.expectation(description: "callFunction completes")
|
|
297
|
+
|
|
298
|
+
let runtime = JSRuntime.shared
|
|
299
|
+
|
|
300
|
+
runtime.initialize {
|
|
301
|
+
runtime.evaluateScript("function multiply(a, b) { return a * b; }") { _ in
|
|
302
|
+
runtime.callFunction("multiply", withArguments: [6, 7]) { result in
|
|
303
|
+
XCTAssertEqual(result?.toInt32(), 42)
|
|
304
|
+
expectation.fulfill()
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
waitForExpectations(timeout: 5.0)
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// MARK: - Test: JSON Operation Parsing
|
|
313
|
+
|
|
314
|
+
func testOperationJSONParsing() {
|
|
315
|
+
// Test that our expected operation format can be parsed
|
|
316
|
+
let json = """
|
|
317
|
+
[
|
|
318
|
+
{"op": "create", "args": [1, "VView"]},
|
|
319
|
+
{"op": "createText", "args": [2, "Hello"]},
|
|
320
|
+
{"op": "appendChild", "args": [1, 2]},
|
|
321
|
+
{"op": "updateStyle", "args": [1, {"backgroundColor": "#ff0000", "padding": 16}]},
|
|
322
|
+
{"op": "setRootView", "args": [1]}
|
|
323
|
+
]
|
|
324
|
+
"""
|
|
325
|
+
|
|
326
|
+
let data = json.data(using: .utf8)!
|
|
327
|
+
let operations = try? JSONSerialization.jsonObject(with: data) as? [[String: Any]]
|
|
328
|
+
|
|
329
|
+
XCTAssertNotNil(operations)
|
|
330
|
+
XCTAssertEqual(operations?.count, 5)
|
|
331
|
+
|
|
332
|
+
// Verify first operation
|
|
333
|
+
XCTAssertEqual(operations?[0]["op"] as? String, "create")
|
|
334
|
+
if let args = operations?[0]["args"] as? [Any] {
|
|
335
|
+
XCTAssertEqual(args[0] as? Int, 1)
|
|
336
|
+
XCTAssertEqual(args[1] as? String, "VView")
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// Verify style operation has nested dictionary
|
|
340
|
+
if let args = operations?[3]["args"] as? [Any],
|
|
341
|
+
let styles = args[1] as? [String: Any] {
|
|
342
|
+
XCTAssertEqual(styles["backgroundColor"] as? String, "#ff0000")
|
|
343
|
+
XCTAssertEqual(styles["padding"] as? Int, 16)
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// MARK: - Helpers
|
|
348
|
+
|
|
349
|
+
private func registerConsolePolyfills() {
|
|
350
|
+
context.evaluateScript("var console = {};")
|
|
351
|
+
|
|
352
|
+
let log: @convention(block) (JSValue) -> Void = { _ in }
|
|
353
|
+
let warn: @convention(block) (JSValue) -> Void = { _ in }
|
|
354
|
+
let error: @convention(block) (JSValue) -> Void = { _ in }
|
|
355
|
+
|
|
356
|
+
let consoleObj = context.objectForKeyedSubscript("console")!
|
|
357
|
+
consoleObj.setObject(log, forKeyedSubscript: "log" as NSString)
|
|
358
|
+
consoleObj.setObject(warn, forKeyedSubscript: "warn" as NSString)
|
|
359
|
+
consoleObj.setObject(error, forKeyedSubscript: "error" as NSString)
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
#endif
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thelacanians/vue-native-cli",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.4",
|
|
4
4
|
"description": "CLI for creating and running Vue Native apps",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Vue Native Contributors",
|
|
@@ -20,8 +20,9 @@
|
|
|
20
20
|
".": "./dist/config.js",
|
|
21
21
|
"./cli": "./dist/cli.js"
|
|
22
22
|
},
|
|
23
|
-
"files": ["dist", "README.md"],
|
|
23
|
+
"files": ["dist", "README.md", "native"],
|
|
24
24
|
"scripts": {
|
|
25
|
+
"prebuild": "rm -rf native && cp -r ../../native native",
|
|
25
26
|
"build": "tsup",
|
|
26
27
|
"dev": "tsup --watch",
|
|
27
28
|
"test": "vitest run",
|