Skip to content

Commit 1aa7874

Browse files
committed
Added support for safaridriver
1 parent 144f0df commit 1aa7874

24 files changed

+652
-490
lines changed

.bazelci/presubmit.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,7 @@ tasks:
10801080
name: Extensions wasm-bindgen
10811081
working_directory: extensions/wasm_bindgen
10821082
shell_commands:
1083-
- "bash ./test/bazelci_linux_setup.sh"
1083+
- "bash ./test/bazelci_unix_setup.sh"
10841084
build_flags: *aspects_flags
10851085
test_flags: *aspects_flags
10861086
build_targets:
@@ -1105,6 +1105,8 @@ tasks:
11051105
platform: macos_arm64
11061106
name: Extensions wasm-bindgen
11071107
working_directory: extensions/wasm_bindgen
1108+
shell_commands:
1109+
- "bash ./test/bazelci_unix_setup.sh"
11081110
build_flags: *aspects_flags
11091111
test_flags: *aspects_flags
11101112
build_targets:
Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,14 @@
11
bcr_test_module:
22
module_path: ""
33
matrix:
4-
platform: ["macos_arm64", "windows"]
4+
platform: ["macos_arm64", "ubuntu2004", "windows"]
55
bazel: ["7.x", "8.x"]
66
tasks:
77
run_tests:
88
name: "Run test module"
99
platform: ${{ platform }}
1010
bazel: ${{ bazel }}
11-
test_targets:
12-
- "//..."
13-
bcr_test_module_linux:
14-
module_path: ""
15-
matrix:
16-
platform: ["ubuntu2004"]
17-
bazel: ["7.x", "8.x"]
18-
tasks:
19-
run_tests:
2011
shell_commands:
21-
- "bash ./test/bazelci_linux_setup.sh"
22-
name: "Run test module"
23-
platform: ${{ platform }}
24-
bazel: ${{ bazel }}
12+
- "bash ./test/bazelci_unix_setup.sh"
2513
test_targets:
2614
- "//..."

extensions/wasm_bindgen/.bazelrc

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
# TODO: https://github.com/bazelbuild/rules_rust/issues/3319
99
common --deleted_packages=rules_js,rules_js/test
1010

11+
# An alias for the test browser setting.
12+
common --flag_alias=test_browser=//settings:test_browser
13+
1114
###############################################################################
1215

1316
# https://bazel.build/reference/command-line-reference#flag--enable_platform_specific_config
@@ -29,14 +32,8 @@ common --experimental_cc_shared_library
2932
## Unique configuration groups
3033
###############################################################################
3134

32-
# Explicitly use firefox for browser tests.
33-
build:firefox --//settings:test_browser=firefox
34-
35-
# Explicitly use chrome for browser tests
36-
build:chrome --//settings:test_browser=chrome
37-
3835
# Default linux to run firefox
39-
build:linux --config=firefox
36+
build:linux --test_browser=firefox
4037

4138
# Enable use of the nightly toolchains.
4239
build:nightly --@rules_rust//rust/toolchain/channel=nightly

