Skip to content

Commit

Permalink
Extract Codegen code from the react_native_pods to its own file (#34176)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #34176

It extracts the code related to the codegen from the main `react_native_pods` script to a dedicated file, adding also tests.

## Changelog

[iOS][Changed] - Move codegen in separate files

Reviewed By: cortinico

Differential Revision: D37755818

fbshipit-source-id: 99760d1def26ddbf065fdd234e0d183c2795513c
  • Loading branch information
Riccardo Cipolleschi authored and facebook-github-bot committed Jul 19, 2022
1 parent 089c9a5 commit 7d069b2
Show file tree
Hide file tree
Showing 12 changed files with 1,025 additions and 236 deletions.
59 changes: 59 additions & 0 deletions scripts/cocoapods/__tests__/codegen-test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
require_relative "./test_utils/FileMock.rb"
require_relative "./test_utils/DirMock.rb"
require_relative "./test_utils/systemUtils.rb"
require_relative "./test_utils/CodegenUtilsMock.rb"

class CodegenTests < Test::Unit::TestCase
:third_party_provider_header
Expand Down Expand Up @@ -182,4 +183,62 @@ def testCheckAndGenerateEmptyThirdPartyProvider_whenBothMissing_buildCodegen()
]
})
end

# ================= #
# Test - RunCodegen #
# ================= #
def testRunCodegen_whenNewArchEnabled_runsCodegen
# Arrange
app_path = "~/app"
config_file = ""
codegen_utils_mock = CodegenUtilsMock.new()

# Act
run_codegen!(app_path, config_file, :new_arch_enabled => true, :codegen_utils => codegen_utils_mock)

# Assert
assert_equal(codegen_utils_mock.use_react_native_codegen_discovery_params, [{
:app_path=>"~/app",
:codegen_disabled=>false,
:codegen_output_dir=>"build/generated/ios",
:config_file_dir=>"",
:fabric_enabled=>false,
:folly_version=>"2021.07.22.00",
:react_native_path=>"../node_modules/react-native"
}])
assert_equal(codegen_utils_mock.get_react_codegen_spec_params, [])
assert_equal(codegen_utils_mock.generate_react_codegen_spec_params, [])
end

def testRunCodegen_whenNewArchDisabled_runsCodegen
# Arrange
app_path = "~/app"
config_file = ""
package_json_file = "~/app/package.json"
codegen_specs = { "name" => "React-Codegen" }
codegen_utils_mock = CodegenUtilsMock.new(:react_codegen_spec => codegen_specs)

# Act
run_codegen!(
app_path,
config_file,
:new_arch_enabled => false,
:fabric_enabled => true,
:package_json_file => package_json_file,
:codegen_utils => codegen_utils_mock)

# Assert
assert_equal(codegen_utils_mock.use_react_native_codegen_discovery_params, [])
assert_equal(codegen_utils_mock.get_react_codegen_spec_params, [{
:fabric_enabled => true,
:folly_version=>"2021.07.22.00",
:package_json_file => "~/app/package.json",
:script_phases => nil
}])
assert_equal(codegen_utils_mock.generate_react_codegen_spec_params, [{
:codegen_output_dir=>"build/generated/ios",
:react_codegen_spec=>{"name"=>"React-Codegen"}
}])

end
end
Loading

0 comments on commit 7d069b2

Please sign in to comment.