Skip to content

Commit

Permalink
chore: Support local screenshot testing without applitools or argos
Browse files Browse the repository at this point in the history
  • Loading branch information
sidharthv96 committed Jun 20, 2024
1 parent e8d1818 commit 2f792e3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 25 deletions.
17 changes: 10 additions & 7 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,19 @@ export default eyesPlugin(
}
return launchOptions;
});
addMatchImageSnapshotPlugin(on, config);
// copy any needed variables from process.env to config.env
config.env.useAppli = process.env.USE_APPLI ? true : false;
config.env.useArgos = !!process.env.ARGOS_TOKEN;

// Argos
registerArgosTask(on, config, {
uploadToArgos: !!process.env.CI,
token: process.env.ARGOS_TOKEN,
});

if (config.env.useArgos) {
// Argos
registerArgosTask(on, config, {
uploadToArgos: !!process.env.CI,
token: process.env.ARGOS_TOKEN,
});
} else {
addMatchImageSnapshotPlugin(on, config);
}
// do not forget to return the changed config object!
return config;
},
Expand Down
30 changes: 16 additions & 14 deletions cypress/helpers/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,8 @@ export const openURLAndVerifyRendering = (
options: CypressMermaidConfig,
validation?: any
): void => {
const useAppli: boolean = Cypress.env('useAppli');
const name: string = (options.name || cy.state('runnable').fullTitle()).replace(/\s+/g, '-');

if (useAppli) {
cy.log(`Opening eyes ${Cypress.spec.name} --- ${name}`);
cy.eyesOpen({
appName: 'Mermaid',
testName: name,
batchName: Cypress.spec.name,
batchId: batchId + Cypress.spec.name,
});
}

cy.visit(url);
cy.window().should('have.property', 'rendered', true);
cy.get('svg').should('be.visible');
Expand All @@ -116,15 +105,28 @@ export const openURLAndVerifyRendering = (
cy.get('svg').should(validation);
}

cy.argosScreenshot(name);
verifyScreenshot(name);
};

export const verifyScreenshot = (name: string): void => {
const useAppli: boolean = Cypress.env('useAppli');
const useArgos: boolean = Cypress.env('useArgos');

if (useAppli) {
cy.log(`Opening eyes ${Cypress.spec.name} --- ${name}`);
cy.eyesOpen({
appName: 'Mermaid',
testName: name,
batchName: Cypress.spec.name,
batchId: batchId + Cypress.spec.name,
});
cy.log(`Check eyes ${Cypress.spec.name}`);
cy.eyesCheckWindow('Click!');
cy.log(`Closing eyes ${Cypress.spec.name}`);
cy.eyesClose();
} else if (useArgos) {
cy.argosScreenshot(name);
} else {
// Argos will take care of this
// cy.matchImageSnapshot(name);
cy.matchImageSnapshot(name);
}
};
8 changes: 4 additions & 4 deletions cypress/integration/other/configuration.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { renderGraph } from '../../helpers/util.ts';
import { renderGraph, verifyScreenshot } from '../../helpers/util.ts';
describe('Configuration', () => {
describe('arrowMarkerAbsolute', () => {
it('should handle default value false of arrowMarkerAbsolute', () => {
Expand Down Expand Up @@ -120,7 +120,7 @@ describe('Configuration', () => {
cy.visit(url);
cy.window().should('have.property', 'rendered', true);
cy.get('svg').should('be.visible');
cy.matchImageSnapshot(
verifyScreenshot(
'configuration.spec-should-not-taint-initial-configuration-when-using-multiple-directives'
);
});
Expand All @@ -145,7 +145,7 @@ describe('Configuration', () => {
// none of the diagrams should be error diagrams
expect($svg).to.not.contain('Syntax error');
});
cy.matchImageSnapshot(
verifyScreenshot(
'configuration.spec-should-not-render-error-diagram-if-suppressErrorRendering-is-set'
);
});
Expand All @@ -162,7 +162,7 @@ describe('Configuration', () => {
// some of the diagrams should be error diagrams
expect($svg).to.contain('Syntax error');
});
cy.matchImageSnapshot(
verifyScreenshot(
'configuration.spec-should-render-error-diagram-if-suppressErrorRendering-is-not-set'
);
});
Expand Down

0 comments on commit 2f792e3

Please sign in to comment.