Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Use
cy.task
for health check rather than cy.exec
(BREAKING C…
…HANGE) (#140) BREAKING CHANGE: ## The problem In all of the Percy SDKs we do a thing called a "heath check", which makes sure the Percy agent server is open and ready to accept the DOM we're going to `POST` to it. If the health check fails, we will disable Percy in the SDK so we're not failing your tests due to Percy not running. In the Cypress SDK, this was implemented in an interesting way due a limitation with `cy.request`. The TL:DR of that is we can't `.catch` a failed request, so we needed to use `cy.exec` to health check & gracefully fall out. You can read a little more about that limitation here: cypress-io/cypress#3161 `cy.exec` has it's own issues, which are outlined here: #104 This is a major blocker for _a lot_ of customers. ## What is this? This will fix #104 (and hopefully #138). `cy.task` will always execute within the version of node that is bundled with Cypress, so we no longer have to worry about `$PATH` issues that `cy.exec` faces. We're also no longer running a CLI command for the health check, this new implementation will make a HTTP request from node. This does mean we need to update the docs to let users know there's an extra step to configure the SDK properly now. ### Upgrading to v2.x With this change, you will now need to import this new task into your projects plugins (`cypress/plugins/index.js`) file. Without that, the SDK will not work at all. ```js /// In cypress/plugins/index.js let percyHealthCheck = require('@percy/cypress/task') module.exports = (on, config) => { // `on` is used to hook into various events Cypress emits // `config` is the resolved Cypress config // Make it possible to log things to stdout by calling 'cy.task('log', 'some message to log'). // Useful for development and debugging. on("task", { log(message) { console.log(message); return null; } }); on("task", percyHealthCheck); }; ``` ## In the future In an ideal world we would be able to `.catch` on `cy.request` and disable Percy after the first failed `POST` of the DOM. I think in the future we should look into working with Cypress to implement this so we can shrink the integration, make the SDK more reliable, and faster (since we won't make 2 network requests per-snapshot). ## FAQ #### Why can't you use `fetch` over `cy.request` & `.catch` that? We need to use `cy.request` since those requests aren't actually executed in the browser and avoid any CORS issues. ## TODOs - [x] Update Docs - [x] How can I guarantee semantic release makes this a major version bump - [x] How does one integrate this task into their suite? It's not a default export.. And it runs in node. Maybe it can be apart of the default export
- Loading branch information