Cypress rules for Bazel
The Cypress rules run tests under the Cypress e2e testing framework with Bazel.
Installation
Add @bazel/cypress
and cypress
npm packages to your devDependencies
in package.json
.
npm install --save-dev @bazel/cypress cypress
or using yarn
yarn add -D @bazel/cypress cypress
Then, load and invoke cypress_repository
within your WORKSPACE
file.
load("@npm//@bazel/cypress:index.bzl", "cypress_repository")
cypress_repository(name = "cypress")
macOS install requirements
On macOS, cypress_repository
generates an external repository containing files whose names contain spaces. In order to make these files compatible with bazel you will need to add the following flag to your .bazelrc
file:
build --experimental_inprocess_symlink_creation
windows install requirements
At this point in time, cypress_repository
is incompatible with bazel sandboxing on Windows. This may change in the future, but for now using cypress on windows requires windows sandboxing be disabled (it is disabled by default)
Example use of cypress_web_test
This example assumes you've named your external repository for node_modules as npm
and for cypress as cypress
load("@cypress//:index.bzl", "cypress_web_test")
load("@npm//@bazel/typescript:index.bzl", "ts_library")
ts_library(
name = "plugins_file",
testonly = True,
srcs = ["plugin.ts"],
tsconfig = ":tsconfig.json",
deps = [
"@npm//@types/node",
"@npm//express",
],
)
ts_library(
name = "hello_spec",
testonly = True,
srcs = ["hello.spec.ts"],
tsconfig = ":tsconfig.json",
deps = [
"@npm//cypress",
],
)
cypress_web_test(
name = "test",
srcs = [
"world.spec.js",
":hello_spec",
],
config_file = "cypress.json",
data = [],
plugins_file = ":plugins_file",
)
cypress_repository
USAGE
cypress_repository(name, cypress_bin, fail_on_error, quiet, repo_mapping)
ATTRIBUTES
name
(Name, mandatory): A unique name for this repository.
cypress_bin
(Label): bazel target of the cypress binary
Defaults to @npm//:node_modules/cypress/bin/cypress
fail_on_error
(Boolean): If the repository rule should allow errors
Defaults to True
quiet
(Boolean): If stdout and stderr should be printed to the terminal
Defaults to True
repo_mapping
(Dictionary: String -> String, mandatory): A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.
For example, an entry "@foo": "@bar"
declares that, for any time this repository depends on @foo
(such as a dependency on @foo//some:target
, it should actually resolve that dependency within globally-declared @bar
(@bar//some:target
).