Skip to content

Commit 7782700

Browse files
Migrate React Native Jest setup to Expo
Assisted-By: devx/2d0344dc-43dd-4535-baf2-409ff9e93de5
1 parent 0efe5f5 commit 7782700

24 files changed

Lines changed: 944 additions & 1118 deletions

dev.yml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ up:
2727
name: Run Checkout Kit workspace setup
2828
met?: ./scripts/setup_dev_workspace --check --skip-optional-prompts
2929
meet: ./scripts/setup_dev_workspace --skip-optional-prompts
30+
- custom:
31+
name: Prebuild React Native sample native projects
32+
met?: "false"
33+
meet: cd platforms/react-native && pnpm run prebuild -- all -- --clean
3034

3135
open:
3236
"GitHub": "https://github.com/Shopify/checkout-kit"
@@ -441,10 +445,10 @@ commands:
441445
fi
442446
echo "Cleaned root, module and sample workspaces"
443447
444-
server:
448+
start:
445449
desc: Start Metro development server
446-
aliases: [s]
447-
run: cd platforms/react-native && pnpm sample start --reset-cache
450+
aliases: [s, server]
451+
run: cd platforms/react-native && pnpm sample start "$@"
448452

449453
ios:
450454
desc: Run the iOS sample app in the simulator.
@@ -472,17 +476,19 @@ commands:
472476
desc: Prebuild generated native sample projects.
473477
long_desc: |
474478
Runs Expo prebuild for the React Native sample and prepares platform-specific native dependencies.
479+
Existing native folders are preserved unless Expo's --clean arg is passed through.
475480
476-
dev rn prebuild Prebuild iOS and Android
477-
dev rn prebuild ios Prebuild iOS and install CocoaPods
478-
dev rn prebuild android Prebuild Android
479-
dev rn prebuild ios --local Prebuild iOS against in-repo Swift SDK sources
480-
dev rn prebuild android --local Prebuild Android against in-repo Android SDK artifacts
481+
dev rn prebuild Prebuild iOS and Android
482+
dev rn prebuild ios Prebuild iOS and install CocoaPods
483+
dev rn prebuild android Prebuild Android
484+
dev rn prebuild all -- --clean Regenerate iOS and Android native projects
485+
dev rn prebuild ios --local Prebuild iOS against in-repo Swift SDK sources
486+
dev rn prebuild android --local Prebuild Android against in-repo Android SDK artifacts
481487
482488
--local
483489
Use in-repo native SDKs where supported.
484490
syntax:
485-
optional: "[ios|android|all] [--local]"
491+
optional: "[ios|android|all] [--local] [-- <expo prebuild args>]"
486492
run: cd platforms/react-native && pnpm run prebuild -- "$@"
487493

488494
open:

platforms/react-native/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,10 @@ Here's an example of how to get started with Apollo:
223223

