Skip to content

Commit

Permalink
refactor(cypress): Cypress 10 / Razzle 4
Browse files Browse the repository at this point in the history
  • Loading branch information
avoinea committed Oct 31, 2022
1 parent 67c98f5 commit 19c7f80
Show file tree
Hide file tree
Showing 27 changed files with 3,638 additions and 74 deletions.
83 changes: 46 additions & 37 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ pipeline {
}
}
steps {
parallel(

"Volto": {
node(label: 'docker') {
script {
try {
Expand Down Expand Up @@ -103,10 +106,10 @@ pipeline {
}
}
}
)
}
}



stage('Integration tests') {
when {
allOf {
Expand All @@ -118,43 +121,49 @@ pipeline {
}
}
steps {
node(label: 'docker') {
script {
try {
sh '''docker pull eeacms/plone-backend; docker run --rm -d --name="$BUILD_TAG-plone-eeacms" -e SITE="Plone" -e PROFILES="eea.kitkat:testing" eeacms/plone-backend'''
sh '''docker pull plone/volto-addon-ci:alpha; docker run -i --name="$BUILD_TAG-cypress-eeacms" --link $BUILD_TAG-plone-eeacms:plone -e NAMESPACE="$NAMESPACE" -e GIT_NAME=$GIT_NAME -e GIT_BRANCH="$BRANCH_NAME" -e GIT_CHANGE_ID="$CHANGE_ID" -e DEPENDENCIES="$DEPENDENCIES" -e NODE_ENV=development -e VOLTO="$VOLTO" plone/volto-addon-ci:alpha cypress run --config-file=cypress.eeacms.config.js'''
} finally {
try {
sh '''rm -rf cypress-reports cypress-results cypress-coverage'''
sh '''mkdir -p cypress-reports cypress-results cypress-coverage'''
sh '''docker cp $BUILD_TAG-cypress-eeacms:/opt/frontend/my-volto-project/src/addons/$GIT_NAME/cypress/videos cypress-reports/'''
sh '''docker cp $BUILD_TAG-cypress-eeacms:/opt/frontend/my-volto-project/src/addons/$GIT_NAME/cypress/reports cypress-results/'''
coverage = sh script: '''docker cp $BUILD_TAG-cypress-eeacms:/opt/frontend/my-volto-project/src/addons/$GIT_NAME/coverage cypress-coverage/''', returnStatus: true
if ( coverage == 0 ) {
publishHTML (target : [allowMissing: false,
alwaysLinkToLastBuild: true,
keepAll: true,
reportDir: 'cypress-coverage/coverage/lcov-report',
reportFiles: 'index.html',
reportName: 'CypressCoverage',
reportTitles: 'Integration Tests Code Coverage'])
}
sh '''touch empty_file; for ok_test in $(grep -E 'file=.*failures="0"' $(grep 'testsuites .*failures="0"' $(find cypress-results -name *.xml) empty_file | awk -F: '{print $1}') empty_file | sed 's/.* file="\\(.*\\)" time.*/\\1/' | sed 's#^cypress/integration/##g' | sed 's#^../../../node_modules/volto-slate/##g' | sed 's#^../../../node_modules/@eeacms/##g'); do rm -f cypress-reports/videos/$ok_test.mp4; rm -f cypress-reports/$ok_test.mp4; done'''
archiveArtifacts artifacts: 'cypress-reports/**/*.mp4', fingerprint: true, allowEmptyArchive: true
stash name: "cypress-coverage", includes: "cypress-coverage/**", allowEmpty: true
}
finally {
catchError(buildResult: 'SUCCESS', stageResult: 'SUCCESS') {
junit testResults: 'cypress-results/**/*.xml', allowEmptyResults: true
}
sh script: "docker stop $BUILD_TAG-plone-eeacms", returnStatus: true
sh script: "docker rm -v $BUILD_TAG-plone-eeacms", returnStatus: true
sh script: "docker rm -v $BUILD_TAG-cypress-eeacms", returnStatus: true
parallel(

"Cypress": {
node(label: 'docker') {
script {
try {
sh '''docker pull eeacms/plone-backend; docker run --rm -d --name="$BUILD_TAG-plone" -e SITE="Plone" -e PROFILES="eea.kitkat:testing" eeacms/plone-backend'''
sh '''docker pull plone/volto-addon-ci:alpha; docker run -i --name="$BUILD_TAG-cypress" --link $BUILD_TAG-plone:plone -e NAMESPACE="$NAMESPACE" -e GIT_NAME=$GIT_NAME -e GIT_BRANCH="$BRANCH_NAME" -e GIT_CHANGE_ID="$CHANGE_ID" -e DEPENDENCIES="$DEPENDENCIES" -e VOLTO=$VOLTO plone/volto-addon-ci:alpha cypress'''
} finally {
try {
sh '''rm -rf cypress-reports cypress-results cypress-coverage'''
sh '''mkdir -p cypress-reports cypress-results cypress-coverage'''
sh '''docker cp $BUILD_TAG-cypress:/opt/frontend/my-volto-project/src/addons/$GIT_NAME/cypress/videos cypress-reports/'''
sh '''docker cp $BUILD_TAG-cypress:/opt/frontend/my-volto-project/src/addons/$GIT_NAME/cypress/reports cypress-results/'''
coverage = sh script: '''docker cp $BUILD_TAG-cypress:/opt/frontend/my-volto-project/src/addons/$GIT_NAME/coverage cypress-coverage/''', returnStatus: true
if ( coverage == 0 ) {
publishHTML (target : [allowMissing: false,
alwaysLinkToLastBuild: true,
keepAll: true,
reportDir: 'cypress-coverage/coverage/lcov-report',
reportFiles: 'index.html',
reportName: 'CypressCoverage',
reportTitles: 'Integration Tests Code Coverage'])
}
sh '''touch empty_file; for ok_test in $(grep -E 'file=.*failures="0"' $(grep 'testsuites .*failures="0"' $(find cypress-results -name *.xml) empty_file | awk -F: '{print $1}') empty_file | sed 's/.* file="\\(.*\\)" time.*/\\1/' | sed 's#^cypress/integration/##g' | sed 's#^../../../node_modules/@eeacms/##g'); do rm -f cypress-reports/videos/$ok_test.mp4; rm -f cypress-reports/$ok_test.mp4; done'''
archiveArtifacts artifacts: 'cypress-reports/**/*.mp4', fingerprint: true, allowEmptyArchive: true
stash name: "cypress-coverage", includes: "cypress-coverage/**", allowEmpty: true
}
finally {
catchError(buildResult: 'SUCCESS', stageResult: 'SUCCESS') {
junit testResults: 'cypress-results/**/*.xml', allowEmptyResults: true
}
sh script: "docker stop $BUILD_TAG-plone", returnStatus: true
sh script: "docker rm -v $BUILD_TAG-plone", returnStatus: true
sh script: "docker rm -v $BUILD_TAG-cypress", returnStatus: true

}
}
}
}
}
}

)
}
}

Expand All @@ -176,12 +185,12 @@ pipeline {
script{
checkout scm
unstash "xunit-reports"
unstash "cypress-coverage-all"
unstash "cypress-coverage"
def scannerHome = tool 'SonarQubeScanner';
def nodeJS = tool 'NodeJS';
withSonarQubeEnv('Sonarqube') {
sh '''sed -i "s#/opt/frontend/my-volto-project/src/addons/${GIT_NAME}/##g" xunit-reports/coverage/lcov.info'''
sh "export PATH=${scannerHome}/bin:${nodeJS}/bin:$PATH; sonar-scanner -Dsonar.javascript.lcov.reportPaths=./xunit-reports/coverage/lcov.info,./cypress-coverage-all/coverage/lcov.info, -Dsonar.sources=./src -Dsonar.projectKey=$GIT_NAME-$BRANCH_NAME -Dsonar.projectVersion=$BRANCH_NAME-$BUILD_NUMBER"
sh "export PATH=${scannerHome}/bin:${nodeJS}/bin:$PATH; sonar-scanner -Dsonar.javascript.lcov.reportPaths=./xunit-reports/coverage/lcov.info,./cypress-coverage/coverage/lcov.info -Dsonar.sources=./src -Dsonar.projectKey=$GIT_NAME-$BRANCH_NAME -Dsonar.projectVersion=$BRANCH_NAME-$BUILD_NUMBER"
sh '''try=2; while [ \$try -gt 0 ]; do curl -s -XPOST -u "${SONAR_AUTH_TOKEN}:" "${SONAR_HOST_URL}api/project_tags/set?project=${GIT_NAME}-${BRANCH_NAME}&tags=${SONARQUBE_TAGS},${BRANCH_NAME}" > set_tags_result; if [ \$(grep -ic error set_tags_result ) -eq 0 ]; then try=0; else cat set_tags_result; echo "... Will retry"; sleep 60; try=\$(( \$try - 1 )); fi; done'''
}
}
Expand Down
8 changes: 2 additions & 6 deletions cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ module.exports = defineConfig({
viewportWidth: 1280,
defaultCommandTimeout: 8888,
chromeWebSecurity: false,
videoUploadOnPasses: false,
screenshotOnRunFailure: false,
reporter: 'junit',
video: true,
retries: {
Expand All @@ -20,11 +18,9 @@ module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
// e2e testing node events setup code
require('@cypress/code-coverage/task')(on, config);
return config;
},
baseUrl: 'http://localhost:3000',
specPattern: '../**/cypress/e2e/**/*.cy.js',
// excludeSpecPattern:
// '../../../node_modules/@eeacms/volto-slate-zotero/cypress/e2e/**/*.js',
fixturesFolder: '../volto-slate-zotero/cypress/fixtures',
},
});
31 changes: 0 additions & 31 deletions cypress.eeacms.config.js

This file was deleted.

29 changes: 29 additions & 0 deletions cypress/e2e/01-block-basics.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { slateBeforeEach, slateAfterEach } from '../support/e2e';

describe('Blocks Tests', () => {
beforeEach(slateBeforeEach);
afterEach(slateAfterEach);

it('Add Block: Empty', () => {
// Change page title
cy.clearSlateTitle();
cy.getSlateTitle().type('My Add-on Page');

cy.get('.documentFirstHeading').contains('My Add-on Page');

cy.getSlate().click();

// Add block
cy.get('.ui.basic.icon.button.block-add-button').first().click();
cy.get('.blocks-chooser .title').contains('Media').click();
cy.get('.content.active.media .button.image').contains('Image').click();

// Save
cy.get('#toolbar-save').click();
cy.url().should('eq', Cypress.config().baseUrl + '/cypress/my-page');

// then the page view should contain our changes
cy.contains('My Add-on Page');
cy.get('.block.image');
});
});
72 changes: 72 additions & 0 deletions cypress/e2e/01-block-columns.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { slateBeforeEach, slateAfterEach } from '../support/e2e';

describe('Blocks Tests', () => {
beforeEach(slateBeforeEach);
afterEach(slateAfterEach);

it('Add Block: Empty', () => {
// Change page title
cy.clearSlateTitle();
cy.getSlateTitle().type('My Add-on Page');

cy.get('.documentFirstHeading').contains('My Add-on Page');

cy.getSlate().click();

// Add block
cy.get('.ui.basic.icon.button.block-add-button').first().click();
cy.get('.blocks-chooser .title').contains('Common').click();
cy.get('.content.active.common .button.columnsBlock')
.contains('Columns')
.click({ force: true });

cy.get('.columns-block .ui.card').eq(2).click();
cy.get('.field-wrapper-title #field-title').last().type('Column test');
cy.get('.field-wrapper-data .columns-area button').last().click();

cy.get('.columns-area .drag.handle.wrapper')
.first()
.trigger('mousedown', { which: 1 }, { force: true })
.trigger('mousemove', 0, 60, { force: true })
.trigger('mouseup');

cy.get('.field-wrapper-gridCols #field-gridCols').click();
cy.get('.react-select__menu').contains('25').click();

cy.get('[contenteditable=true]').first().focus().click();
cy.get('.columns-block [contenteditable=true]')
.eq(0)
.focus()
.click()
.type('First');
cy.get('.columns-block [contenteditable=true]')
.eq(1)
.focus()
.click()
.type('Second');
cy.get('.columns-block [contenteditable=true]')
.eq(2)
.focus()
.click()
.type('Third');
cy.get('.block-toolbar button').eq(1).click();

cy.get(
'.field-wrapper-grid_vertical_align #field-grid_vertical_align',
).click();
cy.get('.react-select__menu').contains('Middle').click();
cy.get('.field-wrapper-backgroundColor .ui.huge.button').click();
cy.get('.github-picker.color-picker span').eq(3).click();

// Save
cy.get('#toolbar-save').click();
cy.url().should('eq', Cypress.config().baseUrl + '/cypress/my-page');

// then the page view should contain our changes
cy.contains('My Add-on Page');
cy.contains('First');
cy.contains('Second');
cy.contains('Third');
cy.get('.columns-view');
});
});
52 changes: 52 additions & 0 deletions cypress/e2e/01-block-group.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { slateBeforeEach, slateAfterEach } from '../support/e2e';

describe('Blocks Tests', () => {
beforeEach(slateBeforeEach);
afterEach(slateAfterEach);

it('Add Block: Empty', () => {
// Change page title
cy.clearSlateTitle();
cy.getSlateTitle().type('My Add-on Page');

cy.get('.documentFirstHeading').contains('My Add-on Page');

cy.getSlate().click();

// Add block
cy.get('.ui.basic.icon.button.block-add-button').first().click();
cy.get('.blocks-chooser .title').contains('Common').click();
cy.get('.content.active.common .button.group')
.contains('Section (Group)')
.click({ force: true });

cy.get('.block-editor-group [contenteditable=true]')
.focus()
.click()
.type('test{enter}');
cy.get('.block-editor-group [contenteditable=true]')
.eq(1)
.focus()
.click()
.type('test2{enter}');
cy.get('.block-editor-group [contenteditable=true]')
.eq(2)
.focus()
.click()
.type('test3');

cy.get('.block-toolbar svg')
.first()
.trigger('mousedown', { button: 0 })
.trigger('mousemove', 10, -40, { force: true })
.trigger('mouseup', 10, -40, { force: true });

// Save
cy.get('#toolbar-save').click();
cy.url().should('eq', Cypress.config().baseUrl + '/cypress/my-page');

// then the page view should contain our changes
cy.contains('My Add-on Page');
cy.contains('test2');
});
});
40 changes: 40 additions & 0 deletions cypress/e2e/01-block-slate-metadata-mentions.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { slateBeforeEach, slateAfterEach } from '../support/e2e';

describe('Block Tests: Metadata', () => {
beforeEach(slateBeforeEach);
afterEach(slateAfterEach);

it('As editor I can add metadata mentions', function () {
// Complete chained commands
cy.getSlateEditorAndType('Colorless green ideas sleep furiously.');

// Metadata mention
cy.setSlateSelection('Colorless', 'green');
cy.clickSlateButton('Metadata');

cy.get('.sidebar-container div[id="field-metadata"]')
.type('Publishing Date{enter}');
cy.get('.sidebar-container .form .header button:first-of-type').click();

// Remove link
cy.setSlateSelection('Colorless')
.setSlateSelection('green');
cy.clickSlateButton('Remove metadata');

// Re-add link
cy.setSlateSelection('green', 'sleep');
cy.clickSlateButton('Metadata');

cy.get('.sidebar-container div[id="field-metadata"]')
.type('Summary{enter}');
cy.get('.sidebar-container [id="blockform-fieldset-metadata"] [id="field-description"]')
.type('blue cats sleep');
cy.get('.sidebar-container .form .header button:first-of-type').click();

// Save
cy.toolbarSave();

// then the page view should contain a link
cy.contains('Colorless blue cats sleep furiously.');
});
});
Loading

0 comments on commit 19c7f80

Please sign in to comment.