Skip to content

Commit

Permalink
concatjs_web back to karma_web
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eagle committed Dec 2, 2020
1 parent af59591 commit c1b19b7
Show file tree
Hide file tree
Showing 20 changed files with 73 additions and 63 deletions.
2 changes: 1 addition & 1 deletion examples/angular/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ load("@npm//@bazel/protractor:package.bzl", "npm_bazel_protractor_dependencies")

npm_bazel_protractor_dependencies()

# Load concatjs_web_test dependencies
# Load karma_web_test dependencies
http_archive(
name = "io_bazel_rules_webtesting",
sha256 = "9bb461d5ef08e850025480bab185fd269242d4e533bca75bfb748001ceb343c3",
Expand Down
4 changes: 2 additions & 2 deletions examples/angular/src/app/hello-world/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@io_bazel_rules_sass//:defs.bzl", "multi_sass_binary")
load("@npm//@bazel/concatjs:index.bzl", "concatjs_web_test_suite")
load("@npm//@bazel/concatjs:index.bzl", "karma_web_test_suite")
load("@npm//@bazel/typescript:index.bzl", "ts_library")
load("//tools:angular_ts_library.bzl", "ng_ts_library")

Expand Down Expand Up @@ -49,7 +49,7 @@ ts_library(
],
)

