Skip to content

Commit 0445588

Browse files
committed
link test update for iOS
1 parent 33c789f commit 0445588

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import UIKit
2+
import React
3+
import React_RCTAppDelegate
4+
import ReactAppDependencyProvider
5+
6+
@main
7+
class AppDelegate: UIResponder, UIApplicationDelegate {
8+
var window: UIWindow?
9+
10+
var reactNativeDelegate: ReactNativeDelegate?
11+
var reactNativeFactory: RCTReactNativeFactory?
12+
13+
func application(
14+
_ application: UIApplication,
15+
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
16+
) -> Bool {
17+
let delegate = ReactNativeDelegate()
18+
let factory = RCTReactNativeFactory(delegate: delegate)
19+
delegate.dependencyProvider = RCTAppDependencyProvider()
20+
21+
reactNativeDelegate = delegate
22+
reactNativeFactory = factory
23+
24+
window = UIWindow(frame: UIScreen.main.bounds)
25+
26+
factory.startReactNative(
27+
withModuleName: "RN79",
28+
in: window,
29+
launchOptions: launchOptions
30+
)
31+
32+
return true
33+
}
34+
}
35+
36+
class ReactNativeDelegate: RCTDefaultReactNativeFactoryDelegate {
37+
override func sourceURL(for bridge: RCTBridge) -> URL? {
38+
self.bundleURL()
39+
}
40+
41+
override func bundleURL() -> URL? {
42+
#if DEBUG
43+
RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index")
44+
#else
45+
Bundle.main.url(forResource: "main", withExtension: "jsbundle")
46+
#endif
47+
}
48+
}

autolink/postlink/__helpers__/fixtures.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,6 @@ module.exports = {
2121
prepareFixtureDuplicate,
2222
prepareFixtureDuplicate77: ({ userFixtureFileName, patchedFixtureFileName }) =>
2323
prepareFixtureDuplicate({ rnVersion: '77', userFixtureFileName, patchedFixtureFileName }),
24+
prepareFixtureDuplicate79: ({ userFixtureFileName, patchedFixtureFileName }) =>
25+
prepareFixtureDuplicate({ rnVersion: '79', userFixtureFileName, patchedFixtureFileName }),
2426
};

autolink/postlink/appDelegateLinker.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,24 @@ describe('appDelegateLinker', () => {
4242
const appDelegateContent = fs.readFileSync(linker.appDelegatePath, 'utf8');
4343
expect(appDelegateContent).toMatchSnapshot();
4444
});
45+
46+
it('should work with Swift bridgeless RN 0.79+', () => {
47+
jest.mock('./path', () => {
48+
const tmpAppDelegatePath = mockHelpers.prepareFixtureDuplicate79({
49+
userFixtureFileName: 'AppDelegate.swift.template',
50+
patchedFixtureFileName: 'rnn-tests_AppDelegate79.swift',
51+
});
52+
53+
return {
54+
appDelegate: tmpAppDelegatePath,
55+
};
56+
});
57+
58+
const AppDelegateLinker = require('./appDelegateLinker');
59+
const linker = new AppDelegateLinker();
60+
linker.link();
61+
62+
const appDelegateContent = fs.readFileSync(linker.appDelegatePath, 'utf8');
63+
expect(appDelegateContent).toMatchSnapshot();
64+
});
4565
});

0 commit comments

Comments
 (0)