Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Cypress to v10 and fix E2E errors #3459

Merged
merged 8 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 0 additions & 44 deletions .github/workflows/e2e

This file was deleted.

38 changes: 38 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: E2E

on: [push, pull_request]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aloisklink Se my comment regarding when to trigger

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've deleted the commit adding Applitools to CI, and will create a new PR that adds a e2e-applitool.yml CI action.

The e2e.yml test now doesn't use Applitools, so it's fine to have it run on every push/PR, since GitHub Actions is currently completely free for open-source projects.


permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
steps:
- uses: actions/checkout@v3

- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
cache: yarn
node-version: ${{ matrix.node-version }}

- name: Install Yarn
run: npm i yarn --global

- name: Install Packages
run: |
yarn install --frozen-lockfile
env:
CYPRESS_CACHE_FOLDER: .cache/Cypress

- name: Run Build
run: yarn build

- name: Run E2E Tests
run: yarn e2e
env:
CYPRESS_CACHE_FOLDER: .cache/Cypress
16 changes: 0 additions & 16 deletions applitools.cnfig.js

This file was deleted.

19 changes: 19 additions & 0 deletions applitools.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { defineConfig } = require('cypress');

module.exports = defineConfig({
testConcurrency: 1,
browser: [
// Add browsers with different viewports
// { width: 800, height: 600, name: 'chrome' },
// { width: 700, height: 500, name: 'firefox' },
// { width: 1600, height: 1200, name: 'ie11' },
// { width: 1024, height: 768, name: 'edgechromium' },
// { width: 800, height: 600, name: 'safari' },
// // Add mobile emulation devices in Portrait mode
// { deviceName: 'iPhone X', screenOrientation: 'portrait' },
// { deviceName: 'Pixel 2', screenOrientation: 'portrait' },
],
// set batch name to the configuration
batchName: `Mermaid ${process.env.APPLI_BRANCH ?? "'no APPLI_BRANCH set'"}`,
});
7 changes: 3 additions & 4 deletions cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@

const { defineConfig } = require('cypress');
const { addMatchImageSnapshotPlugin } = require('cypress-image-snapshot/plugin');
require('@applitools/eyes-cypress')(module);

module.exports = defineConfig({
e2e: {
specPattern: 'cypress/e2e/**/*.{js,jsx,ts,tsx}',
specPattern: 'cypress/integration/**/*.{js,jsx,ts,tsx}',
setupNodeEvents(on, config) {
addMatchImageSnapshotPlugin(on, config);
// copy any needed variables from process.env to config.env
config.env.useAppli = process.env.USE_APPLI ? true : false;
config.env.codeBranch = process.env.APPLI_BRANCH;

// do not forget to return the changed config object!
return config;
},
supportFile: 'cypress/support/index.js',
},
video: false,
});

require('@applitools/eyes-cypress')(module);
1 change: 0 additions & 1 deletion cypress/downloads/downloads.html

This file was deleted.

8 changes: 2 additions & 6 deletions cypress/helpers/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,13 @@ export const imgSnapshotTest = (graphStr, _options, api = false, validation) =>
}
const useAppli = Cypress.env('useAppli');
//const useAppli = false;
const branch = Cypress.env('codeBranch');
cy.log('Hello ' + useAppli ? 'Appli' : 'image-snapshot');
const name = (options.name || cy.state('runnable').fullTitle()).replace(/\s+/g, '-');

if (useAppli) {
cy.eyesOpen({
appName: 'Mermaid-' + branch,
appName: 'Mermaid',
testName: name,
batchName: branch,
});
}

Expand Down Expand Up @@ -96,15 +94,13 @@ export const urlSnapshotTest = (url, _options, api = false, validation) => {
options.fontSize = '16px';
}
const useAppli = Cypress.env('useAppli');
const branch = Cypress.env('codeBranch');
cy.log('Hello ' + useAppli ? 'Appli' : 'image-snapshot');
const name = (options.name || cy.state('runnable').fullTitle()).replace(/\s+/g, '-');

if (useAppli) {
cy.eyesOpen({
appName: 'Mermaid-' + branch,
appName: 'Mermaid',
testName: name,
batchName: branch,
});
}

