blob: 31a1f60842e76efe8b9870ae128884d245bc434e [file] [edit]
load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin")
load("@aspect_rules_js//js:defs.bzl", "js_binary", "js_library")
load("@aspect_rules_js//npm:defs.bzl", "npm_package")
load("@npm//:defs.bzl", "npm_link_all_packages")
load("@npm//javascript/selenium-webdriver:eslint/package_json.bzl", eslint_bin = "bin")
load("@npm//javascript/selenium-webdriver:jsdoc/package_json.bzl", jsdoc_bin = "bin")
load("@npm//javascript/selenium-webdriver:prettier/package_json.bzl", prettier_bin = "bin")
load("@rules_pkg//pkg:pkg.bzl", "pkg_tar")
load("//common:defs.bzl", "copy_file")
load("//javascript:defs.bzl", "mocha_test")
load("//javascript/private:browsers.bzl", "BROWSERS")
load("//javascript/private:jsdoc.bzl", "jsdoc")
load("//javascript/selenium-webdriver/private:generate_bidi.bzl", "generate_bidi_library")
npm_link_all_packages(name = "node_modules")
# Copy the shared license + note next to the generator so it can read them as siblings.
copy_file(
name = "license_header_local",
src = "//scripts:license_header.txt",
out = "license_header.txt",
)
copy_file(
name = "generated_note_local",
src = "//scripts:generated_note_template.txt",
out = "generated_note_template.txt",
)
# Generator script that reads the merged CDDL spec and produces one .ts file per BiDi domain.
js_binary(
name = "generate_bidi_script",
data = [
"generate_bidi.mjs",
":generated_note_local",
":license_header_local",
":node_modules/cddl",
":node_modules/cddl2ts",
],
entry_point = "generate_bidi.mjs",
)
# Projects the normalized, flat BiDi schema (commands + events + types) consumed
# by the generated Ruby / Java / Python clients. Pure JS — no npm dependencies.
js_binary(
name = "project_bidi_schema_script",
data = [
"normalize_bidi_ast.mjs",
"project_bidi_schema.mjs",
],
entry_point = "project_bidi_schema.mjs",
)
# Extracts the core spec's prose section anchors (#type-/#command-/#event-/#module-)
# from the pinned rendered HTML into the small index the schema step joins against.
js_binary(
name = "extract_bidi_anchors_script",
data = ["extract_bidi_anchors.mjs"],
entry_point = "extract_bidi_anchors.mjs",
)
# Tests for the BiDi schema tooling: unit tests for the normalizer + projector
# transforms, plus the authoritative field-fidelity check that diffs the
# projected schema against cddl2ts (an independent generator over the same AST,
# run over the generated artifacts) — catching dropped/mistyped fields and enum
# drift that the structural validators cannot see.
mocha_test(
name = "bidi-schema-tests",
size = "small",
args = ["./*_test.mjs"],
chdir = package_name(),
data = [
"bidi_schema_diff_test.mjs",
"extract_bidi_anchors.mjs",
"normalize_bidi_ast.mjs",
"normalize_bidi_ast_test.mjs",
"project_bidi_schema.mjs",
"project_bidi_schema_test.mjs",
":create-bidi-src_ast",
":create-bidi-src_schema",
":node_modules/cddl2ts",
":node_modules/mocha",
],
)
# Generate WebDriver BiDi TypeScript modules from CDDL specification.
# extra_cddl_files are parsed alongside the primary BiDi spec so that adjacent specs
# (Permissions, Prefetch, UA Client Hints, Web Bluetooth) are included.
generate_bidi_library(
name = "create-bidi-src",
cddl_file = "@webdriver_bidi_all_cddl//file:spec.cddl",
# One webref definition index per merged spec above; the schema step joins them by
# type name to attach a `specHref` link to each type's definition in the live spec.
dfns_files = [
"@webdriver_bidi_dfns//file:dfns.json",
"@permissions_dfns//file:dfns.json",
"@prefetch_dfns//file:dfns.json",
"@ua_client_hints_dfns//file:dfns.json",
"@web_bluetooth_dfns//file:dfns.json",
],
enhancements_manifest = "//javascript/selenium-webdriver/private:bidi_enhancements_manifest",
extra_cddl_files = [
"@permissions_all_cddl//file:spec.cddl",
"@prefetch_all_cddl//file:spec.cddl",
"@ua_client_hints_all_cddl//file:spec.cddl",
"@web_bluetooth_all_cddl//file:spec.cddl",
],
# The local #1140 extension point (supersedes the upstream closed InstallParameters): spec-
# shaped and browser-neutral, it only opens the map. Stays in the shared schema.
override_cddl_files = [
"//common/bidi:webdriver-bidi-1140.cddl",
],
# The pinned rendered core spec. The schema step extracts its prose section anchors
# (#type-/#command-/#event-/#module-) to upgrade type links and add command/event/
# domain links; adjacent specs keep the webref CDDL fallback.
spec_html = "@webdriver_bidi_spec_html//file:index.html",
spec_version = "1.0",
# Firefox's vendor fields plugged into that extension point. Provenance-tagged and routed into
# the schema's separate `vendor` section, so the shared schema stays exactly what upstream emits.
vendor_cddl_files = [
"//common/bidi:webextension-install-extensions.cddl",
],
)
VERSION = "4.49.0-nightly202608272014"
BROWSER_VERSIONS = [
"v152",
"v150",
"v151",
]
js_library(
name = "prod-src-files",
srcs = [
"CHANGES.md",
"README.md",
"package.json",
] + glob([
"*.js",
"example/*.js",
"http/*.js",
"io/*.js",
"lib/*.js",
"lib/fedcm/*.js",
"net/*.js",
"remote/*.js",
"testing/*.js",
"devtools/*.js",
"common/*.js",
"bidi/*.js",
"bidi/external/*.js",
"bidi/serialization/*.js",
]),
deps = [
":node_modules/@bazel/runfiles",
":node_modules/jszip",
":node_modules/tmp",
":node_modules/ws",
],
)
npm_package(
name = "selenium-webdriver",
srcs = [
":create-bidi-src",
":license",
":manager-linux",
":manager-macos",
":manager-notice",
":manager-sbom",
":manager-windows",
":prod-src-files",
"//javascript/selenium-webdriver/lib/atoms:bidi-mutation-listener",
"//javascript/selenium-webdriver/lib/atoms:find-elements",
"//javascript/selenium-webdriver/lib/atoms:get_attribute",
"//javascript/selenium-webdriver/lib/atoms:is_displayed",
"//javascript/selenium-webdriver/lib/atoms:mutation-listener",
],
package = "selenium-webdriver",
publishable = True,
tags = [
"release-artifact",
],
version = VERSION,
visibility = ["//visibility:public"],
)
pkg_tar(
name = "selenium-webdriver.tgz",
srcs = [
":selenium-webdriver",
],
out = "selenium-webdriver-%s.tgz" % VERSION,
extension = "tgz",
package_dir = "package",
strip_prefix = "selenium-webdriver",
)
SMALL_TESTS = [
"test/bidi/domain_test.js",
"test/bidi/index_test.js",
"test/bidi/serialization/record_test.js",
"test/bidi/serialization/union_test.js",
"test/bidi/serialization/wire_contract_test.js",
"test/io/io_test.js",
"test/io/zip_test.js",
"test/lib/bidi_connection_test.js",
"test/lib/by_test.js",
"test/lib/credentials_test.js",
"test/lib/error_test.js",
"test/lib/http_test.js",
"test/lib/input_test.js",
"test/lib/logging_test.js",
"test/lib/promise_test.js",
"test/lib/until_test.js",
"test/lib/virtualauthenticatoroptions_test.js",
"test/lib/webdriver_test.js",
"test/net/index_test.js",
"test/net/portprober_test.js",
]
LARGE_TESTS = glob(
["test/**/*_test.js"],
exclude = SMALL_TESTS,
)
js_library(
name = "small-test-srcs",
srcs = SMALL_TESTS,
)
js_library(
name = "large-test-srcs",
srcs = LARGE_TESTS,
)
js_library(
name = "test-data",
srcs = glob(
[
"lib/test/**",
"test/**",
],
exclude = [
"test/**/*_test.js",
],
),
deps = [
":node_modules/@bazel/runfiles",
],
)
mocha_test(
name = "small-tests",
size = "small",
args = ["./**/*test.js"],
chdir = package_name(),
data = [
":node_modules/@bazel/runfiles",
":node_modules/mocha",
":node_modules/mocha-junit-reporter",
":node_modules/sinon",
":node_modules/ws",
":small-test-srcs",
":test-data",
"//:node_modules/selenium-webdriver",
"//common/extensions:js-lib",
"//common/src/web:js-lib",
],
)
[
[
mocha_test(
name = "%s-%s" % (
test.replace("/", "-").replace("_", "-"),
browser,
),
size = "large",
args = [
"--retries",
"1",
test,
],
chdir = package_name(),
data = [
":large-test-srcs",
":node_modules/express",
":node_modules/mocha",
":node_modules/mocha-junit-reporter",
":node_modules/multer",
":node_modules/serve-index",
":node_modules/sinon",
":test-data",
"//:node_modules/selenium-webdriver",
"//common/extensions:js-lib",
"//common/src/web:js-lib",
] + BROWSERS[browser]["data"],
env = {
"SELENIUM_BROWSER": browser,
} | BROWSERS[browser]["env"],
tags = [
browser,
"browser-test",
"no-sandbox",
"requires-network",
],
),
]
for test in LARGE_TESTS
for browser in BROWSERS.keys()
]
# npm_package does not pick up filegroup sources.
genrule(
name = "license",
srcs = ["//:license"],
outs = [
"LICENSE",
"NOTICE",
],
cmd = "cp $(locations //:license) $(@D)",
)
copy_file(
name = "manager-linux",
src = "//common/manager:selenium-manager-linux",
out = "bin/linux/selenium-manager",
)
copy_file(
name = "manager-macos",
src = "//common/manager:selenium-manager-macos",
out = "bin/macos/selenium-manager",
)
copy_file(
name = "manager-windows",
src = "//common/manager:selenium-manager-windows",
out = "bin/windows/selenium-manager.exe",
)
copy_file(
name = "manager-sbom",
src = "//common/manager:selenium-manager-sbom",
out = "bin/selenium-manager.cdx.json",
)
copy_file(
name = "manager-notice",
src = "//common/manager:selenium-manager-notice",
out = "bin/selenium-manager-THIRD-PARTY-NOTICES.txt",
)
copy_to_bin(
name = "package-json",
srcs = ["package.json"],
)
eslint_bin.eslint_test(
name = "eslint-test",
chdir = package_name(),
data = [
":eslint-config",
":node_modules/@eslint/js",
":node_modules/eslint-plugin-mocha",
":node_modules/eslint-plugin-n",
":node_modules/eslint-plugin-no-only-tests",
":node_modules/eslint-plugin-prettier",
":node_modules/globals",
":node_modules/jszip",
":node_modules/mocha",
":node_modules/tmp",
":node_modules/ws",
":package-json",
":prod-src-files",
],
tags = [
"lint",
"skip-rbe",
],
)
copy_to_bin(
name = "eslint-config",
srcs = ["eslint.config.js"],
)
prettier_bin.prettier_test(
name = "prettier-test",
args = [
".",
"--check",
"--ignore-unknown",
"--config=.prettierrc",
],
chdir = package_name(),
data = [
":large-test-srcs",
":prettier-config",
":prettier-ignore",
":prod-src-files",
":small-test-srcs",
],
tags = [
"lint",
"skip-rbe",
],
)
copy_to_bin(
name = "prettier-config",
srcs = [".prettierrc"],
)
copy_to_bin(
name = "prettier-ignore",
srcs = [".prettierignore"],
)
_ESLINT_DATA = [
":eslint-config",
":large-test-srcs",
":node_modules/@eslint/js",
":node_modules/eslint-plugin-mocha",
":node_modules/eslint-plugin-n",
":node_modules/eslint-plugin-no-only-tests",
":node_modules/eslint-plugin-prettier",
":node_modules/globals",
":node_modules/jszip",
":node_modules/tmp",
":node_modules/ws",
":package-json",
":prod-src-files",
":small-test-srcs",
]
# Eslint binary with auto-fix support: bazel run //javascript/selenium-webdriver:eslint -- --fix .
eslint_bin.eslint_binary(
name = "eslint",
chdir = package_name(),
data = _ESLINT_DATA,
)
# Internal jsdoc binary from npm - used by the docs rule
jsdoc_bin.jsdoc_binary(
name = "jsdoc_bin",
visibility = ["//visibility:private"],
)
# Documentation generator that wraps jsdoc and handles:
# - Output to workspace build directory
# - Ignoring jsdoc type warning exit codes
jsdoc(
name = "docs",
config = "jsdoc_conf.json",
data = [
":node_modules/clean-jsdoc-theme",
":prod-src-files",
],
jsdoc_binary = ":jsdoc_bin",
)