extensions/wasm_bindgen/BUILD.bazel

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ rust_wasm_bindgen_toolchain(
2727
browser = select({
2828
"//settings:test_browser_chrome": "@chrome",
2929
"//settings:test_browser_firefox": "@firefox",
30+
"//settings:test_browser_safari": None,
3031
}),
3132
browser_type = select({
3233
"//settings:test_browser_chrome": "chrome",
3334
"//settings:test_browser_firefox": "firefox",
35+
"//settings:test_browser_safari": "safari",
3436
}),
3537
visibility = ["//visibility:public"],
3638
wasm_bindgen_cli = "//3rdparty:wasm_bindgen_cli",
@@ -39,10 +41,12 @@ rust_wasm_bindgen_toolchain(
3941
webdriver = select({
4042
"//settings:test_browser_chrome": "@chromedriver",
4143
"//settings:test_browser_firefox": "@geckodriver",
44+
"//settings:test_browser_safari": "@safaridriver",
4245
}),
4346
webdriver_args = select({
4447
"//settings:test_browser_chrome": ["--verbose"],
4548
"//settings:test_browser_firefox": [],
49+
"//settings:test_browser_safari": [],
4650
}),
4751
webdriver_json = "webdriver.json",
4852
)

extensions/wasm_bindgen/MODULE.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ use_repo(
6666
"rrwbd__wasmparser-0.214.0",
6767
"rrwbd__wasmprinter-0.214.0",
6868
"rules_rust_wasm_bindgen_cli",
69+
"safaridriver",
6970
)
7071

7172
register_toolchains(

extensions/wasm_bindgen/private/wasm_bindgen.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ For additional information, see the [Bazel toolchains documentation][toolchains]
282282
values = [
283283
"firefox",
284284
"chrome",
285+
"safari",
285286
],
286287
),
287288
"wasm_bindgen_cli": attr.label(

extensions/wasm_bindgen/private/wasm_bindgen_test_wrapper.rs

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,27 @@ use runfiles::{rlocation, Runfiles};
1010

1111
fn write_webdriver_for_browser(
1212
original: &Path,
13-
section: &str,
13+
section: Option<&str>,
1414
args: &Vec<String>,
1515
browser: &Option<PathBuf>,
1616
output: &Path,
1717
) {
18+
// If no section is provided, simply copy the file and early return.
19+
let section = match section {
20+
Some(s) => s,
21+
None => {
22+
fs::copy(original, output).unwrap_or_else(|e| {
23+
panic!(
24+
"Failed to copy webdriver config: {} -> {}\n{:?}",
25+
original.display(),
26+
output.display(),
27+
e
28+
);
29+
});
30+
return;
31+
}
32+
};
33+
1834
let content = fs::read_to_string(original).unwrap_or_else(|e| {
1935
panic!(
2036
"Failed to read webdriver.json at: {}\n{:?}",
@@ -135,7 +151,7 @@ fn main() {
135151

136152
write_webdriver_for_browser(
137153
&webdriver_json,
138-
"goog:chromeOptions",
154+
Some("goog:chromeOptions"),
139155
&vec![format!("user-data-dir={}", user_data_dir.display())],
140156
&browser,
141157
&updated_webdriver_json,
@@ -151,7 +167,7 @@ fn main() {
151167

152168
write_webdriver_for_browser(
153169
&webdriver_json,
154-
"moz:firefoxOptions",
170+
Some("moz:firefoxOptions"),
155171
&Vec::new(),
156172
&browser,
157173
&updated_webdriver_json,
@@ -161,13 +177,56 @@ fn main() {
161177
// and creating an additional one would result in errors.
162178
env.insert("MOZ_DISABLE_CONTENT_SANDBOX".to_string(), "1".to_string());
163179

164-
env.insert("GECKODRIVER_ARGS".to_string(), webdriver_args);
180+
let mut args = Vec::new();
181+
182+
// Define a clean profile root that can be checked at the end of tests.
183+
let profile_root = undeclared_test_outputs.join("profile_root");
184+
fs::create_dir_all(&profile_root).unwrap_or_else(|e| {
185+
panic!(
186+
"Failed to create directory: {}\n{:?}",
187+
profile_root.display(),
188+
e
189+
)
190+
});
191+
192+
// geckodriver directly accepts the profile root arg so it's tracked here
193+
// as there's no way to write this info in a usable way to the `webdriver.json`.
194+
args.push(format!("--profile-root={}", profile_root.display()));
195+
196+
// geckodriver explicitly accepts a browser flag so we pass that in addition
197+
// to setting it in the webdriver.json config.
198+
if let Some(browser) = browser {
199+
args.push(format!("--binary={}", browser.display()));
200+
}
201+
202+
// Ensure logs are always complete.
203+
args.push("--log-no-truncate".to_string());
204+
205+
// Some arguments must be passed to geckodriver directly to ensure it's
206+
// launched in an expected manner
207+
env.insert(
208+
"GECKODRIVER_ARGS".to_string(),
209+
args.join(" ").trim().to_string(),
210+
);
211+
}
212+
"safari" => {
213+
write_webdriver_for_browser(
214+
&webdriver_json,
215+
None,
216+
&Vec::new(),
217+
&browser,
218+
&updated_webdriver_json,
219+
);
220+
221+
env.insert("SAFARIDRIVER_ARGS".to_string(), webdriver_args);
165222
}
166223
_ => {
167224
panic!("Unexpected browser type: {}", browser_type)
168225
}
169226
}
170227

228+
env.insert("RUST_LOG".to_string(), "debug".to_string());
229+
171230
// Run the test
172231
let mut command = Command::new(test_runner);
173232
command.envs(env).arg(test_bin).args(env::args().skip(1));

extensions/wasm_bindgen/private/webdrivers/BUILD.bazel

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
22

3-
exports_files([
4-
"firefox",
5-
"chrome",
6-
])
7-
83
bzl_library(
94
name = "bzl_lib",
105
srcs = glob(["*.bzl"]),

extensions/wasm_bindgen/private/webdrivers/chrome/BUILD.bazel

Whitespace-only changes.

0 commit comments

Comments
 (0)