Skip to content

Commit

Permalink
✨ Disable Percy when Cypress is in interactive mode (#321)
Browse files Browse the repository at this point in the history
  • Loading branch information
Robdel12 authored Apr 14, 2021
1 parent 6159ae7 commit 00991d5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
27 changes: 27 additions & 0 deletions cypress/integration/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
})
);
});
});
});
});
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==
Expand Down

0 comments on commit 00991d5

Please sign in to comment.