defs
Public API re-exports
Macros and Functions
cypress_test
cypress_test runs the cypress CLI with the cypress toolchain.
The environment is bootstrapped by first setting the environment variable CYPRESS_RUN_BINARY
to the binary downloaded by the cypress toolchain. See https://docs.cypress.io/guides/references/advanced-installation#Run-binary
See documentation on what arguments the cypress CLI supports: https://docs.cypress.io/guides/guides/command-line#What-you-ll-learn
Example usage (generated):
load("@aspect_rules_cypress//cypress:defs.bzl", "cypress_test")
cypress_test(
# The name used for this rule and output files
name = "",
)
name
Required.
The name used for this rule and output files
cypress
Optional. Default: "//:node_modules/cypress"
The cypress npm package which was already linked using an API like npm_link_all_packages.
disable_sandbox
Optional. Default: True
Turn off sandboxing by default to allow electron to perform write operations. Cypress does not expose the underlying electron apis so we cannot alter the user app data directory to be within the bazel sandbox.
From https://www.electronjs.org/docs/latest/api/app appData Per-user application data directory, which by default points to: %APPDATA% on Windows $XDG_CONFIG_HOME or ~/.config on Linux ~/Library/Application Support on macOS
Cypress may fail to connect on macos with errors like: Timed out waiting for the browser to connect. Retrying... Timed out waiting for the browser to connect. Retrying again... The browser never connected. Something is wrong. The tests cannot run. Aborting...
browsers
Optional. Default: []
A sequence of labels specifying the browsers to include. Usually, any dependency that you wish to be included in the runfiles tree should be included within the data attribute. However, data dependencies, by default, are copied to the Bazel output tree before being passed as inputs to runfiles.
This is not a good default behavior for browser since these typically come from external workspaces which cannot be symlinked into bazel-bin. Instead, we place them at the root of the runfiles tree. Use relative paths to construct account for this placement
e.g. ../../../BROWSER_WORKSPACE_NAME
kwargs
Optional.
All other args from js_test
. See https://github.com/aspect-build/rules_js/blob/main/docs/js_binary.md#js_test
cypress_module_test
cypress_module_test creates a node environment which is hooked up to the cypress toolchain.
The environment is bootstrapped by first setting the environment variable CYPRESS_RUN_BINARY
to the binary downloaded by the cypress toolchain. See https://docs.cypress.io/guides/references/advanced-installation#Run-binary
You will provide a test runner, via the runner attribute, which is expected to call into cypress's module API to bootstrap testing.
Example runner.js
:
async function main() {
const result = await cypress.run({
headless: true,
});
// If any tests have failed, results.failures is non-zero, some tests have failed
if (result.failures) {
console.error("One or more cypress tests have failed");
console.error(result.message);
return 1;
}
if (result.status === "failed") {
console.log("Cypress exited with a failure status");
return 2;
}
return 0;
}
In most scenarios, it is easier to use cypress_test. But in some scenarios, you may need more flexibility:
- Accessing to the test results directly after the run and do something with them.
- Reruning a failing spec file
- Kicking off other builds or scripts
Example usage (generated):
load("@aspect_rules_cypress//cypress:defs.bzl", "cypress_module_test")
cypress_module_test(
# The name used for this rule and output files
name = "",
# JS file to call into the cypress module api
runner = None,
)
name
Required.
The name used for this rule and output files
runner
Required.
JS file to call into the cypress module api See https://docs.cypress.io/guides/guides/module-api
cypress
Optional. Default: "//:node_modules/cypress"
The cypress npm package which was already linked using an API like npm_link_all_packages.
disable_sandbox
Optional. Default: True
Turn off sandboxing by default to allow electron to perform write operations. Cypress does not expose the underlying electron apis so we cannot alter the user app data directory to be within the bazel sandbox.
From https://www.electronjs.org/docs/latest/api/app appData Per-user application data directory, which by default points to: %APPDATA% on Windows $XDG_CONFIG_HOME or ~/.config on Linux ~/Library/Application Support on macOS
Cypress may fail to connect on macos with errors like: Timed out waiting for the browser to connect. Retrying... Timed out waiting for the browser to connect. Retrying again... The browser never connected. Something is wrong. The tests cannot run. Aborting...
browsers
Optional. Default: []
A sequence of labels specifying the browsers to include. Usually, any dependency that you wish to be included in the runfiles tree should be included within the data attribute. However, data dependencies, by default, are copied to the Bazel output tree before being passed as inputs to runfiles.
This is not a good default behavior for browser since these typically come from external workspaces which cannot be symlinked into bazel-bin. Instead, we place them at the root of the runfiles tree. Use relative paths to construct account for this placement
e.g. ../../../BROWSER_WORKSPACE_NAME
kwargs
Optional.
All other args from js_test
. See https://github.com/aspect-build/rules_js/blob/main/docs/js_binary.md#js_test