blob: 2def22e1388982f02b78eaa9a248b0f61b20f710 [file] [edit]
load("@aspect_bazel_lib//lib:jq.bzl", "jq")
load("@aspect_rules_js//js:defs.bzl", "js_binary", "js_library", "js_test")
load("@aspect_rules_js//npm:defs.bzl", "npm_package")
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("@rules_closure//closure:defs.bzl", "closure_js_library")
load("//:version.bzl", "VERSIONS")
load("//javascript:defs.bzl", "closure_js_deps", "closure_test_suite")
load("//javascript/atoms:typescript/defs.bzl", "ATOMS", "typescript_atom")
package(default_visibility = ["//visibility:public"])
VERSION = VERSIONS["javascript"]
# These build tools are CommonJS; the .cjs extension keeps that true regardless
# of the "type": "module" declared by the @selenium/atoms package.json above
# them in this directory.
js_binary(
name = "wrap_as_global",
data = ["typescript/wrap-as-global.cjs"],
entry_point = "typescript/wrap-as-global.cjs",
)
js_library(
name = "esbuild-atom-config",
srcs = ["typescript/esbuild.atom.config.mjs"],
)
write_file(
name = "atom-registry",
out = "typescript/atoms.json",
content = [json.encode(ATOMS)],
)
# Adding an atom without extending the published surface is the drift this
# guards against; the failure prints the blocks to paste into package.json.
js_test(
name = "exports-up-to-date",
data = [
"package.json",
":atom-registry",
],
entry_point = "typescript/generate-exports.cjs",
fixed_args = [
"$(rootpath :atom-registry)",
"$(rootpath package.json)",
"--check",
],
)
# Every atom can reach every shared module, so the bundler gets the whole set
# and tree-shakes down to what each entry point actually imports.
ATOM_SRCS = glob([
"typescript/*.ts",
"typescript/core/**/*.ts",
])
# ── the atoms ────────────────────────────────────────────────────────────────
[
typescript_atom(
name = atom["name"],
srcs = ATOM_SRCS,
global_name = atom["global"],
)
for atom in ATOMS
]
# Node consumers run each atom's body when they load it: selenium-webdriver's
# lib/http.js require()s its atoms at import time, and npm consumers import the
# barrel. An atom that touches a DOM global while loading breaks both.
js_test(
name = "atoms-load-in-node",
data = [
"package.json",
":atoms-npm-compiled",
] + [":typescript/%s.generated.js" % atom["name"] for atom in ATOMS],
entry_point = "typescript/load-in-node.mjs",
fixed_args = ["javascript/atoms/dist/index.js"] + [
"$(rootpath :typescript/%s.generated.js)" % atom["name"]
for atom in ATOMS
],
)
# The pure parts of the accessibility modules (the reference text renderer)
# run in Node against the test-only bundle, with no browser.
js_test(
name = "accessibility-unit-tests",
size = "small",
data = [
":typescript/accessibility-snapshot.generated.js",
":typescript/accessibility-snapshot-wire.generated.js",
":typescript/testing/accessibility.generated.js",
],
entry_point = "typescript/testing/accessibility-unit-tests.mjs",
fixed_args = [
"$(rootpath :typescript/testing/accessibility.generated.js)",
"$(rootpath :typescript/accessibility-snapshot.generated.js)",
"$(rootpath :typescript/accessibility-snapshot-wire.generated.js)",
],
)
# The shared accessibility corpus is the cross-binding contract: every
# expectation validates against the node schema and every text file is the
# renderer's output over its JSON, so a removed or renamed field fails here
# before any binding sees it.
js_test(
name = "accessibility-corpus-consistent",
size = "small",
data = [
"typescript/accessibility-node.schema.json",
":typescript/testing/accessibility.generated.js",
"//common/src/web:accessibility-corpus",
],
entry_point = "typescript/testing/corpus-consistent.mjs",
fixed_args = [
"common/src/web/accessibility",
"$(rootpath typescript/accessibility-node.schema.json)",
"$(rootpath :typescript/testing/accessibility.generated.js)",
],
)
# ── test-only bundles ────────────────────────────────────────────────────────
# Shared modules that no atom reaches yet still need a QUnit page. Each entry
# under typescript/testing/ default-exports what its page drives. These are not
# in ATOMS, so they are never published and never reach a binding.
TEST_BUNDLES = {
"accessibility": "bot.accessibility.typescript.testing",
"events": "bot.events.typescript",
"keyboard": "bot.keyboard.typescript",
"mouse": "bot.mouse.typescript",
}
# Every test-only module is a source of every test bundle: esbuild resolves
# imports only among the sources it is given, and a bundle's entry may import
# a sibling (the accessibility bundle imports its text renderer). Only what an
# entry imports ends up in its bundle.
TEST_BUNDLE_SRCS = ATOM_SRCS + glob(["typescript/testing/*.ts"])
[
typescript_atom(
name = "testing/%s" % bundle,
srcs = TEST_BUNDLE_SRCS,
global_name = global_name,
visibility = ["//visibility:private"],
)
for bundle, global_name in TEST_BUNDLES.items()
]
# ── @selenium/atoms npm package ──────────────────────────────────────────────
# esbuild only strips types, so this is also what type-checks the atoms: it is
# the one target that runs tsc over them.
ts_project(
name = "atoms-npm-compiled",
srcs = ["index.ts"] + ATOM_SRCS,
declaration = True,
declaration_map = True,
out_dir = "dist",
source_map = True,
tsconfig = "tsconfig.json",
)
# npm_package does not pick up filegroup sources.
genrule(
name = "license",
srcs = ["//:license"],
outs = [
"LICENSE",
"NOTICE",
],
cmd = "cp $(locations //:license) $(@D)",
)
jq(
name = "package-json-stamped",
srcs = ["package.json"],
out = "stamped/package.json",
filter = '.version = "%s"' % VERSION,
)
npm_package(
name = "selenium-atoms-package",
srcs = [
# README.md in this directory is the contributor guide; the npm page
# gets its own file, renamed into place below.
"README.npm.md",
# Published so the emitted .d.ts.map / .js.map resolve for consumers.
"index.ts",
":atoms-npm-compiled",
":license",
":package-json-stamped",
] + ATOM_SRCS,
package = "@selenium/atoms",
publishable = True,
replace_prefixes = {
"README.npm.md": "README.md",
"stamped/": "",
},
tags = ["release-artifact"],
version = VERSION,
visibility = ["//visibility:public"],
)
filegroup(
name = "atoms",
srcs = glob([
"**/*.cjs",
"**/*.html",
"**/*.jpg",
"**/*.js",
"**/*.png",
"**/*.svg",
"**/*.ts",
]) + [":%s-global" % atom["name"] for atom in ATOMS],
visibility = [
"//dotnet/test:__subpackages__",
"//java/test/org/openqa/selenium/environment:__pkg__",
"//javascript/selenium-webdriver:__pkg__",
],
)
closure_js_library(
name = "action",
srcs = ["action.js"],
suppress = [
"JSC_IMPLICITLY_NULLABLE_JSDOC",
"JSC_STRICT_INEXISTENT_PROPERTY",
"JSC_UNKNOWN_EXPR_TYPE",
"JSC_USE_OF_GOOG_PROVIDE",
],
visibility = [
"//javascript/atoms/fragments:__pkg__",
"//javascript/selenium-atoms:__pkg__",
"//javascript/webdriver/atoms:__pkg__",
"//javascript/webdriver/atoms/inject:__pkg__",
],
deps = [
":bot",
":devices",
":dom",
":errors",
":events",
"//third_party/closure/goog/array",
"//third_party/closure/goog/dom:tagname",
"//third_party/closure/goog/math:coordinate",
"//third_party/closure/goog/math:vec2",
"//third_party/closure/goog/style",
"//third_party/closure/goog/useragent",
"//third_party/closure/goog/useragent:product",
"//third_party/closure/goog/utils",
],
)
closure_js_library(
name = "bot",
srcs = ["bot.js"],
suppress = [
"JSC_USE_OF_GOOG_PROVIDE",
],
)
closure_js_library(
name = "color",
srcs = ["color.js"],
suppress = [
"JSC_USE_OF_GOOG_PROVIDE",
],
deps = [
"//third_party/closure/goog/array",
"//third_party/closure/goog/color:names",
],
)
closure_js_library(
name = "devices",
srcs = [
"device.js",
"keyboard.js",
"mouse.js",
"touchscreen.js",
],
suppress = [
"JSC_IMPLICITLY_NULLABLE_JSDOC",
"JSC_STRICT_INEXISTENT_PROPERTY",
"JSC_UNKNOWN_EXPR_TYPE",
"JSC_USE_OF_GOOG_PROVIDE",
],
deps = [
":bot",
":dom",
":errors",
":events",
":locators",
":useragent",
"//third_party/closure/goog/array",
"//third_party/closure/goog/dom",
"//third_party/closure/goog/dom:selection",
"//third_party/closure/goog/dom:tagname",
"//third_party/closure/goog/math:coordinate",
"//third_party/closure/goog/structs:map",
"//third_party/closure/goog/structs:set",
"//third_party/closure/goog/useragent",
"//third_party/closure/goog/useragent:product",
"//third_party/closure/goog/utils",
],
)
closure_js_library(
name = "domcore",
srcs = ["domcore.js"],
suppress = [
"JSC_IMPLICITLY_NULLABLE_JSDOC",
"JSC_STRICT_INEXISTENT_PROPERTY",
"JSC_UNKNOWN_EXPR_TYPE",
"JSC_USE_OF_GOOG_PROVIDE",
],
deps = [
":errors",
":useragent",
"//third_party/closure/goog/array",
"//third_party/closure/goog/dom",
"//third_party/closure/goog/dom:nodetype",
"//third_party/closure/goog/dom:tagname",
],
)
closure_js_library(
name = "dom",
srcs = ["dom.js"],
suppress = [
"JSC_DEPRECATED_PROP",
"JSC_IMPLICITLY_NULLABLE_JSDOC",
"JSC_STRICT_INEXISTENT_PROPERTY",
"JSC_UNKNOWN_EXPR_TYPE",
"JSC_USE_OF_GOOG_PROVIDE",
],
deps = [
":bot",
":color",
":css",
":domcore",
":json",
":useragent",
"//third_party/closure/goog/array",
"//third_party/closure/goog/dom",
"//third_party/closure/goog/dom:nodetype",
"//third_party/closure/goog/dom:tagname",
"//third_party/closure/goog/math",
"//third_party/closure/goog/math:coordinate",
"//third_party/closure/goog/math:rect",
"//third_party/closure/goog/string",
"//third_party/closure/goog/style",
"//third_party/closure/goog/useragent",
],
)
closure_js_library(
name = "errors",
srcs = [
"error.js",
"response.js",
],
suppress = [
"JSC_IMPLICITLY_NULLABLE_JSDOC",
"JSC_STRICT_INEXISTENT_PROPERTY",
"JSC_UNKNOWN_EXPR_TYPE",
"JSC_USE_OF_GOOG_PROVIDE",
],
deps = [
"//third_party/closure/goog/utils",
],
)
closure_js_library(
name = "events",
srcs = ["events.js"],
suppress = [
"JSC_IMPLICITLY_NULLABLE_JSDOC",
"JSC_STRICT_INEXISTENT_PROPERTY",
"JSC_UNKNOWN_EXPR_TYPE",
"JSC_USE_OF_GOOG_PROVIDE",
],
deps = [
":bot",
":dom",
":errors",
":json",
":useragent",
"//third_party/closure/goog/array",
"//third_party/closure/goog/dom",
"//third_party/closure/goog/events:browserevent",
"//third_party/closure/goog/style",
"//third_party/closure/goog/useragent",
"//third_party/closure/goog/useragent:product",
"//third_party/closure/goog/utils",
],
)
closure_js_library(
name = "frame",
srcs = ["frame.js"],
suppress = [
"JSC_IMPLICITLY_NULLABLE_JSDOC",
"JSC_UNKNOWN_EXPR_TYPE",
"JSC_USE_OF_GOOG_PROVIDE",
],
visibility = [
"//javascript/webdriver/atoms/inject:__pkg__",
],
deps = [
":bot",
":dom",
":errors",
":locators",
"//third_party/closure/goog/dom",
"//third_party/closure/goog/dom:tagname",
],
)
closure_js_library(
name = "html5",
srcs = glob(["html5/*.js"]),
suppress = [
"JSC_IMPLICITLY_NULLABLE_JSDOC",
"JSC_UNKNOWN_EXPR_TYPE",
"JSC_USE_OF_GOOG_PROVIDE",
],
deps = [
":bot",
":errors",
":json",
":useragent",
"//third_party/closure/goog/useragent",
"//third_party/closure/goog/useragent:product",
],
)
closure_js_library(
name = "inject",
srcs = ["inject.js"],
suppress = [
"JSC_IMPLICITLY_NULLABLE_JSDOC",
"JSC_STRICT_INEXISTENT_PROPERTY",
"JSC_UNKNOWN_EXPR_TYPE",
"JSC_USE_OF_GOOG_PROVIDE",
],
visibility = [
"//javascript/atoms/fragments:__pkg__",
"//javascript/selenium-atoms:__pkg__",
"//javascript/webdriver/atoms/inject:__pkg__",
],
deps = [
":bot",
":errors",
":json",
"//third_party/closure/goog/array",
"//third_party/closure/goog/dom:nodetype",
"//third_party/closure/goog/object",
"//third_party/closure/goog/useragent",
"//third_party/closure/goog/utils",
],
)
closure_js_library(
name = "json",
srcs = ["json.js"],
suppress = [
"JSC_USE_OF_GOOG_PROVIDE",
],
deps = [
":useragent",
"//third_party/closure/goog/json",
"//third_party/closure/goog/useragent",
],
)
closure_js_library(
name = "locators",
srcs = glob(
["locators/*.js"],
exclude = ["locators/css.js"],
),
suppress = [
"JSC_IMPLICITLY_NULLABLE_JSDOC",
"JSC_LATE_PROVIDE_ERROR",
"JSC_UNKNOWN_EXPR_TYPE",
"JSC_USE_OF_GOOG_PROVIDE",
],
deps = [
":bot",
":css",
":dom",
":errors",
":json",
":useragent",
"//third_party/closure/goog/array",
"//third_party/closure/goog/dom",
"//third_party/closure/goog/dom:nodetype",
"//third_party/closure/goog/dom:tagname",
"//third_party/closure/goog/math:rect",
"//third_party/closure/goog/string",
"//third_party/closure/goog/useragent",
"//third_party/closure/goog/useragent:product",
"//third_party/closure/goog/utils",
],
)
closure_js_library(
name = "useragent",
srcs = ["userAgent.js"],
suppress = [
"JSC_STRICT_INEXISTENT_PROPERTY",
"JSC_UNKNOWN_EXPR_TYPE",
"JSC_USE_OF_GOOG_PROVIDE",
],
deps = [
"//third_party/closure/goog/string",
"//third_party/closure/goog/useragent",
"//third_party/closure/goog/useragent:product",
"//third_party/closure/goog/useragent:product_isversion",
],
)
closure_js_library(
name = "window",
srcs = [
"frame.js",
"window.js",
],
suppress = [
"JSC_USE_OF_GOOG_PROVIDE",
],
deps = [
":bot",
":errors",
":events",
":json",
":locators",
],
)
closure_js_library(
name = "css",
srcs = ["locators/css.js"],
suppress = [
"JSC_IMPLICITLY_NULLABLE_JSDOC",
"JSC_STRICT_INEXISTENT_PROPERTY",
"JSC_UNKNOWN_EXPR_TYPE",
"JSC_USE_OF_GOOG_PROVIDE",
],
deps = [
":bot",
":errors",
":useragent",
"//third_party/closure/goog/dom:nodetype",
"//third_party/closure/goog/string",
"//third_party/closure/goog/useragent",
"//third_party/closure/goog/utils",
],
)
closure_js_library(
name = "test_util",
testonly = 1,
srcs = ["test/test_util.js"],
suppress = [
"JSC_USE_OF_GOOG_PROVIDE",
],
deps = [
":useragent",
],
)
closure_js_deps(
name = "deps",
testonly = True,
visibility = [
"//:__pkg__",
"//java/test/org/openqa/selenium/environment:__pkg__",
"//javascript:__pkg__",
"//javascript/webdriver:__pkg__",
],
deps = [
":action",
":bot",
":color",
":css",
":devices",
":dom",
":domcore",
":errors",
":events",
":html5",
":inject",
":json",
":locators",
":test_util",
":useragent",
":window",
"//third_party/closure/goog:library",
"//third_party/closure/goog:testing",
],
)
closure_test_suite(
name = "closure-test",
data = [
":atoms",
":deps",
# The accessibility corpus pages, loaded by
# test/accessibility_corpus_typescript_test.html.
"//common/src/web",
] + [":testing/%s-global" % bundle for bundle in TEST_BUNDLES],
)