Skip to content

Instantly share code, notes, and snippets.

@dicarlo2
Created November 27, 2018 08:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dicarlo2/8254f5b8c3d954515287d5e33f20466f to your computer and use it in GitHub Desktop.
Save dicarlo2/8254f5b8c3d954515287d5e33f20466f to your computer and use it in GitHub Desktop.
load(":providers.bzl", "TypeScriptModuleInfo")
def _test_sources_aspect_impl(target, ctx):
result = depset()
if hasattr(ctx.rule.attr, "tags") and "NODE_MODULE_MARKER" in ctx.rule.attr.tags:
return struct(node_test_sources=result)
if hasattr(ctx.rule.attr, "deps"):
for dep in ctx.rule.attr.deps:
if hasattr(dep, "node_test_sources"):
result = depset(transitive=[result, dep.node_test_sources])
if TypeScriptModuleInfo in target:
result = depset(
[f for f in target[TypeScriptModuleInfo].js if f.path.endswith(
".test.js")],
transitive=[result])
elif hasattr(target, "files"):
result = depset([f for f in target.files.to_list() if f.path.endswith(".test.js")],
transitive=[result])
return struct(node_test_sources=result)
test_sources_aspect = aspect(
_test_sources_aspect_impl,
attr_aspects=["deps"],
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment