|
| 1 | +# Copyright (c) Meta Platforms, Inc. and affiliates. |
| 2 | +# |
| 3 | +# This source code is licensed under the MIT license found in the |
| 4 | +# LICENSE file in the root directory of this source tree. |
| 5 | + |
| 6 | +require "test/unit" |
| 7 | +require_relative "../jsengine.rb" |
| 8 | +require_relative "./test_utils/podSpy.rb" |
| 9 | +require_relative "./test_utils/PodMock.rb" |
| 10 | +require_relative "./test_utils/Open3Mock.rb" |
| 11 | + |
| 12 | +class JSEngineTests < Test::Unit::TestCase |
| 13 | + |
| 14 | + :react_native_path |
| 15 | + |
| 16 | + def setup |
| 17 | + @react_native_path = "../.." |
| 18 | + podSpy_cleanUp() |
| 19 | + end |
| 20 | + |
| 21 | + def teardown |
| 22 | + Open3.reset() |
| 23 | + Pod::Config.reset() |
| 24 | + Pod::UI.reset() |
| 25 | + podSpy_cleanUp() |
| 26 | + ENV['USE_HERMES'] = '1' |
| 27 | + end |
| 28 | + |
| 29 | + # =============== # |
| 30 | + # TEST - setupJsc # |
| 31 | + # =============== # |
| 32 | + def test_setupJsc_installsPods |
| 33 | + # Arrange |
| 34 | + fabric_enabled = false |
| 35 | + |
| 36 | + # Act |
| 37 | + setup_jsc!(:react_native_path => @react_native_path, :fabric_enabled => fabric_enabled) |
| 38 | + |
| 39 | + # Assert |
| 40 | + assert_equal($podInvocationCount, 2) |
| 41 | + assert_equal($podInvocation["React-jsi"][:path], "../../ReactCommon/jsi") |
| 42 | + assert_equal($podInvocation["React-jsc"][:path], "../../ReactCommon/jsi") |
| 43 | + end |
| 44 | + |
| 45 | + def test_setupJsc_installsPods_installsFabricSubspecWhenFabricEnabled |
| 46 | + # Arrange |
| 47 | + fabric_enabled = true |
| 48 | + |
| 49 | + # Act |
| 50 | + setup_jsc!(:react_native_path => @react_native_path, :fabric_enabled => fabric_enabled) |
| 51 | + |
| 52 | + # Assert |
| 53 | + assert_equal($podInvocationCount, 3) |
| 54 | + assert_equal($podInvocation["React-jsi"][:path], "../../ReactCommon/jsi") |
| 55 | + assert_equal($podInvocation["React-jsc"][:path], "../../ReactCommon/jsi") |
| 56 | + assert_equal($podInvocation["React-jsc/Fabric"][:path], "../../ReactCommon/jsi") |
| 57 | + end |
| 58 | + |
| 59 | + # ================== # |
| 60 | + # TEST - setupHermes # |
| 61 | + # ================== # |
| 62 | + def test_setupHermes_whenHermesScriptFails_abort |
| 63 | + # Arrange |
| 64 | + fabric_enabled = false |
| 65 | + Pod::Config.instance.installation_root.set_installation_root("Pods/") |
| 66 | + Open3.set_returned_status(1) |
| 67 | + Open3.set_returned_text("This test\nshould fail") |
| 68 | + |
| 69 | + # Act |
| 70 | + assert_raises { |
| 71 | + setup_hermes!(:react_native_path => @react_native_path, :fabric_enabled => fabric_enabled) |
| 72 | + } |
| 73 | + |
| 74 | + # Assert |
| 75 | + assert_equal(Open3.collected_commands, ["node scripts/hermes/prepare-hermes-for-build"]) |
| 76 | + assert_equal(Open3.collected_dirs, ["Pods/../.."]) |
| 77 | + assert_equal(Pod::UI.collected_infoes, ["This test", "should fail"]) |
| 78 | + assert_equal($podInvocationCount, 0) |
| 79 | + assert_equal($podInvocation, {}) |
| 80 | + end |
| 81 | + |
| 82 | + def test_setupHermes_whenHermesScriptSucceeds_installsPods |
| 83 | + # Arrange |
| 84 | + fabric_enabled = false |
| 85 | + Pod::Config.instance.installation_root.set_installation_root("Pods/") |
| 86 | + Open3.set_returned_status(0) |
| 87 | + Open3.set_returned_text("This is\nthe text\nreturned by\nprepare-hermes-for-build") |
| 88 | + |
| 89 | + # Act |
| 90 | + setup_hermes!(:react_native_path => @react_native_path, :fabric_enabled => fabric_enabled) |
| 91 | + |
| 92 | + # Assert |
| 93 | + assert_equal(Open3.collected_commands, ["node scripts/hermes/prepare-hermes-for-build"]) |
| 94 | + assert_equal(Open3.collected_dirs, ["Pods/../.."]) |
| 95 | + assert_equal(Pod::UI.collected_infoes, [ |
| 96 | + "This is", |
| 97 | + "the text", |
| 98 | + "returned by", |
| 99 | + "prepare-hermes-for-build", |
| 100 | + ]) |
| 101 | + assert_equal($podInvocationCount, 5) |
| 102 | + assert_equal($podInvocation["React-jsi"][:path], "../../ReactCommon/jsi") |
| 103 | + assert_equal($podInvocation["React-hermes"][:path], "../../ReactCommon/hermes") |
| 104 | + assert_equal($podInvocation["libevent"][:version], "~> 2.1.12") |
| 105 | + assert_equal($podInvocation["hermes-engine"][:podspec], "../../sdks/hermes/hermes-engine.podspec") |
| 106 | + end |
| 107 | + |
| 108 | + def test_setupHermes_installsPods_installsFabricSubspecWhenFabricEnabled |
| 109 | + # Arrange |
| 110 | + fabric_enabled = true |
| 111 | + |
| 112 | + # Act |
| 113 | + setup_hermes!(:react_native_path => @react_native_path, :fabric_enabled => fabric_enabled) |
| 114 | + |
| 115 | + # Assert |
| 116 | + assert_equal($podInvocationCount, 6) |
| 117 | + assert_equal($podInvocation["React-jsi"][:path], "../../ReactCommon/jsi") |
| 118 | + assert_equal($podInvocation["React-jsc"][:path], "../../ReactCommon/jsi") |
| 119 | + assert_equal($podInvocation["React-jsc/Fabric"][:path], "../../ReactCommon/jsi") |
| 120 | + assert_equal($podInvocation["hermes-engine"][:podspec], "../../sdks/hermes/hermes-engine.podspec") |
| 121 | + assert_equal($podInvocation["React-hermes"][:path], "../../ReactCommon/hermes") |
| 122 | + assert_equal($podInvocation["libevent"][:version], "~> 2.1.12") |
| 123 | + end |
| 124 | +end |
0 commit comments