sealights-cypress-plugin
sealights-cypress-plugin is a custom plugin for the Cypress testing framework that enhances your testing capabilities by providing additional support for various tasks and configurations.
This plugin adds support for Sealights, reporting coverage and test skipping as well.
Supported Node / Cypress versions
Features
-
Support File: The plugin introduces a support file, it is automatically loaded before each test, providing a centralized location to manage the Sealights information and execute the required hooks
-
Config File: The config file empowers the Cypress tests run by adding the required tasks and communicates with Sealights
Installation
To use sealights-cypress-plugin in your Cypress project, follow these steps:
-
Install and Setup Cypress if you haven't already:
npm install cypress --save-dev
-
Install the plugin from GitHub/npm
npm install sealights-cypress-plugin
Cypress v10+
In your cypress.config.js
register the plugin:
const { defineConfig } = require('cypress');
const { registerSealightsTasks } = require('sealights-cypress-plugin');
module.exports = defineConfig({
e2e: {
experimentalInteractiveRunEvents: true,
testIsolation: false,
setupNodeEvents(on, config) {
registerSealightsTasks(on, config);
},
},
});
Add to your cypress/support/e2e.js
:
import 'sealights-cypress-plugin/support';
Cypress v9
Add to your cypress/plugins/index.js file
const { registerSealightsTasks } = require('sealights-cypress-plugin');
module.exports = (on, config) => {
registerSealightsTasks(on, config);
return config;
};
Add to your cypress/support/index.js
file
import 'sealights-cypress-plugin/support';
Configuration
Minimal configuration
In order for the Sealights integration to work, three parameters have to be exported to the Cypress config.
This can be done using environment variables and exposing them to Cypress. The three environment variables are:
SL_BUILD_SESSION_ID // this or labId
SL_LAB_ID // this or buildSessionId
SL_TOKEN
SL_TEST_STAGE
Additionally you can configure a proxy:
SL_PROXY=
For them to be available to Cypress, they have to be prefixed with CYPRESS_
, for example:
export CYPRESS_SL_TOKEN={token}
export CYPRESS_SL_BUILD_SESSION_ID={buildSessionId}
export CYPRESS_SL_LAB_ID={labId}
export CYPRESS_SL_TEST_STAGE={your-test-stage}
export CYPRESS_SL_PROXY={your-proxy}
More about defining the environment variables in Cypress at the following link:
https://docs.cypress.io/guides/guides/environment-variables
Using remote-agent version
The primary goal of this implementation is to significantly reduce load times and test execution times, especially in scenarios where there are repeated page reloads. We aim to achieve this by providing an alternative method for skipping the download of our browser agent and use a remote-agent implementation instead.
To enable this feature please set the following Environment Variable:
export CYPRESS_SL_ENABLE_REMOTE_AGENT=true
One additional change that has to be done in this case is in the Cypress config file:
async setupNodeEvents(on, config) {
await registerSealightsTasks(on, config);
}
Using a collector
The primary goal of this implementation is to reduce load times and test execution times. A collector can reduce the time by taking the sl-mapping part from the remote-agent and taking care of it instead. This feature is only supported when using remote-agent.
To enable this feature please set the following Environment Variable:
export CYPRESS_SL_COLLECTOR_URL={your-collector-url}
Using per-spec-file reporting
In this mode the test events are reported at the end of each spec file and each spec is considered
a single test. If a test belonging to the spec failed, the spec will be marked as failed as well.
The reported test names are equal to the spec name.
In this mode TIA is disabled by default because there are no separate tests being reported to Sealights.
It is up to the user to decide which spec files to run before initiating Cypress run.
export CYPRESS_SL_PER_FILE_REPORTING=true
Exporting generated coverage to files
This feature once enabled will store all generated coverage content to files in a predefined
path.
export CYPRESS_SL_EXPORT_COVERAGE_PATH=$PWD // or any other path
The plugin will create a directory sl-coverage-files
in the specified path and store the coverage files in JSON format.
In this mode the generated footprints file for the coverage will be dropped and not forwarded to Sealights.
export CYPRESS_SL_DROP_FOOTPRINTS=true // default: false
Using the Plugins API (events) instead of Life Cycle hooks
Using the Plugins API for Cypress will use the following events instead of using Life cycle hooks:
Cypress event | Usage |
---|
before:run | Start the test session |
after:run | End the test session |
Be careful when enabling this mode, Cypress has an ongoing issues (https://github.com/cypress-io/cypress/issues/19809) which prevents
plugins to register the same event.
Meaning if a plugin before Sealights subscribed to the same events (the ones from the table above), our event handlers will not fire and vice-versa.
If you still want to opt in for this mode and use multiple plugins registering the same events
you will need to use the suggested module in the issue thread above: cypress-on-fix or similar fix.
export CYPRESS_SL_ENABLE_PLUGINS_API=true // default: false