Unit testing with Karma
ts_web_test_macro
ts_web_test_macro(karma, tags, data, **kwargs)
ibazel wrapper for ts_web_test
This macro re-exposes the ts_web_test
rule with some extra tags so that
it behaves correctly under ibazel.
This is re-exported in //:defs.bzl
as ts_web_test
so if you load the rule
from there, you actually get this macro.
Attributes
karma |
karma binary label |
tags |
standard Bazel tags, this macro adds a couple for ibazel |
data |
runtime dependencies |
**kwargs |
passed through to |
ts_web_test_suite
ts_web_test_suite(name, browsers, karma, args, browser_overrides, config, flaky, local, shard_count, size, tags, test_suite_tags, timeout, visibility, web_test_data, wrapped_test_tags, **remaining_keyword_args)
Defines a test_suite of web_test targets that wrap a ts_web_test target.
Attributes
name |
The base name of the test. |
browsers |
A sequence of labels specifying the browsers to use. |
karma |
karma binary label |
args |
Args for web_test targets generated by this extension. |
browser_overrides |
Dictionary; optional; default is an empty dictionary. A dictionary mapping from browser names to browser-specific web_test attributes, such as shard_count, flakiness, timeout, etc. For example: {'//browsers:chrome-native': {'shard_count': 3, 'flaky': 1} '//browsers:firefox-native': {'shard_count': 1, 'timeout': 100}}. |
config |
Label; optional; Configuration of web test features. |
flaky |
A boolean specifying that the test is flaky. If set, the test will be retried up to 3 times (default: 0) |
local |
boolean; optional. |
shard_count |
The number of test shards to use per browser. (default: 1) |
size |
A string specifying the test size. (default: 'large') |
tags |
A list of test tag strings to apply to each generated web_test target. This macro adds a couple for ibazel. |
test_suite_tags |
A list of tag strings for the generated test_suite. |
timeout |
A string specifying the test timeout (default: computed from size) |
visibility |
List of labels; optional. |
web_test_data |
Data dependencies for the web_test. |
wrapped_test_tags |
A list of test tag strings to use for the wrapped test |
**remaining_keyword_args |
Arguments for the wrapped test target. |
ts_web_test
ts_web_test(name, deps, data, srcs, bootstrap, karma, runtime_deps, static_files)
Runs unit tests in a browser.
When executed under bazel test
, this uses a headless browser for speed.
This is also because bazel test
allows multiple targets to be tested together,
and we don't want to open a Chrome window on your machine for each one. Also,
under bazel test
the test will execute and immediately terminate.
Running under ibazel test
gives you a "watch mode" for your tests. The rule is
optimized for this case - the test runner server will stay running and just
re-serve the up-to-date JavaScript source bundle.
To debug a single test target, run it with bazel run
instead. This will open a
browser window on your computer. Also you can use any other browser by opening
the URL printed when the test starts up. The test will remain running until you
cancel the bazel run
command.
Currently this rule uses Karma as the test runner, but this is an implementation detail. We might switch to another runner like Jest in the future.
Attributes
name |
A unique name for this rule. |
deps |
Other targets which produce JavaScript such as |
data |
Runtime dependencies |
srcs |
JavaScript source files |
bootstrap |
JavaScript files to include before the module loader (require.js). For example, you can include Reflect,js for TypeScript decorator metadata reflection, or UMD bundles for third-party libraries. |
karma |
|
runtime_deps |
Dependencies which should be loaded after the module loader but before the srcs and deps.
These should be a list of targets which produce JavaScript such as |
static_files |
Arbitrary files which are available to be served on request.
Files are served at:
|