Expand Down
62 changes: 36 additions & 26 deletions cypress/integration/other/configuration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ describe('Configuration', () => {

// Check the marker-end property to make sure it is properly set to
// start with #
cy.get('.edgePath path')
.first()
.should('have.attr', 'marker-end')
.should('exist')
.and('include', 'url(#');
cy.get('.edgePaths').within(() => {
cy.get('path')
.first()
.should('have.attr', 'marker-end')
.should('exist')
.and('include', 'url(#');
});
});
it('should handle default value false of arrowMarkerAbsolute', () => {
renderGraph(
Expand All @@ -35,11 +37,13 @@ describe('Configuration', () => {

// Check the marker-end property to make sure it is properly set to
// start with #
cy.get('.edgePath path')
.first()
.should('have.attr', 'marker-end')
.should('exist')
.and('include', 'url(#');
cy.get('.edgePaths').within(() => {
cy.get('path')
.first()
.should('have.attr', 'marker-end')
.should('exist')
.and('include', 'url(#');
});
});
it('should handle arrowMarkerAbsolute explicitly set to false', () => {
renderGraph(
Expand All @@ -57,11 +61,13 @@ describe('Configuration', () => {

// Check the marker-end property to make sure it is properly set to
// start with #
cy.get('.edgePath path')
.first()
.should('have.attr', 'marker-end')
.should('exist')
.and('include', 'url(#');
cy.get('.edgePaths').within(() => {
cy.get('path')
.first()
.should('have.attr', 'marker-end')
.should('exist')
.and('include', 'url(#');
});
});
it('should handle arrowMarkerAbsolute explicitly set to "false" as false', () => {
renderGraph(
Expand All @@ -79,15 +85,17 @@ describe('Configuration', () => {

// Check the marker-end property to make sure it is properly set to
// start with #
cy.get('.edgePath path')
.first()
.should('have.attr', 'marker-end')
.should('exist')
.and('include', 'url(#');
cy.get('.edgePaths').within(() => {
cy.get('path')
.first()
.should('have.attr', 'marker-end')
.should('exist')
.and('include', 'url(#');
});
});
it('should handle arrowMarkerAbsolute set to true', () => {
renderGraph(
`graph TD
`flowchart TD
A[Christmas] -->|Get money| B(Go shopping)
B --> C{Let me think}
C -->|One| D[Laptop]
Expand All @@ -99,11 +107,13 @@ describe('Configuration', () => {
}
);

cy.get('.edgePath path')
.first()
.should('have.attr', 'marker-end')
.should('exist')
.and('include', 'url(http://localhost');
cy.get('.edgePaths').within(() => {
cy.get('path')
.first()
.should('have.attr', 'marker-end')
.should('exist')
.and('include', 'url(http://localhost');
});
});
it('should not taint the initial configuration when using multiple directives', () => {
const url = 'http://localhost:9000/regression/issue-1874.html';
Expand Down
3 changes: 3 additions & 0 deletions cypress/integration/other/xss.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ describe('XSS', () => {
cy.get('#the-malware').should('not.exist');
});
it('should not allow manipulating antiscript to run javascript using onerror in state diagrams with dagre d3', () => {
cy.on('uncaught:exception', (_err, _runnable) => {
return false; // continue rendering even if there if mermaid throws an error
});
cy.visit('http://localhost:9000/xss9.html');
cy.wait(1000);
cy.get('#the-malware').should('not.exist');
Expand Down
8 changes: 4 additions & 4 deletions cypress/integration/rendering/flowchart.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -745,13 +745,13 @@ describe('Graph', () => {
cy.get('svg').should((svg) => {
expect(svg).to.have.attr('width', '100%');
// expect(svg).to.have.attr('height');
// use within because the absolute value can be slightly different depending on the environment ±5%
// use within because the absolute value can be slightly different depending on the environment ±10%
// const height = parseFloat(svg.attr('height'));
// expect(height).to.be.within(446 * 0.95, 446 * 1.05);
const style = svg.attr('style');
expect(style).to.match(/^max-width: [\d.]+px;$/);
const maxWidthValue = parseFloat(style.match(/[\d.]+/g).join(''));
expect(maxWidthValue).to.be.within(300 * 0.95, 300 * 1.05);
expect(maxWidthValue).to.be.within(300 * 0.9, 300 * 1.1);
});
});
it('39: should render a flowchart when useMaxWidth is false', () => {
Expand All @@ -768,9 +768,9 @@ describe('Graph', () => {
cy.get('svg').should((svg) => {
// const height = parseFloat(svg.attr('height'));
const width = parseFloat(svg.attr('width'));
// use within because the absolute value can be slightly different depending on the environment ±5%
// use within because the absolute value can be slightly different depending on the environment ±10%
// expect(height).to.be.within(446 * 0.95, 446 * 1.05);
expect(width).to.be.within(300 * 0.95, 300 * 1.05);
expect(width).to.be.within(300 * 0.9, 300 * 1.1);
expect(svg).to.not.have.attr('style');
});
});
Expand Down
21 changes: 11 additions & 10 deletions cypress/integration/rendering/gitGraph.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,42 +213,43 @@ describe('Git Graph diagram', () => {
`
gitGraph
checkout main
commit
%% Make sure to manually set the ID of all commits, for consistent visual tests
aloisklink marked this conversation as resolved.
Show resolved Hide resolved
commit id: "1-abcdefg"
checkout main
branch branch1
commit
commit id: "2-abcdefg"
checkout main
merge branch1
branch branch2
commit
commit id: "3-abcdefg"
checkout main
merge branch2
branch branch3
commit
commit id: "4-abcdefg"
checkout main
merge branch3
branch branch4
commit
commit id: "5-abcdefg"
checkout main
merge branch4
branch branch5
commit
commit id: "6-abcdefg"
checkout main
merge branch5
branch branch6
commit
commit id: "7-abcdefg"
checkout main
merge branch6
branch branch7
commit
commit id: "8-abcdefg"
checkout main
merge branch7
branch branch8
commit
commit id: "9-abcdefg"
checkout main
merge branch8
branch branch9
commit
commit id: "10-abcdefg"
`,
{}
);
Expand Down
Loading