Skip to content

Commit

Permalink
fix(jasmine): transitive specs are no longer added to the test suite (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
a-ignatov-parc authored Apr 6, 2021
1 parent 73a9811 commit e7eaf34
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
16 changes: 14 additions & 2 deletions packages/jasmine/jasmine_node_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ def _js_sources_impl(ctx):
depsets = []
for src in ctx.attr.srcs:
if JSModuleInfo in src:
depsets.append(src[JSModuleInfo].sources)
provider = src[JSModuleInfo]
files = provider.direct_sources if ctx.attr.use_direct_specs else provider.sources
depsets.append(files)
if hasattr(src, "files"):
depsets.append(src.files)
sources = depset(transitive = depsets)
Expand All @@ -48,6 +50,7 @@ _js_sources = rule(
"srcs": attr.label_list(
allow_files = True,
),
"use_direct_specs": attr.bool(),
},
outputs = {
"manifest": "%{name}.MF",
Expand All @@ -62,6 +65,7 @@ def jasmine_node_test(
expected_exit_code = 0,
tags = [],
config_file = None,
use_direct_specs = None,
# Replaced by pkg_npm with jasmine = "//@bazel/jasmine",
jasmine = "//packages/jasmine",
# Replaced by pkg_npm with jasmine_entry_point = "//:node_modules/@bazel/jasmine/jasmine_runner.js",
Expand Down Expand Up @@ -91,6 +95,13 @@ def jasmine_node_test(
See https://jasmine.github.io/setup/nodejs.html#configuration
use_direct_specs: Limits the list of specs added to the execution (test suite) to direct sources.
Note that this is a bug fix opt-in flag, which will be the default
behavior in the next major release.
More info: https://github.com/bazelbuild/rules_nodejs/pull/2576
jasmine: A label providing the `@bazel/jasmine` npm dependency.
jasmine_entry_point: A label providing the `@bazel/jasmine` entry point.
**kwargs: Remaining arguments are passed to the test rule
Expand All @@ -100,9 +111,10 @@ def jasmine_node_test(

_js_sources(
name = "%s_js_sources" % name,
srcs = srcs + deps,
srcs = srcs if use_direct_specs else (srcs + deps),
testonly = 1,
tags = tags,
use_direct_specs = use_direct_specs,
)

all_data = data + srcs + deps + [Label(jasmine)]
Expand Down
15 changes: 15 additions & 0 deletions packages/jasmine/test/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("//:index.bzl", "js_library")
load("//internal/common:copy_to_bin.bzl", "copy_to_bin")
load("//packages/jasmine:index.bzl", "jasmine_node_test")
load("//packages/typescript:index.bzl", "ts_library")
Expand Down Expand Up @@ -208,4 +209,18 @@ jasmine_node_test(
jasmine_node_test(
name = "stack_test",
srcs = ["stack.spec.js"],
deps = [":fail_test"],
)

# Verify that transitive specs are not added to the execution
js_library(
name = "lib_with_fail_spec",
srcs = ["fail.spec.js"],
)

jasmine_node_test(
name = "transitive_spec_test",
srcs = ["foo.spec.js"],
use_direct_specs = True,
deps = [":lib_with_fail_spec"],
)
5 changes: 4 additions & 1 deletion packages/rollup/rollup_bundle.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,10 @@ def _rollup_bundle(ctx):

return [
DefaultInfo(files = outputs_depset),
JSModuleInfo(sources = outputs_depset),
JSModuleInfo(
direct_sources = outputs_depset,
sources = outputs_depset,
),
]

rollup_bundle = rule(
Expand Down
9 changes: 7 additions & 2 deletions packages/terser/terser_minified.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,14 @@ def _terser(ctx):
progress_message = "Minifying JavaScript %s [terser]" % (outputs[0].short_path),
)

outputs_depset = depset(outputs)

return [
DefaultInfo(files = depset(outputs)),
JSModuleInfo(sources = depset(outputs)),
DefaultInfo(files = outputs_depset),
JSModuleInfo(
direct_sources = outputs_depset,
sources = outputs_depset,
),
]

terser_minified = rule(
Expand Down

0 comments on commit e7eaf34

Please sign in to comment.