224224
```tsx
225225
import {ApolloClient, gql, ApolloProvider} from '@apollo/client';
226-
import {API_VERSION, STOREFRONT_DOMAIN, STOREFRONT_ACCESS_TOKEN} from '@env';
226+
227+
const API_VERSION = '2026-04';
228+
const STOREFRONT_DOMAIN = 'your-store.myshopify.com';
229+
const STOREFRONT_ACCESS_TOKEN = 'your-public-storefront-access-token';
227230

228231
// Create a new instance of the ApolloClient
229232
const client = new ApolloClient({

platforms/react-native/__mocks__/react-native.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ module.exports = {
106106
requireNativeComponent,
107107
codegenNativeComponent,
108108
TurboModuleRegistry: {
109+
get: jest.fn((name: string) => {
110+
if (name === 'ShopifyCheckoutKit') {
111+
return ShopifyCheckoutKit;
112+
}
113+
return null;
114+
}),
109115
getEnforcing: jest.fn((name: string) => {
110116
if (name === 'ShopifyCheckoutKit') {
111117
return ShopifyCheckoutKit;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = {
2-
presets: ['module:@react-native/babel-preset'],
2+
presets: ['babel-preset-expo'],
33
};
Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
module.exports = {
2-
preset: '@react-native/jest-preset',
2+
preset: 'jest-expo',
33
modulePathIgnorePatterns: ['modules/@shopify/checkout-kit-react-native/lib'],
44
modulePaths: ['<rootDir>/node_modules', '<rootDir>/sample/node_modules'],
55
moduleNameMapper: {
66
'^react$': '<rootDir>/node_modules/react',
7-
'^react-test-renderer$': '<rootDir>/node_modules/react-test-renderer',
87
'^react-native$': '<rootDir>/__mocks__/react-native.ts',
98
},
109
setupFiles: ['<rootDir>/jest.setup.ts'],
1110
transform: {
1211
'\\.[jt]sx?$': 'babel-jest',
1312
},
14-
globals: {
15-
'ts-jest': {
16-
tsConfig: {
17-
importHelpers: true,
18-
},
19-
},
20-
},
2113
};

platforms/react-native/jest.setup.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ declare global {
22
var __fbBatchedBridgeConfig: unknown;
33
}
44

5-
jest.mock('react-native');
6-
75
const platformConstants = {
86
forceTouchAvailable: false,
97
interfaceIdiom: 'phone',

platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/AcceleratedCheckoutButtons.swift

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,6 @@ import UIKit
77

88
// MARK: - AcceleratedCheckout Components
99

10-
@available(iOS 16.0, *)
11-
class AcceleratedCheckoutConfiguration {
12-
static let shared = AcceleratedCheckoutConfiguration()
13-
var configuration: ShopifyAcceleratedCheckouts.Configuration?
14-
var applePayConfiguration: ShopifyAcceleratedCheckouts.ApplePayConfiguration?
15-
16-
var available: Bool {
17-
if #available(iOS 16.0, *) {
18-
return configuration != nil
19-
} else {
20-
return false
21-
}
22-
}
23-
24-
var applePayAvailable: Bool {
25-
if #available(iOS 16.0, *) {
26-
return applePayConfiguration != nil
27-
} else {
28-
return false
29-
}
30-
}
31-
}
32-
3310
@objc(RCTAcceleratedCheckoutButtonsManager)
3411
class RCTAcceleratedCheckoutButtonsManager: RCTViewManager {
3512
/// Internal property used in tests to simulate legacy devices
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import Foundation
2+
import ShopifyCheckoutKit
3+
4+
@available(iOS 16.0, *)
5+
class AcceleratedCheckoutConfiguration {
6+
static let shared = AcceleratedCheckoutConfiguration()
7+
var configuration: ShopifyAcceleratedCheckouts.Configuration?
8+
var applePayConfiguration: ShopifyAcceleratedCheckouts.ApplePayConfiguration?
9+
10+
var available: Bool {
11+
if #available(iOS 16.0, *) {
12+
return configuration != nil
13+
} else {
14+
return false
15+
}
16+
}
17+
18+
var applePayAvailable: Bool {
19+
if #available(iOS 16.0, *) {
20+
return applePayConfiguration != nil
21+
} else {
22+
return false
23+
}
24+
}
25+
}

platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/ShopifyCheckoutKit.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import Foundation
22
import PassKit
3-
import React
3+
#if canImport(React)
4+
import React
5+
#endif
46
import ShopifyCheckoutKit
57
import SwiftUI
68
import UIKit
@@ -258,7 +260,7 @@ class RCTShopifyCheckoutKit: NSObject {
258260
@available(iOS 16.0, *)
259261
private func contactFieldsToRequiredContactFields(_ contactFields: [String]) throws -> [ShopifyAcceleratedCheckouts.RequiredContactFields] {
260262
return try contactFields.compactMap {
261-
guard let field = ShopifyAcceleratedCheckouts.RequiredContactFields(rawValue: $0), field != nil else {
263+
guard let field = ShopifyAcceleratedCheckouts.RequiredContactFields(rawValue: $0) else {
262264
let message = "Unknown contactField option: \(String(describing: $0))"
263265
print("[ShopifyCheckoutKit] \(message)")
264266
throw NSError(domain: "ShopifyCheckoutKit", code: 1, userInfo: ["message": message])
@@ -325,7 +327,9 @@ extension RCTShopifyCheckoutKit: CheckoutDelegate {
325327

326328
extension RCTShopifyCheckoutKit {
327329
private func emitDispatchEvent(_ json: String) {
328-
perform(NSSelectorFromString("emitOnDispatchFromSwift:"), with: json)
330+
let selector = NSSelectorFromString("emitOnDispatchFromSwift:")
331+
guard responds(to: selector) else { return }
332+
perform(selector, with: json)
329333
}
330334

331335
/// Builds a `{ "type": ..., "payload": ... }` envelope and forwards

platforms/react-native/modules/@shopify/checkout-kit-react-native/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@
7070
"@shopify/checkout-kit-protocol": "workspace:*",
7171
"@microsoft/api-extractor": "^7.58.7",
7272
"react-native-builder-bob": "^0.23.2",
73-
"typescript": "^5.9.2",
74-
"react": "19.2.3",
75-
"react-native": "0.85.3"
73+
"typescript": "^5.9.2"
7674
},
7775
"codegenConfig": {
7876
"name": "RNShopifyCheckoutKitSpec",

0 commit comments

Comments
 (0)