@@ -54,6 +54,7 @@ def wd_test(
5454 ] + args
5555
5656 _wd_test (
57+ src = src ,
5758 name = name ,
5859 data = data ,
5960 args = args ,
@@ -173,17 +174,43 @@ def _wd_test_impl(ctx):
173174 if default_runfiles :
174175 runfiles = runfiles .merge (default_runfiles )
175176
177+ # IMPORTANT: The workerd binary must be listed in dependency_attributes
178+ # to ensure its transitive dependencies (all the C++ source files) are
179+ # included in the coverage instrumentation. Without this, coverage data
180+ # won't be collected for the actual workerd implementation code.
181+ instrumented_files_info = coverage_common .instrumented_files_info (
182+ ctx ,
183+ source_attributes = ["src" , "data" ],
184+ dependency_attributes = ["workerd" , "sidecar" , "sidecar_supervisor" ],
185+ # Include all file types that might contain testable code
186+ extensions = ["cc" , "c++" , "cpp" , "cxx" , "c" , "h" , "hh" , "hpp" , "hxx" , "inc" , "js" , "ts" , "mjs" , "wd-test" , "capnp" ],
187+ )
188+
176189 return [
177190 DefaultInfo (
178191 executable = executable ,
179192 runfiles = runfiles ,
180193 ),
194+ instrumented_files_info ,
181195 ]
182196
183197_wd_test = rule (
184198 implementation = _wd_test_impl ,
185199 test = True ,
186200 attrs = {
201+ # Implicit dependencies used by Bazel to generate coverage reports.
202+ "_lcov_merger" : attr .label (
203+ default = configuration_field (fragment = "coverage" , name = "output_generator" ),
204+ executable = True ,
205+ cfg = config .exec (exec_group = "test" ),
206+ ),
207+ "_collect_cc_coverage" : attr .label (
208+ default = "@bazel_tools//tools/test:collect_cc_coverage" ,
209+ executable = True ,
210+ cfg = config .exec (exec_group = "test" ),
211+ ),
212+ # Source file
213+ "src" : attr .label (allow_single_file = True ),
187214 # The workerd executable is used to run all tests
188215 "workerd" : attr .label (
189216 allow_single_file = True ,
@@ -216,7 +243,7 @@ _wd_test = rule(
216243 allow_single_file = True ,
217244 executable = True ,
218245 cfg = "exec" ,
219- default = "//src/workerd/api/node:sidecar-supervisor" ,
246+ default = "//src/workerd/api/node/tests :sidecar-supervisor" ,
220247 ),
221248 "python_snapshot_test" : attr .bool (),
222249 # A reference to the Windows platform label, needed for the implementation of wd_test
0 commit comments