Skip to content

Commit 06aa455

Browse files
committed
build: update karma rules and interop to work with rules_js
Introduces a new spec-bundle Karma variant that works with `rules_js`, and updates the interop to work with `rules_js` node modules.
1 parent bca1ac9 commit 06aa455

File tree

3 files changed

+34
-43
lines changed

3 files changed

+34
-43
lines changed

tools/bazel/ts_project_interop.bzl

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,27 +44,17 @@ def _ts_project_module_impl(ctx):
4444
runfiles = ctx.attr.dep[DefaultInfo].default_runfiles
4545
info = ctx.attr.dep[JsInfo]
4646

47-
# Filter runfiles to not include `node_modules` from Aspect as this interop
48-
# target is supposed to be used downstream by `rules_nodejs` consumers,
49-
# and mixing pnpm-style node modules with linker node modules is incompatible.
50-
filtered_runfiles = []
51-
for f in runfiles.files.to_list():
52-
if f.short_path.startswith("node_modules/"):
53-
continue
54-
filtered_runfiles.append(f)
55-
runfiles = ctx.runfiles(files = filtered_runfiles)
56-
5747
providers = [
5848
DefaultInfo(
5949
runfiles = runfiles,
6050
),
6151
JSModuleInfo(
6252
direct_sources = info.sources,
63-
sources = depset(transitive = [info.transitive_sources]),
53+
sources = depset(transitive = [info.transitive_sources, info.npm_sources]),
6454
),
6555
JSEcmaScriptModuleInfo(
6656
direct_sources = info.sources,
67-
sources = depset(transitive = [info.transitive_sources]),
57+
sources = depset(transitive = [info.transitive_sources, info.npm_sources]),
6858
),
6959
DeclarationInfo(
7060
declarations = _filter_types_depset(info.types),
@@ -155,7 +145,7 @@ def ts_project(
155145
dep = name,
156146
# Forwarded dependencies for linker module mapping aspect.
157147
# RJS deps can also transitively pull in module mappings from their `interop_deps`.
158-
deps = [":%s_interop_deps" % name] + deps,
148+
deps = deps,
159149
module_name = module_name,
160150
)
161151

tools/defaults.bzl

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ load("@build_bazel_rules_nodejs//:index.bzl", _pkg_npm = "pkg_npm")
55
load("@io_bazel_rules_sass//:defs.bzl", _npm_sass_library = "npm_sass_library", _sass_binary = "sass_binary", _sass_library = "sass_library")
66
load("@npm//@angular/bazel:index.bzl", _ng_package = "ng_package")
77
load("@npm//@angular/build-tooling/bazel/integration:index.bzl", _integration_test = "integration_test")
8-
load("@npm//@angular/build-tooling/bazel/karma:index.bzl", _karma_web_test_suite = "karma_web_test_suite")
98
load("@npm//@angular/build-tooling/bazel/esbuild:index.bzl", _esbuild = "esbuild", _esbuild_config = "esbuild_config")
109
load("@npm//@angular/build-tooling/bazel/spec-bundling:index.bzl", _spec_bundle = "spec_bundle")
1110
load("@npm//@angular/build-tooling/bazel/http-server:index.bzl", _http_server = "http_server")
@@ -18,6 +17,7 @@ load("//tools/markdown-to-html:index.bzl", _markdown_to_html = "markdown_to_html
1817
load("//tools/extract-tokens:index.bzl", _extract_tokens = "extract_tokens")
1918
load("//tools/angular:index.bzl", "LINKER_PROCESSED_FW_PACKAGES")
2019
load("//tools/bazel:ng_package_interop.bzl", "ng_package_interop")
20+
load("//tools:defaults2.bzl", _karma_web_test_suite = "karma_web_test_suite")
2121

2222
npmPackageSubstitutions = select({
2323
"//tools:stamp": NPM_PACKAGE_SUBSTITUTIONS,
@@ -31,6 +31,7 @@ extract_tokens = _extract_tokens
3131
esbuild = _esbuild
3232
esbuild_config = _esbuild_config
3333
http_server = _http_server
34+
karma_web_test_suite = _karma_web_test_suite
3435

3536
def sass_binary(sourcemap = False, include_paths = [], **kwargs):
3637
_sass_binary(
@@ -145,35 +146,6 @@ def jasmine_node_test(**kwargs):
145146
kwargs["templated_args"] = ["--bazel_patch_module_resolver"] + kwargs.get("templated_args", [])
146147
_jasmine_node_test(**kwargs)
147148

148-
def karma_web_test_suite(name, **kwargs):
149-
test_deps = kwargs.get("deps", [])
150-
151-
kwargs["tags"] = ["partial-compilation-integration"] + kwargs.get("tags", [])
152-
kwargs["deps"] = ["%s_bundle" % name]
153-
154-
spec_bundle(
155-
name = "%s_bundle" % name,
156-
deps = test_deps,
157-
platform = "browser",
158-
)
159-
160-
# Set up default browsers if no explicit `browsers` have been specified.
161-
if not hasattr(kwargs, "browsers"):
162-
kwargs["tags"] = ["native"] + kwargs.get("tags", [])
163-
kwargs["browsers"] = [
164-
# Note: when changing the browser names here, also update the "yarn test"
165-
# script to reflect the new browser names.
166-
"@npm//@angular/build-tooling/bazel/browsers/chromium:chromium",
167-
"@npm//@angular/build-tooling/bazel/browsers/firefox:firefox",
168-
]
169-
170-
# Default test suite with all configured browsers, and the debug target being
171-
# setup from `angular/dev-infra`.
172-
_karma_web_test_suite(
173-
name = name,
174-
**kwargs
175-
)
176-
177149
def protractor_web_test_suite(name, deps, **kwargs):
178150
spec_bundle(
179151
name = "%s_bundle" % name,

tools/defaults2.bzl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ load("//tools/bazel:ts_project_interop.bzl", _ts_project = "ts_project")
33
load("//tools/bazel:module_name.bzl", "compute_module_name")
44
load("@aspect_rules_js//npm:defs.bzl", _npm_package = "npm_package")
55
load("@rules_angular//src/ng_project:index.bzl", _ng_project = "ng_project")
6+
load("@devinfra//bazel/spec-bundling:index_rjs.bzl", "spec_bundle_amd")
7+
load("@devinfra//bazel/karma:index.bzl", _karma_web_test_suite = "karma_web_test_suite")
68

79
def npm_package(**kwargs):
810
_npm_package(**kwargs)
@@ -73,3 +75,30 @@ def jasmine_test(data = [], args = [], **kwargs):
7375
],
7476
**kwargs
7577
)
78+
79+
def karma_web_test_suite(name, tags = [], deps = [], browsers = None, **kwargs):
80+
spec_bundle_amd(
81+
name = "%s_bundle" % name,
82+
workspace_name = "angular_material",
83+
deps = deps,
84+
)
85+
86+
test_tags = ["partial-compilation-integration"] + tags
87+
88+
# Set up default browsers if no explicit `browsers` have been specified.
89+
if browsers == None:
90+
test_tags.append("native")
91+
browsers = [
92+
# Note: when changing the browser names here, also update the "yarn test"
93+
# script to reflect the new browser names.
94+
"@npm//@angular/build-tooling/bazel/browsers/chromium:chromium",
95+
"@npm//@angular/build-tooling/bazel/browsers/firefox:firefox",
96+
]
97+
98+
_karma_web_test_suite(
99+
name = name,
100+
tags = test_tags,
101+
deps = [":%s_bundle" % name],
102+
browsers = browsers,
103+
**kwargs
104+
)

0 commit comments

Comments
 (0)