@@ -20,8 +20,6 @@ class CodegenTests < Test::Unit::TestCase
20
20
:tmp_schema_list_file
21
21
22
22
def setup
23
- File . enable_testing_mode!
24
- Dir . enable_testing_mode!
25
23
Pod ::Config . reset ( )
26
24
27
25
@prefix = "../.."
@@ -38,8 +36,8 @@ def teardown
38
36
Pod ::UI . reset ( )
39
37
Pod ::Executable . reset ( )
40
38
Pathname . reset ( )
41
- File . reset ( )
42
- Dir . reset ( )
39
+ FileMock . reset ( )
40
+ DirMock . reset ( )
43
41
end
44
42
45
43
# ============================================== #
@@ -48,90 +46,90 @@ def teardown
48
46
def testCheckAndGenerateEmptyThirdPartyProvider_whenFileAlreadyExists_doNothing ( )
49
47
50
48
# Arrange
51
- File . mocked_existing_files ( [
49
+ FileMock . mocked_existing_files ( [
52
50
@base_path + "/build/" + @third_party_provider_header ,
53
51
@base_path + "/build/" + @third_party_provider_implementation ,
54
52
] )
55
53
56
54
# Act
57
- checkAndGenerateEmptyThirdPartyProvider! ( @prefix , false , 'build' )
55
+ checkAndGenerateEmptyThirdPartyProvider! ( @prefix , false , 'build' , dir_manager : DirMock , file_manager : FileMock )
58
56
59
57
# Assert
60
58
assert_equal ( Pathname . pwd_invocation_count , 1 )
61
59
assert_equal ( Pod ::Config . instance . installation_root . relative_path_from_invocation_count , 1 )
62
- assert_equal ( File . exist_invocation_params , [
60
+ assert_equal ( FileMock . exist_invocation_params , [
63
61
@base_path + "/build/" + @third_party_provider_header ,
64
62
@base_path + "/build/" + @third_party_provider_implementation ,
65
63
] )
66
- assert_equal ( Dir . exist_invocation_params , [ ] )
64
+ assert_equal ( DirMock . exist_invocation_params , [ ] )
67
65
assert_equal ( Pod ::UI . collected_messages , [ ] )
68
66
assert_equal ( $collected_commands, [ ] )
69
- assert_equal ( File . open_files . length , 0 )
67
+ assert_equal ( FileMock . open_files . length , 0 )
70
68
assert_equal ( Pod ::Executable . executed_commands . length , 0 )
71
69
end
72
70
73
71
def testCheckAndGenerateEmptyThirdPartyProvider_whenHeaderMissingAndCodegenMissing_raiseError ( )
74
72
75
73
# Arrange
76
- File . mocked_existing_files ( [
74
+ FileMock . mocked_existing_files ( [
77
75
@base_path + "/build/" + @third_party_provider_implementation ,
78
76
] )
79
77
80
78
# Act
81
79
assert_raise {
82
- checkAndGenerateEmptyThirdPartyProvider! ( @prefix , false , 'build' )
80
+ checkAndGenerateEmptyThirdPartyProvider! ( @prefix , false , 'build' , dir_manager : DirMock , file_manager : FileMock )
83
81
}
84
82
85
83
# Assert
86
84
assert_equal ( Pathname . pwd_invocation_count , 1 )
87
85
assert_equal ( Pod ::Config . instance . installation_root . relative_path_from_invocation_count , 1 )
88
- assert_equal ( File . exist_invocation_params , [
86
+ assert_equal ( FileMock . exist_invocation_params , [
89
87
@base_path + "/build/" + @third_party_provider_header
90
88
] )
91
- assert_equal ( Dir . exist_invocation_params , [
89
+ assert_equal ( DirMock . exist_invocation_params , [
92
90
@base_path + "/" + @prefix + "/packages/react-native-codegen" ,
93
91
@base_path + "/" + @prefix + "/../@react-native/codegen" ,
94
92
] )
95
93
assert_equal ( Pod ::UI . collected_messages , [ ] )
96
94
assert_equal ( $collected_commands, [ ] )
97
- assert_equal ( File . open_files . length , 0 )
95
+ assert_equal ( FileMock . open_files . length , 0 )
98
96
assert_equal ( Pod ::Executable . executed_commands . length , 0 )
99
97
end
100
98
101
99
def testCheckAndGenerateEmptyThirdPartyProvider_whenImplementationMissingAndCodegenrepoExists_dontBuildCodegen ( )
102
100
103
101
# Arrange
104
- File . mocked_existing_files ( [
102
+ FileMock . mocked_existing_files ( [
105
103
@base_path + "/build/" + @third_party_provider_header ,
106
104
@base_path + "/build/tmpSchemaList.txt"
107
105
] )
108
106
109
- Dir . mocked_existing_dirs ( [
107
+ DirMock . mocked_existing_dirs ( [
110
108
@base_path + "/" + @prefix + "/packages/react-native-codegen" ,
111
109
@base_path + "/" + @prefix + "/packages/react-native-codegen/lib"
112
110
] )
113
111
114
112
# Act
115
- checkAndGenerateEmptyThirdPartyProvider! ( @prefix , false , 'build' )
113
+ checkAndGenerateEmptyThirdPartyProvider! ( @prefix , false , 'build' , dir_manager : DirMock , file_manager : FileMock )
116
114
117
115
# Assert
118
116
assert_equal ( Pathname . pwd_invocation_count , 1 )
119
117
assert_equal ( Pod ::Config . instance . installation_root . relative_path_from_invocation_count , 1 )
120
- assert_equal ( File . exist_invocation_params , [
118
+ assert_equal ( FileMock . exist_invocation_params , [
121
119
@base_path + "/build/" + @third_party_provider_header ,
122
120
@base_path + "/build/" + @third_party_provider_implementation ,
123
121
@base_path + "/build/tmpSchemaList.txt" ,
124
122
] )
125
- assert_equal ( Dir . exist_invocation_params , [
123
+ assert_equal ( DirMock . exist_invocation_params , [
126
124
@base_path + "/" + @prefix + "/packages/react-native-codegen" ,
127
125
@base_path + "/" + @prefix + "/packages/react-native-codegen/lib" ,
128
126
] )
129
127
assert_equal ( Pod ::UI . collected_messages , [ "[Codegen] generating an empty RCTThirdPartyFabricComponentsProvider" ] )
130
128
assert_equal ( $collected_commands, [ ] )
131
- assert_equal ( File . open_invocation_count , 1 )
132
- assert_equal ( File . open_files_with_mode [ @base_path + "/build/tmpSchemaList.txt" ] , 'w' )
133
- assert_equal ( File . open_files [ 0 ] . collected_write , [ "[]" ] )
134
- assert_equal ( File . open_files [ 0 ] . fsync_invocation_count , 1 )
129
+ assert_equal ( FileMock . open_invocation_count , 1 )
130
+ assert_equal ( FileMock . open_files_with_mode [ @base_path + "/build/tmpSchemaList.txt" ] , 'w' )
131
+ assert_equal ( FileMock . open_files [ 0 ] . collected_write , [ "[]" ] )
132
+ assert_equal ( FileMock . open_files [ 0 ] . fsync_invocation_count , 1 )
135
133
assert_equal ( Pod ::Executable . executed_commands [ 0 ] , {
136
134
"command" => "node" ,
137
135
"arguments" => [
@@ -141,27 +139,27 @@ def testCheckAndGenerateEmptyThirdPartyProvider_whenImplementationMissingAndCode
141
139
"--outputDir" , @base_path + "/build"
142
140
]
143
141
} )
144
- assert_equal ( File . delete_invocation_count , 1 )
145
- assert_equal ( File . deleted_files , [ @base_path + "/build/tmpSchemaList.txt" ] )
142
+ assert_equal ( FileMock . delete_invocation_count , 1 )
143
+ assert_equal ( FileMock . deleted_files , [ @base_path + "/build/tmpSchemaList.txt" ] )
146
144
end
147
145
148
146
def testCheckAndGenerateEmptyThirdPartyProvider_whenBothMissing_buildCodegen ( )
149
147
# Arrange
150
148
codegen_cli_path = @base_path + "/" + @prefix + "/../@react-native/codegen"
151
- Dir . mocked_existing_dirs ( [
149
+ DirMock . mocked_existing_dirs ( [
152
150
codegen_cli_path ,
153
151
] )
154
152
# Act
155
- checkAndGenerateEmptyThirdPartyProvider! ( @prefix , false , 'build' )
153
+ checkAndGenerateEmptyThirdPartyProvider! ( @prefix , false , 'build' , dir_manager : DirMock , file_manager : FileMock )
156
154
157
155
# Assert
158
156
assert_equal ( Pathname . pwd_invocation_count , 1 )
159
157
assert_equal ( Pod ::Config . instance . installation_root . relative_path_from_invocation_count , 1 )
160
- assert_equal ( File . exist_invocation_params , [
158
+ assert_equal ( FileMock . exist_invocation_params , [
161
159
@base_path + "/build/" + @third_party_provider_header ,
162
160
@base_path + "/build/" + @tmp_schema_list_file
163
161
] )
164
- assert_equal ( Dir . exist_invocation_params , [
162
+ assert_equal ( DirMock . exist_invocation_params , [
165
163
@base_path + "/" + @prefix + "/packages/react-native-codegen" ,
166
164
codegen_cli_path ,
167
165
codegen_cli_path + "/lib" ,
@@ -171,8 +169,8 @@ def testCheckAndGenerateEmptyThirdPartyProvider_whenBothMissing_buildCodegen()
171
169
"[Codegen] generating an empty RCTThirdPartyFabricComponentsProvider"
172
170
] )
173
171
assert_equal ( $collected_commands, [ "~/app/ios/../../../@react-native/codegen/scripts/oss/build.sh" ] )
174
- assert_equal ( File . open_files [ 0 ] . collected_write , [ "[]" ] )
175
- assert_equal ( File . open_files [ 0 ] . fsync_invocation_count , 1 )
172
+ assert_equal ( FileMock . open_files [ 0 ] . collected_write , [ "[]" ] )
173
+ assert_equal ( FileMock . open_files [ 0 ] . fsync_invocation_count , 1 )
176
174
assert_equal ( Pod ::Executable . executed_commands [ 0 ] , {
177
175
"command" => "node" ,
178
176
"arguments" => [
0 commit comments