From adf695ff7b30fb830a4bc2e03b3a1354ce761cd9 Mon Sep 17 00:00:00 2001 From: Robert DeLuca Date: Wed, 14 Apr 2021 11:14:14 -0500 Subject: [PATCH] :sparkles: Disable Percy when Cypress is in interactive mode --- cypress/integration/index.test.js | 27 +++++++++++++++++++++++++++ index.js | 8 ++++++++ yarn.lock | 2 +- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/cypress/integration/index.test.js b/cypress/integration/index.test.js index 352e1ae..038e8b5 100644 --- a/cypress/integration/index.test.js +++ b/cypress/integration/index.test.js @@ -65,4 +65,31 @@ describe('percySnapshot', () => { '[percy] Error: 500 Internal Server Error' ]); }); + + describe('in interactive mode', () => { + let ogInteractive; + + beforeEach(() => { + ogInteractive = Cypress.config('isInteractive'); + }); + + afterEach(() => { + Cypress.config('isInteractive', ogInteractive); + }); + + it('disables snapshots', () => { + Cypress.config('isInteractive', true); + cy.percySnapshot('Snapshot name'); + + cy.get('@log').should((spy) => { + expect(spy).to.be.calledWith( + match({ + name: 'percySnapshot', + displayName: 'percy', + message: 'Disabled in interactive mode' + }) + ); + }); + }); + }); }); diff --git a/index.js b/index.js index 279e838..860ac5a 100644 --- a/index.js +++ b/index.js @@ -32,6 +32,14 @@ Cypress.Commands.add('percySnapshot', (name, options) => { name = name || cy.state('runnable').fullTitle(); cy.then(async () => { + if (Cypress.config('isInteractive') && + !Cypress.config('enablePercyInteractiveMode')) { + return cylog('Disabled in interactive mode', { + details: 'use "cypress run" instead of "cypress open"', + name + }); + } + // Check if Percy is enabled if (!await utils.isPercyEnabled()) { return cylog('Not running', { name }); diff --git a/yarn.lock b/yarn.lock index 03db9b5..f6609fd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -950,7 +950,7 @@ dependencies: dotenv "^8.2.0" -"@percy/logger@^1.0.0-beta.44", "@percy/logger@^1.0.0-beta.47": +"@percy/logger@^1.0.0-beta.47": version "1.0.0-beta.47" resolved "https://registry.yarnpkg.com/@percy/logger/-/logger-1.0.0-beta.47.tgz#72d91b693b43c59f1cccffdfafec70adc9ffc1a8" integrity sha512-6mDHvIQ8wJCN7dd9bnnKtT/VrE+HBTB+U9C7a7vSakC35DnY4QrxH1sbK4hAO8wc2aw6YR3vepX2w/ZYpeuqnA==