concatjs_web_test_suite(
karma_web_test_suite(
name = "test",
srcs = [
# We are manaully adding the bazel generated named-UMD date-fns bundle here as
Expand Down
4 changes: 2 additions & 2 deletions examples/angular_view_engine/src/app/hello-world/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@io_bazel_rules_sass//:defs.bzl", "sass_binary")
load("@npm//@bazel/concatjs:index.bzl", "concatjs_web_test_suite")
load("@npm//@bazel/concatjs:index.bzl", "karma_web_test_suite")
load("@npm//@bazel/typescript:index.bzl", "ts_library")
load("@npm_angular_bazel//:index.bzl", "ng_module")

Expand Down Expand Up @@ -59,7 +59,7 @@ ts_library(
],
)

concatjs_web_test_suite(
karma_web_test_suite(
name = "test",
srcs = [
# We are manaully adding the bazel generated named-UMD date-fns bundle here as
Expand Down
4 changes: 2 additions & 2 deletions examples/protocol_buffers/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@npm//@bazel/concatjs:index.bzl", "concatjs_devserver", "concatjs_web_test_suite")
load("@npm//@bazel/concatjs:index.bzl", "concatjs_devserver", "karma_web_test_suite")
load("@npm//@bazel/labs:index.bzl", "ts_proto_library")
load("@npm//@bazel/protractor:index.bzl", "protractor_web_test_suite")
load("@npm//@bazel/rollup:index.bzl", "rollup_bundle")
Expand Down Expand Up @@ -53,7 +53,7 @@ ts_library(
],
)

concatjs_web_test_suite(
karma_web_test_suite(
name = "test",
srcs = [
"@npm//@bazel/labs/grpc_web:bootstrap_scripts",
Expand Down
6 changes: 3 additions & 3 deletions examples/web_testing/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@npm//@bazel/concatjs:index.bzl", "concatjs_web_test_suite")
load("@npm//@bazel/concatjs:index.bzl", "karma_web_test_suite")
load("@npm//@bazel/typescript:index.bzl", "ts_config", "ts_library")

ts_library(
Expand Down Expand Up @@ -35,7 +35,7 @@ ts_library(
],
)

concatjs_web_test_suite(
karma_web_test_suite(
name = "config_test",
browsers = [
"@io_bazel_rules_webtesting//browsers:chromium-local",
Expand All @@ -55,7 +55,7 @@ concatjs_web_test_suite(
],
)

concatjs_web_test_suite(
karma_web_test_suite(
name = "no_config_test",
browsers = [
"@io_bazel_rules_webtesting//browsers:chromium-local",
Expand Down
3 changes: 3 additions & 0 deletions packages/concatjs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ js_library(

bzl_library(
name = "bzl",
testonly = True,
srcs = glob(["*.bzl"]) + [
# Work-around since we don't have and don't wnat a bzl_library in the generated
# @nodejs//:BUILD.bazel file
"@nodejs//:index.bzl",
],
deps = [
"//packages/concatjs/devserver:bzl",
"//packages/concatjs/web_test:bzl",
"@build_bazel_rules_nodejs//:bzl",
"@build_bazel_rules_nodejs//internal/common:bzl",
"@build_bazel_rules_nodejs//internal/node:bzl",
Expand All @@ -57,6 +59,7 @@ bzl_library(

stardoc(
name = "docs",
testonly = True,
out = "index.md",
input = "index.docs.bzl",
tags = ["fix-windows"],
Expand Down
8 changes: 4 additions & 4 deletions packages/concatjs/_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Most packages do not ship with this format, so in order to use concatjs tooling,
This is at the core of how Google does JavaScript development.
So Bazel rules that originated in Google's codebase have affordances for concatjs.
For example `ts_library` produces named AMD modules in its "devmode" output, and
`concatjs_web_test` expects to bundle inputs using concatjs.
`karma_web_test` expects to bundle inputs using concatjs.

## Serving JS in development mode under Bazel

Expand Down Expand Up @@ -78,13 +78,13 @@ finishes.

## Testing with Karma

The `concatjs_web_test` rule runs karma tests with Bazel.
The `karma_web_test` rule runs karma tests with Bazel.

It depends on rules_webtesting, so you need to add this to your `WORKSPACE`
if you use the web testing rules in `@bazel/concatjs`:

```python
# Fetch transitive Bazel dependencies of concatjs_web_test
# Fetch transitive Bazel dependencies of karma_web_test
http_archive(
name = "io_bazel_rules_webtesting",
sha256 = "9bb461d5ef08e850025480bab185fd269242d4e533bca75bfb748001ceb343c3",
Expand All @@ -109,7 +109,7 @@ browser_repositories(
If you didn't use the `yarn_install` or `npm_install` rule to create an `npm` workspace, you'll have to declare a rule in your root `BUILD.bazel` file to execute karma:

```python
# Create a karma rule to use in concatjs_web_test_suite karma
# Create a karma rule to use in karma_web_test_suite karma
# attribute when using self-managed dependencies
nodejs_binary(
name = "karma/karma",
Expand Down
10 changes: 5 additions & 5 deletions packages/concatjs/index.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ Users should not load files under "/internal"

load("//packages/concatjs/devserver:concatjs_devserver.bzl", _concatjs_devserver = "concatjs_devserver_macro")
load(
"//packages/concatjs/web_test:concatjs_web_test.bzl",
_concatjs_web_test = "concatjs_web_test",
_concatjs_web_test_suite = "concatjs_web_test_suite",
"//packages/concatjs/web_test:karma_web_test.bzl",
_karma_web_test = "karma_web_test",
_karma_web_test_suite = "karma_web_test_suite",
)

concatjs_web_test = _concatjs_web_test
concatjs_web_test_suite = _concatjs_web_test_suite
karma_web_test = _karma_web_test
karma_web_test_suite = _karma_web_test_suite
concatjs_devserver = _concatjs_devserver
7 changes: 7 additions & 0 deletions packages/concatjs/index.docs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ So this is a copy of index.bzl with macro indirection removed.
"""

load("//packages/concatjs/devserver:concatjs_devserver.bzl", _concatjs_devserver = "concatjs_devserver")
load(
"//packages/concatjs/web_test:karma_web_test.bzl",
_karma_web_test = "karma_web_test",
_karma_web_test_suite = "karma_web_test_suite",
)

karma_web_test = _karma_web_test
karma_web_test_suite = _karma_web_test_suite
concatjs_devserver = _concatjs_devserver
# DO NOT ADD MORE rules here unless they appear in the generated docsite.
# Run yarn stardoc to re-generate the docsite.
2 changes: 1 addition & 1 deletion packages/concatjs/web_test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ filegroup(
name = "package_contents",
srcs = [
"BUILD.bazel",
"concatjs_web_test.bzl",
"karma.conf.js",
"karma_web_test.bzl",
],
)
10 changes: 5 additions & 5 deletions packages/concatjs/web_test/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ try {
}

/**
* Configuration settings for karma under Bazel common to concatjs_web_test
* and concatjs_web_test_suite.
* Configuration settings for karma under Bazel common to karma_web_test
* and karma_web_test_suite.
*/
function configureBazelConfig(config, conf) {
// list of karma plugins
Expand Down Expand Up @@ -279,15 +279,15 @@ try {
}

/**
* Configure karma under concatjs_web_test_suite.
* Configure karma under karma_web_test_suite.
* `browsers` and `customLaunchers` are setup by Bazel.
*/
function configureTsWebTestSuiteConfig(conf) {
// WEB_TEST_METADATA is configured in rules_webtesting based on value
// of the browsers attribute passed to karms_web_test_suite
// We setup the karma configuration based on the values in this object
if (!process.env['WEB_TEST_METADATA']) {
// This is a concatjs_web_test rule since there is no WEB_TEST_METADATA
// This is a karma_web_test rule since there is no WEB_TEST_METADATA
return;
}

Expand Down Expand Up @@ -369,7 +369,7 @@ try {

function configureTsWebTestConfig(conf) {
if (process.env['WEB_TEST_METADATA']) {
// This is a concatjs_web_test_suite rule since there is a WEB_TEST_METADATA
// This is a karma_web_test_suite rule since there is a WEB_TEST_METADATA
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ KARMA_PEER_DEPS = [
"@npm//requirejs",
]

CONCATJS_WEB_TEST_ATTRS = {
KARMA_WEB_TEST_ATTRS = {
"bootstrap": attr.label_list(
doc = """JavaScript files to include *before* the module loader (require.js).
For example, you can include Reflect,js for TypeScript decorator metadata reflection,
Expand Down Expand Up @@ -207,7 +207,7 @@ def _write_karma_config(ctx, files, amd_names_shim):

return configuration

def _concatjs_web_test_impl(ctx):
def _karma_web_test_impl(ctx):
files_depsets = [depset(ctx.files.srcs)]
for dep in ctx.attr.deps + ctx.attr.runtime_deps:
if JSNamedModuleInfo in dep:
Expand Down Expand Up @@ -316,17 +316,17 @@ ${{COMMAND}}
executable = ctx.outputs.executable,
)]

_concatjs_web_test = rule(
implementation = _concatjs_web_test_impl,
_karma_web_test = rule(
implementation = _karma_web_test_impl,
test = True,
executable = True,
attrs = CONCATJS_WEB_TEST_ATTRS,
attrs = KARMA_WEB_TEST_ATTRS,
outputs = {
"configuration": "%{name}.conf.js",
},
)

def concatjs_web_test(
def karma_web_test(
srcs = [],
deps = [],
data = [],
Expand Down Expand Up @@ -361,7 +361,7 @@ def concatjs_web_test(
By default we open a headless Chrome. To use a real Chrome browser window, you can pass
`--define DISPLAY=true` to Bazel, along with `configuration_env_vars = ["DISPLAY"]` on
`concatjs_web_test`.
`karma_web_test`.
Args:
srcs: A list of JavaScript test files
Expand All @@ -385,11 +385,11 @@ def concatjs_web_test(
certain attributes of this configuration file. Attributes that are
overridden will be outputted to the test log.
tags: Standard Bazel tags, this macro adds tags for ibazel support
peer_deps: list of peer npm deps required by concatjs_web_test
**kwargs: Passed through to `concatjs_web_test`
peer_deps: list of peer npm deps required by karma_web_test
**kwargs: Passed through to `karma_web_test`
"""

_concatjs_web_test(
_karma_web_test(
srcs = srcs,
deps = deps + peer_deps,
data = data,
Expand All @@ -405,16 +405,16 @@ def concatjs_web_test(
**kwargs
)

def concatjs_web_test_suite(
def karma_web_test_suite(
name,
browsers = None,
web_test_data = [],
wrapped_test_tags = list(DEFAULT_WRAPPED_TEST_TAGS),
**kwargs):
"""Defines a test_suite of web_test targets that wrap a concatjs_web_test target.
"""Defines a test_suite of web_test targets that wrap a karma_web_test target.
This macro accepts all parameters in concatjs_web_test and adds additional parameters
for the suite. See concatjs_web_test docs for all concatjs_web_test.
This macro accepts all parameters in karma_web_test and adds additional parameters
for the suite. See karma_web_test docs for all karma_web_test.
The wrapping macro is `web_test_suite` which comes from rules_websting:
https://github.com/bazelbuild/rules_webtesting/blob/master/web/web.bzl.
Expand All @@ -424,8 +424,8 @@ def concatjs_web_test_suite(
browsers: A sequence of labels specifying the browsers to use.
web_test_data: Data dependencies for the wrapper web_test targets.
wrapped_test_tags: A list of test tag strings to use for the wrapped
concatjs_web_test target.
**kwargs: Arguments for the wrapped concatjs_web_test target.
karma_web_test target.
**kwargs: Arguments for the wrapped karma_web_test target.
"""

# Common attributes
Expand All @@ -452,9 +452,9 @@ def concatjs_web_test_suite(
if not "native" in tags:
tags = tags + ["native"]

# The wrapped `concatjs_web_test` target
# The wrapped `karma_web_test` target
wrapped_test_name = name + "_wrapped_test"
concatjs_web_test(
karma_web_test(
name = wrapped_test_name,
args = args,
flaky = flaky,
Expand Down
4 changes: 2 additions & 2 deletions packages/concatjs/web_test/test/karma/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

load("@build_bazel_rules_nodejs//:index.bzl", "generated_file_test")
load("@io_bazel_rules_webtesting//web:web.bzl", "custom_browser")
load("//packages/concatjs:index.bzl", "concatjs_web_test_suite")
load("//packages/concatjs:index.bzl", "karma_web_test_suite")

concatjs_web_test_suite(
karma_web_test_suite(
name = "testing",
srcs = glob(
["*.js"],
Expand Down
4 changes: 2 additions & 2 deletions packages/concatjs/web_test/test/karma_typescript/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("//packages/concatjs:index.bzl", "concatjs_web_test_suite")
load("//packages/concatjs:index.bzl", "karma_web_test_suite")
load("//packages/jasmine:index.bzl", "jasmine_node_test")
load("//packages/typescript:index.bzl", "ts_library")

Expand Down Expand Up @@ -42,7 +42,7 @@ ts_library(
],
)

concatjs_web_test_suite(
karma_web_test_suite(
name = "testing",
srcs = [
# JS files only in srcs - eval'ed but not require'd
Expand Down
4 changes: 2 additions & 2 deletions packages/concatjs/web_test/test/stack_trace/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("//packages/concatjs:index.bzl", "concatjs_web_test_suite")
load("//packages/concatjs:index.bzl", "karma_web_test_suite")
load("//packages/typescript:index.bzl", "ts_library")

ts_library(
Expand All @@ -27,7 +27,7 @@ ts_library(
# This is a test with failing test. This test is not directly run by CI.
# The sh_test below invokes this test and checks the source mapped lines in the
# stack trace.
concatjs_web_test_suite(
karma_web_test_suite(
name = "karma_test",
browsers = [
"@io_bazel_rules_webtesting//browsers:chromium-local",
Expand Down
2 changes: 1 addition & 1 deletion packages/labs/grpc_web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ You can now use the `test_ts_proto` target as a `dep` in other `ts_library` targ
- `google-protobuf`
- `grpc-web`

UMD versions of these runtime dependencies are provided by `//packages/labs/grpc_web:bootstrap_scripts` (for use within `concatjs_devserver` and `concatjs_web_test_suite`)
UMD versions of these runtime dependencies are provided by `//packages/labs/grpc_web:bootstrap_scripts` (for use within `concatjs_devserver` and `karma_web_test_suite`)

See `//examples/protocol_buffers/BUILD.bazel` for an example.

Expand Down
Loading

0 comments on commit c1b19b7

Please sign in to comment.