Optimising build duration in Cypress v10+
Improve the build duration of Cypress v10+ builds through smarter NPM dependency management.
The BrowserStack Cypress CLI reads the cypress config file for config validation and resource assignment when executing Cypress tests on BrowserStack.
With Cypress version 10 and above, the config file changes from cypress.json
to cypress.config.js/.ts/.cjs/.mjs
. Reading the cypress.config.js/.ts/.cjs/.mjs
file requires the installation of NPM dependencies defined in the file. This installation leads to increased build execution time even though BrowserStack caches all your NPM dependencies to save running npm install again.
To address this issue in Cypress version 10 and above, BrowserStack introduced the enforce_settings
key within the browserstack.json
file. Activating this key allows configurations such as specPattern
, baseURL
, video
, and videoUploadOnPasses
for validation to be fetched from browserstack.json
(Table 2), bypassing the need to read them from the cypress.config.js
file. Consequently, this modification prevents the unnecessary installation of NPM dependencies from Cypress config file, thereby reducing build time on BrowserStack.
The enforce_settings
feature is available from BrowserStack CLI version 1.27
onwards.
Table 1: Details of the enforce_settings
key:
Key | Accepted Values | Description |
---|---|---|
enforce_settings |
true , false (default false ) |
Determines whether to fetch configurations (Table 2) from browserstack.json or cypress.config.js . When the key is: - Not Defined or False in browserstack.json : The Cypress test execution follows the existing flow, reading configurations from the cypress.config.js .- Set to True in browserstack.json : Configurations from Table 2 are fetched from browserstack.json instead of the cypress.config.js . |
When enforce_settings
is set to true
in browserstack.json
, it reads the following configurations from the browserstack.json
file instead of the cypress.config.js
file. Ensure to set the below capabilities in your browserstack.json
file:
Table 2: Configurations read from browserstack.json
Key | Value | Cypress Config Equivalent |
---|---|---|
specs (mandatory) |
Array of patterns (file paths or regexes) that match the spec files to run. An error occurs if not defined with enforce_settings as true . |
specPattern |
baseUrl (optional) |
URL used as a prefix for cy.visit() or cy.request() commands’ URLs. |
baseUrl |
video (optional) |
true (default). Determines if Cypress captures a video of the test runs. |
video |
videoUploadOnPasses (optional) |
true (default). When turned off, only compresses and uploads videos on failures. Applicable only for Cypress 12 and below. |
videoUploadOnPasses |
Example of setting the enforce_settings
key in the browserstack.json
file:
For a detailed guide on defining these keys in browserstack.json
, refer to Capabilities-BrowserStack.
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
- RESOURCES
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
Thank you for your valuable feedback!