Open History to see the last commit
1import { describe, expect, it } from "vitest";
2import withIosSceneLifecycle from "./withIosSceneLifecycle.cjs";
3
4const appDelegate = `class AppDelegate: ExpoAppDelegate {
5 var window: UIWindow?
6 func application() {
7 window = UIWindow(frame: UIScreen.main.bounds)
8 factory.startReactNative(
9 withModuleName: "main",
10 in: window,
11 launchOptions: launchOptions)
12 }
13}`;
14
15async function transform(contents) {
16 const config = withIosSceneLifecycle({ name: "Test", slug: "test" });
17 const result = await config.mods.ios.appDelegate({
18 ...config,
19 modRequest: { platform: "ios", modName: "appDelegate", introspect: false },
20 modResults: { language: "swift", contents },
21 });
22 return result.modResults.contents;
23}
24
25describe("iOS scene lifecycle generation", () => {
26 it("creates the window in the scene before starting React Native and retains launch options", async () => {
27 const result = await transform(appDelegate);
28 const [startup, scene] = result.split("class SceneDelegate:");
29 expect(startup).not.toContain("UIWindow(frame:");
30 expect(startup).not.toContain("startReactNative(");
31 expect(startup).toContain("sceneLaunchOptions = launchOptions");
32 expect(scene.indexOf("UIWindow(windowScene: windowScene)")).toBeLessThan(
33 scene.indexOf("startReactNative("),
34 );
35 expect(scene).toContain("launchOptions: appDelegate.sceneLaunchOptions)");
36 expect(scene).toContain("appDelegate.sceneLaunchOptions = nil");
37 });
38
39 it("does not duplicate startup or scene code on subsequent prebuilds", async () => {
40 const generated = await transform(appDelegate);
41 expect(await transform(generated)).toBe(generated);
42 });
43
44 it("updates the previously generated scene delegate", async () => {
45 const generated = await transform(appDelegate);
46 const oldScene = generated
47 .slice(generated.indexOf("class SceneDelegate:"))
48 .replace("launchOptions: appDelegate.sceneLaunchOptions)", "launchOptions: nil)")
49 .replace(" appDelegate.sceneLaunchOptions = nil\n", "");
50 expect(await transform(`${appDelegate}\n\n${oldScene}`)).toBe(generated);
51 });
52
53 it("fails visibly when the Expo startup template changes", async () => {
54 await expect(transform("class AppDelegate: ExpoAppDelegate {}")).rejects.toThrow(
55 "Could not move React Native startup",
56 );
57 });
58});