Skip to content

Commit 14b2965

Browse files
authored
Added rust_wasm_bindgen_test rule (#3267)
This change adds a new rule `rust_wasm_bindgen_test` for running tests in a headless browser. Currently only `chrome` and `firefox` are supported browsers. The browser can be selected using the following flag. ``` --@rules_rust_wasm_bindgen//:test_browser={BROWSER} ```
1 parent 70f91ac commit 14b2965

35 files changed

+2305
-34
lines changed

.bazelci/presubmit.yml

+12-8
Original file line numberDiff line numberDiff line change
@@ -1066,12 +1066,15 @@ tasks:
10661066
platform: ubuntu2004
10671067
name: Extensions wasm-bindgen
10681068
working_directory: extensions/wasm_bindgen
1069+
shell_commands:
1070+
- "sudo apt -y update && sudo apt -y install libxcb1 libatk1.0-0 libatk-bridge2.0-0 libxcomposite1 libxdamage1 libxfixes3 libxrandr2 libgbm1 libpango-1.0-0 libxkbcommon-x11-0 libcairo2"
10691071
build_flags: *aspects_flags
10701072
test_flags: *aspects_flags
10711073
build_targets:
10721074
- "//..."
1073-
test_targets:
1074-
- "//..."
1075+
# TODO: Chromedriver cannot launch chrome on linux
1076+
# test_targets:
1077+
# - "//..."
10751078
extensions_wasm_bindgen_linux_rbe:
10761079
platform: rbe_ubuntu2004
10771080
name: Extensions wasm-bindgen
@@ -1083,12 +1086,13 @@ tasks:
10831086
test_flags: *aspects_flags
10841087
build_targets:
10851088
- "//..."
1086-
test_targets:
1087-
- "--"
1088-
- "//..."
1089-
# TODO: https://github.com/bazelbuild/rules_rust/issues/3039
1090-
- "-//rules_js/test:hello_world_wasm_lib_test"
1091-
- "-//rules_js/test:hello_world_wasm_direct_test"
1089+
# TODO: Chromedriver cannot launch chrome on linux
1090+
# test_targets:
1091+
# - "--"
1092+
# - "//..."
1093+
# # TODO: https://github.com/bazelbuild/rules_rust/issues/3039
1094+
# - "-//rules_js/test:hello_world_wasm_lib_test"
1095+
# - "-//rules_js/test:hello_world_wasm_direct_test"
10921096
extensions_wasm_bindgen_macos:
10931097
platform: macos_arm64
10941098
name: Extensions wasm-bindgen

extensions/wasm_bindgen/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
/bazel-*
55
user.bazelrc
66

7+
# Test Browsers
8+
browsers/
9+
710
# rust-analyzer
811
rust-project.json
912

extensions/wasm_bindgen/3rdparty/BUILD.bazel

+16
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ crates_vendor(
3333
"wasm-bindgen": crate.spec(
3434
version = WASM_BINDGEN_VERSION,
3535
),
36+
"wasm-bindgen-test": crate.spec(
37+
version = "0.3.37",
38+
),
3639
},
3740
# Shorten the repository name to avoid MAX_PATH issues on Windows
3841
# `rules_rust_wasm_bindgen_deps` == `rrwbd`
@@ -47,12 +50,25 @@ alias(
4750
visibility = ["//visibility:public"],
4851
)
4952

53+
alias(
54+
name = "wasm_bindgen_test_runner",
55+
actual = "@rules_rust_wasm_bindgen_cli//:test_runner",
56+
tags = ["manual"],
57+
visibility = ["//visibility:public"],
58+
)
59+
5060
alias(
5161
name = "wasm_bindgen",
5262
actual = "//3rdparty/crates:wasm-bindgen",
5363
visibility = ["//visibility:public"],
5464
)
5565

66+
alias(
67+
name = "wasm_bindgen_test",
68+
actual = "//3rdparty/crates:wasm-bindgen-test",
69+
visibility = ["//visibility:public"],
70+
)
71+
5672
bzl_library(
5773
name = "bzl_lib",
5874
srcs = [

extensions/wasm_bindgen/3rdparty/BUILD.wasm-bindgen-cli.bazel

+34-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ exports_files([
1212
# TODO: Comment on bootstrapping
1313
rust_binary(
1414
name = "wasm-bindgen-cli",
15-
srcs = glob(["**/*.rs"]),
15+
srcs = glob(
16+
include = ["**/*.rs"],
17+
exclude = ["src/bin/wasm-bindgen-test-runner/**"],
18+
),
1619
aliases = aliases(),
1720
crate_features = [
1821
],
@@ -33,3 +36,33 @@ alias(
3336
actual = ":wasm-bindgen-cli",
3437
tags = ["manual"],
3538
)
39+
40+
rust_binary(
41+
name = "wasm-bindgen-test-runner",
42+
srcs = glob(
43+
include = ["**/*.rs"],
44+
exclude = ["src/bin/wasm-bindgen.rs"],
45+
),
46+
aliases = aliases(),
47+
compile_data = glob([
48+
"**/*.html",
49+
]),
50+
crate_features = [
51+
],
52+
crate_root = "src/bin/wasm-bindgen-test-runner/main.rs",
53+
data = [],
54+
edition = "2018",
55+
proc_macro_deps = all_crate_deps(proc_macro = True),
56+
rustc_flags = [
57+
# Don't produce warnings for this crate
58+
"--cap-lints=allow",
59+
],
60+
version = WASM_BINDGEN_VERSION,
61+
deps = all_crate_deps(),
62+
)
63+
64+
alias(
65+
name = "test_runner",
66+
actual = ":wasm-bindgen-test-runner",
67+
tags = ["manual"],
68+
)

extensions/wasm_bindgen/3rdparty/Cargo.Bazel.lock

+78
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extensions/wasm_bindgen/3rdparty/crates/BUILD.bazel

+24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extensions/wasm_bindgen/3rdparty/crates/BUILD.js-sys-0.3.77.bazel

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)