@@ -158,3 +158,89 @@ diff_test(
158
158
file1 = "actual3" ,
159
159
file2 = "expected_ast.json" ,
160
160
)
161
+
162
+ ################################################
163
+ # Tests and setup for the toolchain changes
164
+
165
+ # Create file for use in test cases later to get the version of node that is run
166
+ write_file (
167
+ name = "version" ,
168
+ out = "version.js" ,
169
+ content = ["require('fs').writeFileSync(process.argv[2], process.version)" ],
170
+ )
171
+
172
+ # Used in nodejs_bianry later to help see which version of node is run
173
+ write_file (
174
+ name = "binary_version" ,
175
+ out = "binary_version.js" ,
176
+ content = ["console.log(process.version)" ],
177
+ )
178
+
179
+ # Files used in test cases later that contain the correct nodejs version
180
+ # that is imported into the workspace.
181
+ write_file (
182
+ name = "write_node_version_15" ,
183
+ out = "expected_node_15" ,
184
+ content = ["v15.14.0" ],
185
+ )
186
+
187
+ write_file (
188
+ name = "write_node_version_16" ,
189
+ out = "expected_node_16" ,
190
+ content = ["v16.9.0" ],
191
+ )
192
+
193
+ # To see what nodejs version is used by default
194
+ my_nodejs (
195
+ name = "run_no_toolchain" ,
196
+ out = "thing_no_toolchain" ,
197
+ entry_point = "version.js" ,
198
+ )
199
+
200
+ # this tests to make sure that the first version imported in the workspace is used as default
201
+ diff_test (
202
+ name = "node_version_default_toolchain_test" ,
203
+ file1 = "write_node_version_15" ,
204
+ file2 = "thing_no_toolchain" ,
205
+ )
206
+
207
+ # Output contains the version number of node that is used.
208
+ # This is used in tests later to verify the toolchain specified is resolved correctly
209
+ my_nodejs (
210
+ name = "run_15" ,
211
+ out = "thing_toolchain_15" ,
212
+ entry_point = "version.js" ,
213
+ # using the select statement will download toolchains for all three platforms
214
+ # you can also just provide an individual toolchain if you don't want to download them all
215
+ toolchain = select ({
216
+ "@bazel_tools//src/conditions:linux_x86_64" : "@node15_linux_amd64//:node_toolchain" ,
217
+ "@bazel_tools//src/conditions:darwin" : "@node15_darwin_amd64//:node_toolchain" ,
218
+ "@bazel_tools//src/conditions:windows" : "@node15_windows_amd64//:node_toolchain" ,
219
+ }),
220
+ )
221
+
222
+ # Section of test the verify the toolchain work as expected matching node version used with expected
223
+ diff_test (
224
+ name = "test_node_version_15" ,
225
+ file1 = "write_node_version_15" ,
226
+ file2 = "thing_toolchain_15" ,
227
+ )
228
+
229
+ my_nodejs (
230
+ name = "run_16" ,
231
+ out = "thing_toolchain_16" ,
232
+ entry_point = "version.js" ,
233
+ # using the select statement will download toolchains for all three platforms
234
+ # you can also just provide an individual toolchain if you don't want to download them all
235
+ toolchain = select ({
236
+ "@bazel_tools//src/conditions:linux_x86_64" : "@node16_linux_amd64//:node_toolchain" ,
237
+ "@bazel_tools//src/conditions:darwin" : "@node16_darwin_amd64//:node_toolchain" ,
238
+ "@bazel_tools//src/conditions:windows" : "@node16_windows_amd64//:node_toolchain" ,
239
+ }),
240
+ )
241
+
242
+ diff_test (
243
+ name = "test_node_version_16" ,
244
+ file1 = "write_node_version_16" ,
245
+ file2 = "thing_toolchain_16" ,
246
+ )
0 commit comments