-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move Hermes setup in a dedicated ruby file (#34100)
Summary: Pull Request resolved: #34100 This Diff continue the effort of refactor and test the cocoapods script, moving hermes setup in a dedicated `hermes.rb` file and adding some tests on the logic of the hermes handling. ## Changelog [iOS][Changed] - move and test Hermes setup from react_native_pods script into a dedicated file Reviewed By: cortinico Differential Revision: D37522432 fbshipit-source-id: 91112476aac576a30110e5dcd4e46fa12241962a
- Loading branch information
1 parent
6c563a5
commit 468b86b
Showing
5 changed files
with
179 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
require "test/unit" | ||
require_relative "../hermes.rb" | ||
require_relative "./test_utils/podSpy.rb" | ||
require_relative "./test_utils/PodMock.rb" | ||
require_relative "./test_utils/Open3Mock.rb" | ||
|
||
class HermesTests < Test::Unit::TestCase | ||
|
||
:prefix | ||
|
||
def setup | ||
@prefix = "../.." | ||
end | ||
|
||
def teardown | ||
Open3.reset() | ||
Pod::Config.reset() | ||
Pod::UI.reset() | ||
podSpy_cleanUp() | ||
end | ||
|
||
def test_installHermesIfEnabled_whenHermesIsDisabled_doesNothing | ||
# Arrange | ||
|
||
# Act | ||
install_hermes_if_enabled(false, @prefix) | ||
|
||
# Assert | ||
assert_equal($podInvocationCount, 0) | ||
assert_equal($podInvocation, {}) | ||
assert_equal(Pod::UI.collected_infoes, []) | ||
assert_equal(Open3.collected_commands, []) | ||
assert_equal(Open3.collected_dirs, []) | ||
end | ||
|
||
def test_installHermesIfEnabled_whenHermesIsEnabledAndHermesScriptFails_abort | ||
# Arrange | ||
Pod::Config.instance.installation_root.set_installation_root("Pods/") | ||
Open3.set_returned_status(1) | ||
Open3.set_returned_text("This test\nshould fail") | ||
|
||
# Act | ||
assert_raises { | ||
install_hermes_if_enabled(true, @prefix) | ||
} | ||
|
||
# Assert | ||
assert_equal(Open3.collected_commands, ["node scripts/hermes/prepare-hermes-for-build"]) | ||
assert_equal(Open3.collected_dirs, ["Pods/../.."]) | ||
assert_equal(Pod::UI.collected_infoes, ["This test", "should fail"]) | ||
assert_equal($podInvocationCount, 0) | ||
assert_equal($podInvocation, {}) | ||
end | ||
|
||
def test_installHermesIfEnabled_whenHermesIsEnabledAndHermesScriptSucceeds_installsPods | ||
# Arrange | ||
Pod::Config.instance.installation_root.set_installation_root("Pods/") | ||
Open3.set_returned_status(0) | ||
Open3.set_returned_text("This is\nthe text\nreturned by\nprepare-hermes-for-build") | ||
|
||
# Act | ||
install_hermes_if_enabled(true, @prefix) | ||
|
||
# Assert | ||
assert_equal(Open3.collected_commands, ["node scripts/hermes/prepare-hermes-for-build"]) | ||
assert_equal(Open3.collected_dirs, ["Pods/../.."]) | ||
assert_equal(Pod::UI.collected_infoes, [ | ||
"This is", | ||
"the text", | ||
"returned by", | ||
"prepare-hermes-for-build", | ||
]) | ||
assert_equal($podInvocationCount, 3) | ||
assert_equal($podInvocation["React-hermes"][:path], "../../ReactCommon/hermes") | ||
assert_equal($podInvocation["libevent"][:version], "~> 2.1.12") | ||
assert_equal($podInvocation["hermes-engine"][:podspec], "../../sdks/hermes/hermes-engine.podspec") | ||
end | ||
|
||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
class Open3 | ||
@@collected_commands = [] | ||
@@collected_dirs = [] | ||
|
||
@@returned_text = "" | ||
@@returned_status = 0 | ||
|
||
def self.capture2e(command, chdir: ".") | ||
@@collected_commands.push(command) | ||
@@collected_dirs.push(chdir) | ||
|
||
return [*@@returned_text, @@returned_status] | ||
end | ||
|
||
def self.collected_commands | ||
return @@collected_commands | ||
end | ||
|
||
def self.collected_dirs | ||
return @@collected_dirs | ||
end | ||
|
||
def self.set_returned_text(text) | ||
@@returned_text = text | ||
end | ||
|
||
def self.set_returned_status(status) | ||
@@returned_status = status | ||
end | ||
|
||
def self.reset() | ||
@@collected_commands = [] | ||
@@collected_dirs = [] | ||
|
||
@@returned_text = "" | ||
@@returned_status = 0 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
def install_hermes_if_enabled(hermes_enabled, react_native_path) | ||
unless hermes_enabled | ||
return | ||
end | ||
|
||
prepare_hermes = 'node scripts/hermes/prepare-hermes-for-build' | ||
react_native_dir = Pod::Config.instance.installation_root.join(react_native_path) | ||
prep_output, prep_status = Open3.capture2e(prepare_hermes, :chdir => react_native_dir) | ||
prep_output.split("\n").each { |line| Pod::UI.info line } | ||
abort unless prep_status == 0 | ||
|
||
pod 'React-hermes', :path => "#{react_native_path}/ReactCommon/hermes" | ||
pod 'libevent', '~> 2.1.12' | ||
pod 'hermes-engine', :podspec => "#{react_native_path}/sdks/hermes/hermes-engine.podspec" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters