From e7eaf340f10e183ae34b5d7095c018b7727b497a Mon Sep 17 00:00:00 2001 From: Anton Ignatov Date: Tue, 6 Apr 2021 21:12:40 +0200 Subject: [PATCH] fix(jasmine): transitive specs are no longer added to the test suite (#2576) --- packages/jasmine/jasmine_node_test.bzl | 16 ++++++++++++++-- packages/jasmine/test/BUILD.bazel | 15 +++++++++++++++ packages/rollup/rollup_bundle.bzl | 5 ++++- packages/terser/terser_minified.bzl | 9 +++++++-- 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/packages/jasmine/jasmine_node_test.bzl b/packages/jasmine/jasmine_node_test.bzl index cdc5f045b5..d1d7b240ae 100644 --- a/packages/jasmine/jasmine_node_test.bzl +++ b/packages/jasmine/jasmine_node_test.bzl @@ -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) @@ -48,6 +50,7 @@ _js_sources = rule( "srcs": attr.label_list( allow_files = True, ), + "use_direct_specs": attr.bool(), }, outputs = { "manifest": "%{name}.MF", @@ -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", @@ -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 @@ -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)] diff --git a/packages/jasmine/test/BUILD.bazel b/packages/jasmine/test/BUILD.bazel index d31129434b..4afd002787 100644 --- a/packages/jasmine/test/BUILD.bazel +++ b/packages/jasmine/test/BUILD.bazel @@ -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") @@ -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"], ) diff --git a/packages/rollup/rollup_bundle.bzl b/packages/rollup/rollup_bundle.bzl index 0cecddcbcf..1bfeb0491b 100644 --- a/packages/rollup/rollup_bundle.bzl +++ b/packages/rollup/rollup_bundle.bzl @@ -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( diff --git a/packages/terser/terser_minified.bzl b/packages/terser/terser_minified.bzl index 947f54c2bb..950fbab233 100644 --- a/packages/terser/terser_minified.bzl +++ b/packages/terser/terser_minified.bzl @@ -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(