From 78c47fea7a704d1addd796ac5f515d262379da92 Mon Sep 17 00:00:00 2001 From: valentinab25 Date: Tue, 17 Oct 2023 01:07:34 +0300 Subject: [PATCH 01/13] chore: husky, lint-staged use fixed versions --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 78c34c8..cdd9737 100644 --- a/package.json +++ b/package.json @@ -22,8 +22,8 @@ "@cypress/code-coverage": "^3.10.0", "@plone/scripts": "*", "babel-plugin-transform-class-properties": "^6.24.1", - "husky": "*", - "lint-staged": "*", + "husky": "^8.0.3", + "lint-staged": "^14.0.1", "md5": "^2.3.0" }, "lint-staged": { From ecd9264bbf3eaef23e09e7323c264ec1d5954c53 Mon Sep 17 00:00:00 2001 From: valentinab25 Date: Tue, 31 Oct 2023 03:06:13 +0200 Subject: [PATCH 02/13] chore: [JENKINS] Refactor automated testing --- Dockerfile | 2 +- Jenkinsfile | 286 ++++++++++++++++++++++++++++------------------------ Makefile | 37 ++++++- 3 files changed, 188 insertions(+), 137 deletions(-) diff --git a/Dockerfile b/Dockerfile index bd8e10d..b1ce603 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 ARG VOLTO_VERSION -FROM plone/frontend-builder:${VOLTO_VERSION} +FROM eeacms/frontend-builder:${VOLTO_VERSION} ARG ADDON_NAME ARG ADDON_PATH diff --git a/Jenkinsfile b/Jenkinsfile index ef8d659..4c272cf 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,16 +1,20 @@ pipeline { - agent any + agent { + node { label 'docker-host' } + } environment { - GIT_NAME = "volto-widget-toggle" - NAMESPACE = "@eeacms" - SONARQUBE_TAGS = "volto.eea.europa.eu,forest.eea.europa.eu,www.eea.europa.eu-ims,climate-energy.eea.europa.eu,sustainability.eionet.europa.eu,biodiversity.europa.eu,clms.land.copernicus.eu,industry.eea.europa.eu,water.europa.eu-freshwater,demo-www.eea.europa.eu,clmsdemo.devel6cph.eea.europa.eu,water.europa.eu-marine,climate-adapt.eea.europa.eu,climate-advisory-board.devel4cph.eea.europa.eu,climate-advisory-board.europa.eu,www.eea.europa.eu-en" - DEPENDENCIES = "" - VOLTO = "16" - } + GIT_NAME = "volto-widget-toggle" + NAMESPACE = "@eeacms" + SONARQUBE_TAGS = "volto.eea.europa.eu,forest.eea.europa.eu,www.eea.europa.eu-ims,climate-energy.eea.europa.eu,sustainability.eionet.europa.eu,biodiversity.europa.eu,clms.land.copernicus.eu,industry.eea.europa.eu,water.europa.eu-freshwater,demo-www.eea.europa.eu,clmsdemo.devel6cph.eea.europa.eu,water.europa.eu-marine,climate-adapt.eea.europa.eu,climate-advisory-board.devel4cph.eea.europa.eu,climate-advisory-board.europa.eu,www.eea.europa.eu-en" + DEPENDENCIES = "" + BACKEND_PROFILES = "eea.kitkat:testing" + BACKEND_ADDONS = "" + VOLTO = "16" + IMAGE_NAME = BUILD_TAG.toLowerCase() + } stages { - stage('Release') { when { allOf { @@ -20,52 +24,41 @@ pipeline { } steps { node(label: 'docker') { - withCredentials([string(credentialsId: 'eea-jenkins-token', variable: 'GITHUB_TOKEN'),string(credentialsId: 'eea-jenkins-npm-token', variable: 'NPM_TOKEN')]) { - sh '''docker pull eeacms/gitflow''' - sh '''docker run -i --rm --name="$BUILD_TAG-gitflow-master" -e GIT_BRANCH="$BRANCH_NAME" -e GIT_NAME="$GIT_NAME" -e GIT_TOKEN="$GITHUB_TOKEN" -e NPM_TOKEN="$NPM_TOKEN" -e LANGUAGE=javascript eeacms/gitflow''' + withCredentials([string(credentialsId: 'eea-jenkins-token', variable: 'GITHUB_TOKEN'), string(credentialsId: 'eea-jenkins-npm-token', variable: 'NPM_TOKEN')]) { + sh '''docker run -i --rm --pull always --name="$IMAGE_NAME-gitflow-master" -e GIT_BRANCH="$BRANCH_NAME" -e GIT_NAME="$GIT_NAME" -e GIT_TOKEN="$GITHUB_TOKEN" -e NPM_TOKEN="$NPM_TOKEN" -e LANGUAGE=javascript eeacms/gitflow''' } } } } - stage('Code') { + stage('Check if testing needed') { when { allOf { - environment name: 'CHANGE_ID', value: '' - not { changelog '.*^Automated release [0-9\\.]+$' } not { branch 'master' } + not { branch 'develop' } + environment name: 'CHANGE_ID', value: '' } } steps { - parallel( - - "ES lint": { - node(label: 'docker') { - sh '''docker run -i --rm --name="$BUILD_TAG-eslint" -e NAMESPACE="$NAMESPACE" -e GIT_NAME=$GIT_NAME -e GIT_BRANCH="$BRANCH_NAME" -e GIT_CHANGE_ID="$CHANGE_ID" -e VOLTO=$VOLTO plone/volto-addon-ci eslint''' - } - }, - - "Style lint": { - node(label: 'docker') { - sh '''docker run -i --rm --name="$BUILD_TAG-stylelint" -e NAMESPACE="$NAMESPACE" -e GIT_NAME=$GIT_NAME -e GIT_BRANCH="$BRANCH_NAME" -e GIT_CHANGE_ID="$CHANGE_ID" -e VOLTO=$VOLTO plone/volto-addon-ci stylelint''' - } - }, + script { + withCredentials([string(credentialsId: 'eea-jenkins-token', variable: 'GITHUB_TOKEN')]) { + check_result = sh script: '''docker run --pull always -i --rm --name="$IMAGE_NAME-gitflow-check" -e GIT_TOKEN="$GITHUB_TOKEN" -e GIT_BRANCH="$BRANCH_NAME" -e GIT_ORG="$GIT_ORG" -e GIT_NAME="$GIT_NAME" eeacms/gitflow /check_if_testing_needed.sh''', returnStatus: true - "Prettier": { - node(label: 'docker') { - sh '''docker run -i --rm --name="$BUILD_TAG-prettier" -e NAMESPACE="$NAMESPACE" -e GIT_NAME=$GIT_NAME -e GIT_BRANCH="$BRANCH_NAME" -e GIT_CHANGE_ID="$CHANGE_ID" -e VOLTO=$VOLTO plone/volto-addon-ci prettier''' + if (check_result == 0) { + env.SKIP_TESTS = 'yes' + } } - } - ) + } } } - stage('Tests') { + stage('Testing') { when { anyOf { allOf { not { environment name: 'CHANGE_ID', value: '' } environment name: 'CHANGE_TARGET', value: 'develop' + environment name: 'SKIP_TESTS', value: '' } allOf { environment name: 'CHANGE_ID', value: '' @@ -73,26 +66,76 @@ pipeline { not { changelog '.*^Automated release [0-9\\.]+$' } branch 'master' } + environment name: 'SKIP_TESTS', value: '' } } } - steps { - parallel( + stages { + stage('Build test image') { + steps { + checkout scm + sh '''docker build --build-arg="VOLTO_VERSION=$VOLTO" --build-arg="ADDON_NAME=$NAMESPACE/$GIT_NAME" --build-arg="ADDON_PATH=$GIT_NAME" . -t $IMAGE_NAME-frontend''' + } + } + + stage('Fix code') { + when { + environment name: 'CHANGE_ID', value: '' + not { branch 'master' } + } + steps { + script { + fix_result = sh(script: '''docker run --name="$IMAGE_NAME-fix" --entrypoint=make --workdir=/app/src/addons/$GIT_NAME $IMAGE_NAME-frontend ci-fix''', returnStatus: true) + sh '''docker cp $IMAGE_NAME-fix:/app/src/addons/$GIT_NAME/src .''' + sh '''docker rm -v $IMAGE_NAME-fix''' + FOUND_FIX = sh(script: '''git diff | wc -l''', returnStdout: true).trim() - "Volto": { - node(label: 'docker') { - script { - try { - sh '''docker pull plone/volto-addon-ci''' - sh '''docker run -i --name="$BUILD_TAG-volto" -e NAMESPACE="$NAMESPACE" -e GIT_NAME=$GIT_NAME -e GIT_BRANCH="$BRANCH_NAME" -e GIT_CHANGE_ID="$CHANGE_ID" -e VOLTO=$VOLTO plone/volto-addon-ci''' - sh '''rm -rf xunit-reports''' - sh '''mkdir -p xunit-reports''' - sh '''docker cp $BUILD_TAG-volto:/opt/frontend/my-volto-project/coverage xunit-reports/''' - sh '''docker cp $BUILD_TAG-volto:/opt/frontend/my-volto-project/junit.xml xunit-reports/''' - sh '''docker cp $BUILD_TAG-volto:/opt/frontend/my-volto-project/unit_tests_log.txt xunit-reports/''' - stash name: "xunit-reports", includes: "xunit-reports/**" - archiveArtifacts artifacts: "xunit-reports/unit_tests_log.txt", fingerprint: true - publishHTML (target : [ + if (FOUND_FIX != '0') { + withCredentials([string(credentialsId: 'eea-jenkins-token', variable: 'GITHUB_TOKEN')]) { + sh '''sed -i "s|url = .*|url = https://eea-jenkins:$GITHUB_TOKEN@github.com/eea/$GIT_NAME.git|" .git/config''' + } + sh '''git fetch origin $GIT_BRANCH:$GIT_BRANCH''' + sh '''git checkout $GIT_BRANCH''' + sh '''git add src/''' + sh '''git commit -m "style: Automated code fix" ''' + sh '''git push --set-upstream origin $GIT_BRANCH''' + sh '''exit 1''' + } + } + } + } + + stage('ES lint') { + steps { + sh '''docker run --rm --name="$IMAGE_NAME-eslint" --entrypoint=make --workdir=/app/src/addons/$GIT_NAME $IMAGE_NAME-frontend lint''' + } + } + + stage('Style lint') { + steps { + sh '''docker run --rm --name="$IMAGE_NAME-stylelint" --entrypoint=make --workdir=/app/src/addons/$GIT_NAME $IMAGE_NAME-frontend stylelint''' + } + } + + stage('Prettier') { + steps { + sh '''docker run --rm --name="$IMAGE_NAME-prettier" --entrypoint=make --workdir=/app/src/addons/$GIT_NAME $IMAGE_NAME-frontend prettier''' + } + } + + stage('Coverage Tests') { + parallel { + + stage('Unit tests') { + steps { + script { + try { + sh '''docker run --name="$IMAGE_NAME-volto" --entrypoint=make --workdir=/app/src/addons/$GIT_NAME $IMAGE_NAME-frontend test-ci''' + sh '''rm -rf xunit-reports''' + sh '''mkdir -p xunit-reports''' + sh '''docker cp $IMAGE_NAME-volto:/app/coverage xunit-reports/''' + sh '''docker cp $IMAGE_NAME-volto:/app/junit.xml xunit-reports/''' + publishHTML(target : [ allowMissing: false, alwaysLinkToLastBuild: true, keepAll: true, @@ -105,75 +148,60 @@ pipeline { catchError(buildResult: 'SUCCESS', stageResult: 'SUCCESS') { junit testResults: 'xunit-reports/junit.xml', allowEmptyResults: true } - sh script: '''docker rm -v $BUILD_TAG-volto''', returnStatus: true + sh script: '''docker rm -v $IMAGE_NAME-volto''', returnStatus: true + } } } } - } - ) - } - } + + stage('Integration tests') { + steps { + script { + try { + sh '''docker run --pull always --rm -d --name="$IMAGE_NAME-plone" -e SITE="Plone" -e PROFILES="$BACKEND_PROFILES" -e ADDONS="$BACKEND_ADDONS" eeacms/plone-backend''' + sh '''docker run --link $IMAGE_NAME-plone:plone --entrypoint=make --name="$IMAGE_NAME-cypress" --workdir=/app/src/addons/${GIT_NAME} -e "RAZZLE_INTERNAL_API_PATH=http://plone:8080/Plone" $IMAGE_NAME-frontend cypress-ci''' + } finally { + try { + sh '''rm -rf cypress-videos cypress-results cypress-coverage cypress-screenshots''' + sh '''mkdir -p cypress-videos cypress-results cypress-coverage cypress-screenshots''' + sh '''docker cp $IMAGE_NAME-cypress:/app/src/addons/$GIT_NAME/cypress/videos cypress-videos/''' + sh '''docker cp $IMAGE_NAME-cypress:/app/src/addons/$GIT_NAME/cypress/reports cypress-results/''' + screenshots = sh script: '''docker cp $IMAGE_NAME-cypress:/app/src/addons/$GIT_NAME/cypress/screenshots cypress-screenshots''', returnStatus: true - stage('Integration tests') { - when { - anyOf { - allOf { - not { environment name: 'CHANGE_ID', value: '' } - environment name: 'CHANGE_TARGET', value: 'develop' - } - allOf { - environment name: 'CHANGE_ID', value: '' - anyOf { - not { changelog '.*^Automated release [0-9\\.]+$' } - branch 'master' - } - } - } - } - steps { - parallel( + archiveArtifacts artifacts: 'cypress-screenshots/**', fingerprint: true, allowEmptyArchive: true - "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; 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 NODE_ENV=development -e VOLTO=$VOLTO plone/volto-addon-ci 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, + coverage = sh script: '''docker cp $IMAGE_NAME-cypress:/app/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') { + } + sh '''for file in $(find cypress-results -name *.xml); do if [ $(grep -E 'failures="[1-9].*"' $file | wc -l) -eq 0 ]; then testname=$(grep -E 'file=.*failures="0"' $file | sed 's#.* file=".*\\/\\(.*\\.[jsxt]\\+\\)" time.*#\\1#' ); rm -f cypress-videos/videos/$testname.mp4; fi; done''' + archiveArtifacts artifacts: 'cypress-videos/**', fingerprint: true, allowEmptyArchive: true + } finally { + catchError(buildResult: 'SUCCESS', stageResult: 'SUCCESS') { junit testResults: 'cypress-results/**/*.xml', allowEmptyResults: true + } + sh script: "docker stop $IMAGE_NAME-plone", returnStatus: true + sh script: "docker rm -v $IMAGE_NAME-plone", returnStatus: true + sh script: "docker rm -v $IMAGE_NAME-cypress", returnStatus: 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 - } } } } } - - ) + } + } + post { + always { + sh script: "docker rmi $IMAGE_NAME-frontend", returnStatus: true + } } } @@ -197,19 +225,16 @@ pipeline { } } steps { - node(label: 'swarm') { - script{ - checkout scm - unstash "xunit-reports" - 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 '''sed -i "s#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/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''' - } + script { + def scannerHome = tool 'SonarQubeScanner' + def nodeJS = tool 'NodeJS' + withSonarQubeEnv('Sonarqube') { + sh '''sed -i "s#/app/src/addons/${GIT_NAME}/##g" xunit-reports/coverage/lcov.info''' + sh '''sed -i "s#src/addons/${GIT_NAME}/##g" xunit-reports/coverage/lcov.info''' + sh '''cat xunit-reports/coverage/lcov.info''' + sh '''cat cypress-coverage/coverage/lcov.info''' + 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=5; 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 15; try=\$(( \$try - 1 )); fi; done''' } } } @@ -230,18 +255,15 @@ pipeline { } } steps { - node(label: 'docker') { - script { - sh '''docker pull eeacms/gitflow''' - sh '''echo "Error" > checkresult.txt''' - catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') { - sh '''set -o pipefail; docker run -i --rm --name="$BUILD_TAG-gitflow-sn" -e GIT_BRANCH="$BRANCH_NAME" -e GIT_NAME="$GIT_NAME" eeacms/gitflow /checkSonarqubemaster.sh | grep -v "Found script" | tee checkresult.txt''' - } - - publishChecks name: 'SonarQube', title: 'Sonarqube Code Quality Check', summary: "Quality check on the SonarQube metrics from branch develop, comparing it with the ones from master branch. No bugs are allowed", - text: readFile(file: 'checkresult.txt'), conclusion: "${currentBuild.currentResult}", - detailsURL: "${env.BUILD_URL}display/redirect" + script { + sh '''echo "Error" > checkresult.txt''' + catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') { + sh '''set -o pipefail; docker run -i --rm --pull always --name="$IMAGE_NAME-gitflow-sn" -e GIT_BRANCH="$BRANCH_NAME" -e GIT_NAME="$GIT_NAME" eeacms/gitflow /checkSonarqubemaster.sh | grep -v "Found script" | tee checkresult.txt''' } + + publishChecks name: 'SonarQube', title: 'Sonarqube Code Quality Check', summary: 'Quality check on the SonarQube metrics from branch develop, comparing it with the ones from master branch. No bugs are allowed', + text: readFile(file: 'checkresult.txt'), conclusion: "${currentBuild.currentResult}", + detailsURL: "${env.BUILD_URL}display/redirect" } } } @@ -254,20 +276,16 @@ pipeline { environment name: 'CHANGE_TARGET', value: 'master' } steps { - node(label: 'docker') { - script { - if ( env.CHANGE_BRANCH != "develop" ) { - error "Pipeline aborted due to PR not made from develop branch" - } - withCredentials([string(credentialsId: 'eea-jenkins-token', variable: 'GITHUB_TOKEN')]) { - sh '''docker pull eeacms/gitflow''' - sh '''docker run -i --rm --name="$BUILD_TAG-gitflow-pr" -e GIT_CHANGE_TARGET="$CHANGE_TARGET" -e GIT_CHANGE_BRANCH="$CHANGE_BRANCH" -e GIT_CHANGE_AUTHOR="$CHANGE_AUTHOR" -e GIT_CHANGE_TITLE="$CHANGE_TITLE" -e GIT_TOKEN="$GITHUB_TOKEN" -e GIT_BRANCH="$BRANCH_NAME" -e GIT_CHANGE_ID="$CHANGE_ID" -e GIT_ORG="$GIT_ORG" -e GIT_NAME="$GIT_NAME" -e LANGUAGE=javascript eeacms/gitflow''' - } + script { + if (env.CHANGE_BRANCH != 'develop') { + error 'Pipeline aborted due to PR not made from develop branch' + } + withCredentials([string(credentialsId: 'eea-jenkins-token', variable: 'GITHUB_TOKEN')]) { + sh '''docker run --pull always -i --rm --name="$IMAGE_NAME-gitflow-pr" -e GIT_CHANGE_TARGET="$CHANGE_TARGET" -e GIT_CHANGE_BRANCH="$CHANGE_BRANCH" -e GIT_CHANGE_AUTHOR="$CHANGE_AUTHOR" -e GIT_CHANGE_TITLE="$CHANGE_TITLE" -e GIT_TOKEN="$GITHUB_TOKEN" -e GIT_BRANCH="$BRANCH_NAME" -e GIT_CHANGE_ID="$CHANGE_ID" -e GIT_ORG="$GIT_ORG" -e GIT_NAME="$GIT_NAME" -e LANGUAGE=javascript eeacms/gitflow''' } } } } - } post { diff --git a/Makefile b/Makefile index f3614a8..6e221b3 100644 --- a/Makefile +++ b/Makefile @@ -50,6 +50,11 @@ VOLTO_VERSION?=16 ADDON_PATH="${DIR}" ADDON_NAME="@eeacms/${ADDON_PATH}" DOCKER_COMPOSE=PLONE_VERSION=${PLONE_VERSION} VOLTO_VERSION=${VOLTO_VERSION} ADDON_NAME=${ADDON_NAME} ADDON_PATH=${ADDON_PATH} docker compose +RAZZLE_INTERNAL_API_PATH?="${RAZZLE_DEV_PROXY_API_PATH}" +RAZZLE_DEV_PROXY_API_PATH?="${RAZZLE_INTERNAL_API_PATH}" +CYPRESS_API_PATH="${RAZZLE_DEV_PROXY_API_PATH}" + + # Top-level targets .PHONY: all @@ -77,11 +82,11 @@ shell: ## Start a shell in the frontend container .PHONY: cypress-open cypress-open: ## Open cypress integration tests - NODE_ENV=development $(NODE_MODULES)/cypress/bin/cypress open + CYPRESS_API_PATH="${RAZZLE_DEV_PROXY_API_PATH}" NODE_ENV=development $(NODE_MODULES)/cypress/bin/cypress open .PHONY: cypress-run cypress-run: ## Run cypress integration tests - NODE_ENV=development $(NODE_MODULES)/cypress/bin/cypress run + CYPRESS_API_PATH="${RAZZLE_DEV_PROXY_API_PATH}" NODE_ENV=development $(NODE_MODULES)/cypress/bin/cypress run .PHONY: test test: ## Run jest tests @@ -129,3 +134,31 @@ i18n: ## i18n help: ## Show this help. @echo -e "$$(grep -hE '^\S+:.*##' $(MAKEFILE_LIST) | sed -e 's/:.*##\s*/:/' -e 's/^\(.\+\):\(.*\)/\\x1b[36m\1\\x1b[m:\2/' | column -c2 -t -s :)" head -n 14 Makefile + +.PHONY: ci-fix +ci-fix: + echo "Running lint-fix" + make lint-fix + echo "Running prettier-fix" + make prettier-fix + echo "Running stylelint-fix" + make stylelint-fix + +.PHONY: test-ci +test-ci: + cd /app + RAZZLE_JEST_CONFIG=src/addons/${ADDON_PATH}/jest-addon.config.js CI=true yarn test src/addons/${ADDON_PATH}/src --watchAll=false --reporters=default --reporters=jest-junit --collectCoverage --coverageReporters lcov cobertura text + +.PHONY: start-ci +start-ci: + cd ../.. + yarn start & + +.PHONY: cypress-ci +cypress-ci: + cp .coverage.babel.config.js /app/babel.config.js + make start-ci + $(NODE_MODULES)/.bin/wait-on -t 240000 http://localhost:3000 + NODE_ENV=development make cypress-run + + From cd49aca874da556ce3d18e8c259cbbe9a1d93c8b Mon Sep 17 00:00:00 2001 From: valentinab25 Date: Thu, 2 Nov 2023 22:29:50 +0200 Subject: [PATCH 03/13] test: [JENKINS] Improve cypress time --- Jenkinsfile | 14 +++++++------- Makefile | 4 ++-- cypress.config.js | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 4c272cf..df4ca11 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -74,7 +74,7 @@ pipeline { stage('Build test image') { steps { checkout scm - sh '''docker build --build-arg="VOLTO_VERSION=$VOLTO" --build-arg="ADDON_NAME=$NAMESPACE/$GIT_NAME" --build-arg="ADDON_PATH=$GIT_NAME" . -t $IMAGE_NAME-frontend''' + sh '''docker build --pull --build-arg="VOLTO_VERSION=$VOLTO" --build-arg="ADDON_NAME=$NAMESPACE/$GIT_NAME" --build-arg="ADDON_PATH=$GIT_NAME" . -t $IMAGE_NAME-frontend''' } } @@ -159,12 +159,12 @@ pipeline { script { try { sh '''docker run --pull always --rm -d --name="$IMAGE_NAME-plone" -e SITE="Plone" -e PROFILES="$BACKEND_PROFILES" -e ADDONS="$BACKEND_ADDONS" eeacms/plone-backend''' - sh '''docker run --link $IMAGE_NAME-plone:plone --entrypoint=make --name="$IMAGE_NAME-cypress" --workdir=/app/src/addons/${GIT_NAME} -e "RAZZLE_INTERNAL_API_PATH=http://plone:8080/Plone" $IMAGE_NAME-frontend cypress-ci''' + sh '''timeout 3600 docker run --link $IMAGE_NAME-plone:plone --entrypoint=make --name="$IMAGE_NAME-cypress" --workdir=/app/src/addons/${GIT_NAME} -e "RAZZLE_INTERNAL_API_PATH=http://plone:8080/Plone" $IMAGE_NAME-frontend cypress-ci''' } finally { try { sh '''rm -rf cypress-videos cypress-results cypress-coverage cypress-screenshots''' sh '''mkdir -p cypress-videos cypress-results cypress-coverage cypress-screenshots''' - sh '''docker cp $IMAGE_NAME-cypress:/app/src/addons/$GIT_NAME/cypress/videos cypress-videos/''' + videos = sh script: '''docker cp $IMAGE_NAME-cypress:/app/src/addons/$GIT_NAME/cypress/videos cypress-videos/''', returnStatus: true sh '''docker cp $IMAGE_NAME-cypress:/app/src/addons/$GIT_NAME/cypress/reports cypress-results/''' screenshots = sh script: '''docker cp $IMAGE_NAME-cypress:/app/src/addons/$GIT_NAME/cypress/screenshots cypress-screenshots''', returnStatus: true @@ -181,8 +181,10 @@ pipeline { reportName: 'CypressCoverage', reportTitles: 'Integration Tests Code Coverage']) } - sh '''for file in $(find cypress-results -name *.xml); do if [ $(grep -E 'failures="[1-9].*"' $file | wc -l) -eq 0 ]; then testname=$(grep -E 'file=.*failures="0"' $file | sed 's#.* file=".*\\/\\(.*\\.[jsxt]\\+\\)" time.*#\\1#' ); rm -f cypress-videos/videos/$testname.mp4; fi; done''' - archiveArtifacts artifacts: 'cypress-videos/**', fingerprint: true, allowEmptyArchive: true + if ( videos == 0 ) { + sh '''for file in $(find cypress-results -name *.xml); do if [ $(grep -E 'failures="[1-9].*"' $file | wc -l) -eq 0 ]; then testname=$(grep -E 'file=.*failures="0"' $file | sed 's#.* file=".*\\/\\(.*\\.[jsxt]\\+\\)" time.*#\\1#' ); rm -f cypress-videos/videos/$testname.mp4; fi; done''' + archiveArtifacts artifacts: 'cypress-videos/**/*.mp4', fingerprint: true, allowEmptyArchive: true + } } finally { catchError(buildResult: 'SUCCESS', stageResult: 'SUCCESS') { junit testResults: 'cypress-results/**/*.xml', allowEmptyResults: true @@ -231,8 +233,6 @@ pipeline { withSonarQubeEnv('Sonarqube') { sh '''sed -i "s#/app/src/addons/${GIT_NAME}/##g" xunit-reports/coverage/lcov.info''' sh '''sed -i "s#src/addons/${GIT_NAME}/##g" xunit-reports/coverage/lcov.info''' - sh '''cat xunit-reports/coverage/lcov.info''' - sh '''cat cypress-coverage/coverage/lcov.info''' 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=5; 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 15; try=\$(( \$try - 1 )); fi; done''' } diff --git a/Makefile b/Makefile index 6e221b3..30b44f0 100644 --- a/Makefile +++ b/Makefile @@ -50,7 +50,7 @@ VOLTO_VERSION?=16 ADDON_PATH="${DIR}" ADDON_NAME="@eeacms/${ADDON_PATH}" DOCKER_COMPOSE=PLONE_VERSION=${PLONE_VERSION} VOLTO_VERSION=${VOLTO_VERSION} ADDON_NAME=${ADDON_NAME} ADDON_PATH=${ADDON_PATH} docker compose -RAZZLE_INTERNAL_API_PATH?="${RAZZLE_DEV_PROXY_API_PATH}" +RAZZLE_INTERNAL_API_PATH?="http://localhost:8080/Plone" RAZZLE_DEV_PROXY_API_PATH?="${RAZZLE_INTERNAL_API_PATH}" CYPRESS_API_PATH="${RAZZLE_DEV_PROXY_API_PATH}" @@ -86,7 +86,7 @@ cypress-open: ## Open cypress integration tests .PHONY: cypress-run cypress-run: ## Run cypress integration tests - CYPRESS_API_PATH="${RAZZLE_DEV_PROXY_API_PATH}" NODE_ENV=development $(NODE_MODULES)/cypress/bin/cypress run + CYPRESS_API_PATH="${RAZZLE_DEV_PROXY_API_PATH}" NODE_ENV=development $(NODE_MODULES)/cypress/bin/cypress run --browser chromium .PHONY: test test: ## Run jest tests diff --git a/cypress.config.js b/cypress.config.js index 4846ce9..7a9e0be 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -2,12 +2,12 @@ const { defineConfig } = require('cypress'); module.exports = defineConfig({ viewportWidth: 1280, - defaultCommandTimeout: 5000, + defaultCommandTimeout: 8888, chromeWebSecurity: false, reporter: 'junit', - video: true, + video: false, retries: { - runMode: 1, + runMode: 2, openMode: 0, }, reporterOptions: { From 45d1523d342925b6e61200f96e44e898df39c51d Mon Sep 17 00:00:00 2001 From: valentinab25 Date: Fri, 3 Nov 2023 20:30:31 +0200 Subject: [PATCH 04/13] test: [JENKINS] Increase shm-size to cypress docker --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index df4ca11..886de3c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -159,7 +159,7 @@ pipeline { script { try { sh '''docker run --pull always --rm -d --name="$IMAGE_NAME-plone" -e SITE="Plone" -e PROFILES="$BACKEND_PROFILES" -e ADDONS="$BACKEND_ADDONS" eeacms/plone-backend''' - sh '''timeout 3600 docker run --link $IMAGE_NAME-plone:plone --entrypoint=make --name="$IMAGE_NAME-cypress" --workdir=/app/src/addons/${GIT_NAME} -e "RAZZLE_INTERNAL_API_PATH=http://plone:8080/Plone" $IMAGE_NAME-frontend cypress-ci''' + sh '''timeout 3600 docker run --shm-size=2g --link $IMAGE_NAME-plone:plone --entrypoint=make --name="$IMAGE_NAME-cypress" --workdir=/app/src/addons/${GIT_NAME} -e "RAZZLE_INTERNAL_API_PATH=http://plone:8080/Plone" $IMAGE_NAME-frontend cypress-ci''' } finally { try { sh '''rm -rf cypress-videos cypress-results cypress-coverage cypress-screenshots''' From 7f73f01bddfb9d1bc52d1d13fcd322f8659527ed Mon Sep 17 00:00:00 2001 From: valentinab25 Date: Mon, 6 Nov 2023 21:59:35 +0200 Subject: [PATCH 05/13] test: [JENKINS] Add cpu limit on cypress docker --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 886de3c..c17fb9c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -159,7 +159,7 @@ pipeline { script { try { sh '''docker run --pull always --rm -d --name="$IMAGE_NAME-plone" -e SITE="Plone" -e PROFILES="$BACKEND_PROFILES" -e ADDONS="$BACKEND_ADDONS" eeacms/plone-backend''' - sh '''timeout 3600 docker run --shm-size=2g --link $IMAGE_NAME-plone:plone --entrypoint=make --name="$IMAGE_NAME-cypress" --workdir=/app/src/addons/${GIT_NAME} -e "RAZZLE_INTERNAL_API_PATH=http://plone:8080/Plone" $IMAGE_NAME-frontend cypress-ci''' + sh '''timeout -s 9 3600 docker run --shm-size=2g --cpu-quota=150000 --link $IMAGE_NAME-plone:plone --entrypoint=make --name="$IMAGE_NAME-cypress" --workdir=/app/src/addons/${GIT_NAME} -e "RAZZLE_INTERNAL_API_PATH=http://plone:8080/Plone" $IMAGE_NAME-frontend cypress-ci''' } finally { try { sh '''rm -rf cypress-videos cypress-results cypress-coverage cypress-screenshots''' From 8daf138f2a820d27111bbbae878d35c1eb514e70 Mon Sep 17 00:00:00 2001 From: valentinab25 Date: Fri, 17 Nov 2023 04:12:59 +0200 Subject: [PATCH 06/13] test: [JENKINS] Run cypress in started frontend container --- Jenkinsfile | 7 ++++++- Makefile | 6 ++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index c17fb9c..5c61c33 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -159,7 +159,8 @@ pipeline { script { try { sh '''docker run --pull always --rm -d --name="$IMAGE_NAME-plone" -e SITE="Plone" -e PROFILES="$BACKEND_PROFILES" -e ADDONS="$BACKEND_ADDONS" eeacms/plone-backend''' - sh '''timeout -s 9 3600 docker run --shm-size=2g --cpu-quota=150000 --link $IMAGE_NAME-plone:plone --entrypoint=make --name="$IMAGE_NAME-cypress" --workdir=/app/src/addons/${GIT_NAME} -e "RAZZLE_INTERNAL_API_PATH=http://plone:8080/Plone" $IMAGE_NAME-frontend cypress-ci''' + sh '''docker run -d --shm-size=3g --link $IMAGE_NAME-plone:plone --name="$IMAGE_NAME-cypress" -e "RAZZLE_INTERNAL_API_PATH=http://plone:8080/Plone" --entrypoint=make --workdir=/app/src/addons/$GIT_NAME $IMAGE_NAME-frontend start-ci''' + sh '''timeout -s 9 1800 docker exec --workdir=/app/src/addons/${GIT_NAME} $IMAGE_NAME-cypress make cypress-ci''' } finally { try { sh '''rm -rf cypress-videos cypress-results cypress-coverage cypress-screenshots''' @@ -189,6 +190,10 @@ pipeline { catchError(buildResult: 'SUCCESS', stageResult: 'SUCCESS') { junit testResults: 'cypress-results/**/*.xml', allowEmptyResults: true } + catchError(buildResult: 'SUCCESS', stageResult: 'SUCCESS') { + sh '''docker logs $IMAGE_NAME-cypress''' + } + sh script: "docker stop $IMAGE_NAME-cypress", returnStatus: true sh script: "docker stop $IMAGE_NAME-plone", returnStatus: true sh script: "docker rm -v $IMAGE_NAME-plone", returnStatus: true sh script: "docker rm -v $IMAGE_NAME-cypress", returnStatus: true diff --git a/Makefile b/Makefile index 30b44f0..efbf2fb 100644 --- a/Makefile +++ b/Makefile @@ -151,14 +151,12 @@ test-ci: .PHONY: start-ci start-ci: + cp .coverage.babel.config.js /app/babel.config.js cd ../.. - yarn start & + yarn start .PHONY: cypress-ci cypress-ci: - cp .coverage.babel.config.js /app/babel.config.js - make start-ci $(NODE_MODULES)/.bin/wait-on -t 240000 http://localhost:3000 NODE_ENV=development make cypress-run - From 0e8e6e5b4dc2b183cb77734c7b9dbcace0428a42 Mon Sep 17 00:00:00 2001 From: valentinab25 Date: Fri, 17 Nov 2023 20:12:55 +0200 Subject: [PATCH 07/13] test: [JENKINS] Use java17 for sonarqube scanner --- Jenkinsfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 5c61c33..d476c93 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,4 +1,7 @@ pipeline { + tools { + jdk 'Java17' + } agent { node { label 'docker-host' } } From 4684626e63b7103fc4d132d91b9696d91cc968ec Mon Sep 17 00:00:00 2001 From: EEA Jenkins Date: Thu, 1 Feb 2024 20:07:03 +0200 Subject: [PATCH 08/13] Add Sonarqube tag using insitu-frontend addons list --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index d476c93..0291945 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,7 +9,7 @@ pipeline { environment { GIT_NAME = "volto-widget-toggle" NAMESPACE = "@eeacms" - SONARQUBE_TAGS = "volto.eea.europa.eu,forest.eea.europa.eu,www.eea.europa.eu-ims,climate-energy.eea.europa.eu,sustainability.eionet.europa.eu,biodiversity.europa.eu,clms.land.copernicus.eu,industry.eea.europa.eu,water.europa.eu-freshwater,demo-www.eea.europa.eu,clmsdemo.devel6cph.eea.europa.eu,water.europa.eu-marine,climate-adapt.eea.europa.eu,climate-advisory-board.devel4cph.eea.europa.eu,climate-advisory-board.europa.eu,www.eea.europa.eu-en" + SONARQUBE_TAGS = "volto.eea.europa.eu,forest.eea.europa.eu,www.eea.europa.eu-ims,climate-energy.eea.europa.eu,sustainability.eionet.europa.eu,biodiversity.europa.eu,clms.land.copernicus.eu,industry.eea.europa.eu,water.europa.eu-freshwater,demo-www.eea.europa.eu,clmsdemo.devel6cph.eea.europa.eu,water.europa.eu-marine,climate-adapt.eea.europa.eu,climate-advisory-board.devel4cph.eea.europa.eu,climate-advisory-board.europa.eu,www.eea.europa.eu-en,insitu-frontend.eionet.europa.eu" DEPENDENCIES = "" BACKEND_PROFILES = "eea.kitkat:testing" BACKEND_ADDONS = "" From a9b8e967be630d5893bf8b5134124cf07137f99b Mon Sep 17 00:00:00 2001 From: EEA Jenkins Date: Tue, 9 Apr 2024 11:37:42 +0300 Subject: [PATCH 09/13] Add Sonarqube tag using freshwater-frontend addons list --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 0291945..3fb6da5 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,7 +9,7 @@ pipeline { environment { GIT_NAME = "volto-widget-toggle" NAMESPACE = "@eeacms" - SONARQUBE_TAGS = "volto.eea.europa.eu,forest.eea.europa.eu,www.eea.europa.eu-ims,climate-energy.eea.europa.eu,sustainability.eionet.europa.eu,biodiversity.europa.eu,clms.land.copernicus.eu,industry.eea.europa.eu,water.europa.eu-freshwater,demo-www.eea.europa.eu,clmsdemo.devel6cph.eea.europa.eu,water.europa.eu-marine,climate-adapt.eea.europa.eu,climate-advisory-board.devel4cph.eea.europa.eu,climate-advisory-board.europa.eu,www.eea.europa.eu-en,insitu-frontend.eionet.europa.eu" + SONARQUBE_TAGS = "volto.eea.europa.eu,forest.eea.europa.eu,www.eea.europa.eu-ims,climate-energy.eea.europa.eu,biodiversity.europa.eu,clms.land.copernicus.eu,industry.eea.europa.eu,water.europa.eu-freshwater,demo-www.eea.europa.eu,clmsdemo.devel6cph.eea.europa.eu,water.europa.eu-marine,climate-adapt.eea.europa.eu,climate-advisory-board.devel4cph.eea.europa.eu,climate-advisory-board.europa.eu,www.eea.europa.eu-en,insitu-frontend.eionet.europa.eu" DEPENDENCIES = "" BACKEND_PROFILES = "eea.kitkat:testing" BACKEND_ADDONS = "" From 46ff8ad8fb0c50ffb7527ac292a3b4b7a8d0edc0 Mon Sep 17 00:00:00 2001 From: EEA Jenkins Date: Wed, 10 Apr 2024 16:18:37 +0300 Subject: [PATCH 10/13] Add Sonarqube tag using insitu-frontend addons list --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 3fb6da5..bb16e8d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,7 +9,7 @@ pipeline { environment { GIT_NAME = "volto-widget-toggle" NAMESPACE = "@eeacms" - SONARQUBE_TAGS = "volto.eea.europa.eu,forest.eea.europa.eu,www.eea.europa.eu-ims,climate-energy.eea.europa.eu,biodiversity.europa.eu,clms.land.copernicus.eu,industry.eea.europa.eu,water.europa.eu-freshwater,demo-www.eea.europa.eu,clmsdemo.devel6cph.eea.europa.eu,water.europa.eu-marine,climate-adapt.eea.europa.eu,climate-advisory-board.devel4cph.eea.europa.eu,climate-advisory-board.europa.eu,www.eea.europa.eu-en,insitu-frontend.eionet.europa.eu" + SONARQUBE_TAGS = "volto.eea.europa.eu,forest.eea.europa.eu,www.eea.europa.eu-ims,climate-energy.eea.europa.eu,biodiversity.europa.eu,clms.land.copernicus.eu,industry.eea.europa.eu,water.europa.eu-freshwater,demo-www.eea.europa.eu,clmsdemo.devel6cph.eea.europa.eu,water.europa.eu-marine,climate-adapt.eea.europa.eu,climate-advisory-board.devel4cph.eea.europa.eu,climate-advisory-board.europa.eu,www.eea.europa.eu-en,insitu-frontend.eionet.europa.eu,insitu.copernicus.eu" DEPENDENCIES = "" BACKEND_PROFILES = "eea.kitkat:testing" BACKEND_ADDONS = "" From 06fd9344ec36b88810c16288030bf91ce1a854a8 Mon Sep 17 00:00:00 2001 From: EEA Jenkins <2368628+eea-jenkins@users.noreply.github.com> Date: Wed, 17 Apr 2024 21:10:28 +0300 Subject: [PATCH 11/13] feat: Volto 17 support - refs #264527 --- .env | 3 + .eslintrc.js | 65 ++++++++++++++ .gitignore | 1 - .project.eslintrc.js | 48 ----------- Jenkinsfile | 188 +++++++++++++++++++++++++++++++---------- Makefile | 19 +++-- cypress/support/e2e.js | 4 - jest-addon.config.js | 23 ++++- jest.setup.js | 65 ++++++++++++++ package.json | 1 + 10 files changed, 307 insertions(+), 110 deletions(-) create mode 100644 .env create mode 100644 .eslintrc.js delete mode 100644 .project.eslintrc.js create mode 100644 jest.setup.js diff --git a/.env b/.env new file mode 100644 index 0000000..ef282fa --- /dev/null +++ b/.env @@ -0,0 +1,3 @@ +# Jest configuration variables +# - possible values: ON, OFF +JEST_USE_SETUP=OFF \ No newline at end of file diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..0cbd65c --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,65 @@ +const fs = require('fs'); +const path = require('path'); +const projectRootPath = fs.realpathSync(__dirname + '/../../../'); + +let voltoPath = path.join(projectRootPath, 'node_modules/@plone/volto'); +let configFile; +if (fs.existsSync(`${projectRootPath}/tsconfig.json`)) + configFile = `${projectRootPath}/tsconfig.json`; +else if (fs.existsSync(`${projectRootPath}/jsconfig.json`)) + configFile = `${projectRootPath}/jsconfig.json`; + +if (configFile) { + const jsConfig = require(configFile).compilerOptions; + const pathsConfig = jsConfig.paths; + if (pathsConfig['@plone/volto']) + voltoPath = `./${jsConfig.baseUrl}/${pathsConfig['@plone/volto'][0]}`; +} + +const AddonConfigurationRegistry = require(`${voltoPath}/addon-registry.js`); +const reg = new AddonConfigurationRegistry(projectRootPath); + +// Extends ESlint configuration for adding the aliases to `src` directories in Volto addons +const addonAliases = Object.keys(reg.packages).map((o) => [ + o, + reg.packages[o].modulePath, +]); + +const addonExtenders = reg.getEslintExtenders().map((m) => require(m)); + +const defaultConfig = { + extends: `${voltoPath}/.eslintrc`, + settings: { + 'import/resolver': { + alias: { + map: [ + ['@plone/volto', '@plone/volto/src'], + ['@plone/volto-slate', '@plone/volto/packages/volto-slate/src'], + ...addonAliases, + ['@package', `${__dirname}/src`], + ['@root', `${__dirname}/src`], + ['~', `${__dirname}/src`], + ], + extensions: ['.js', '.jsx', '.json'], + }, + 'babel-plugin-root-import': { + rootPathSuffix: 'src', + }, + }, + }, + rules: { + 'react/jsx-no-target-blank': [ + 'error', + { + allowReferrer: true, + }, + ], + } +}; + +const config = addonExtenders.reduce( + (acc, extender) => extender.modify(acc), + defaultConfig, +); + +module.exports = config; diff --git a/.gitignore b/.gitignore index 53b9801..f1be4ff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ .vscode/ .history -.eslintrc.js .nyc_output project coverage diff --git a/.project.eslintrc.js b/.project.eslintrc.js deleted file mode 100644 index 765070f..0000000 --- a/.project.eslintrc.js +++ /dev/null @@ -1,48 +0,0 @@ -const fs = require('fs'); -const path = require('path'); - -const projectRootPath = fs.existsSync('./project') - ? fs.realpathSync('./project') - : fs.realpathSync('./../../../'); -const packageJson = require(path.join(projectRootPath, 'package.json')); -const jsConfig = require(path.join(projectRootPath, 'jsconfig.json')).compilerOptions; - -const pathsConfig = jsConfig.paths; - -let voltoPath = path.join(projectRootPath, 'node_modules/@plone/volto'); - -Object.keys(pathsConfig).forEach(pkg => { - if (pkg === '@plone/volto') { - voltoPath = `./${jsConfig.baseUrl}/${pathsConfig[pkg][0]}`; - } -}); -const AddonConfigurationRegistry = require(`${voltoPath}/addon-registry.js`); -const reg = new AddonConfigurationRegistry(projectRootPath); - -// Extends ESlint configuration for adding the aliases to `src` directories in Volto addons -const addonAliases = Object.keys(reg.packages).map(o => [ - o, - reg.packages[o].modulePath, -]); - - -module.exports = { - extends: `${projectRootPath}/node_modules/@plone/volto/.eslintrc`, - settings: { - 'import/resolver': { - alias: { - map: [ - ['@plone/volto', '@plone/volto/src'], - ...addonAliases, - ['@package', `${__dirname}/src`], - ['~', `${__dirname}/src`], - ], - extensions: ['.js', '.jsx', '.json'], - }, - 'babel-plugin-root-import': { - rootPathSuffix: 'src', - }, - }, - }, -}; - diff --git a/Jenkinsfile b/Jenkinsfile index bb16e8d..e26a6b3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -13,7 +13,8 @@ pipeline { DEPENDENCIES = "" BACKEND_PROFILES = "eea.kitkat:testing" BACKEND_ADDONS = "" - VOLTO = "16" + VOLTO = "17" + VOLTO16_BREAKING_CHANGES = "no" IMAGE_NAME = BUILD_TAG.toLowerCase() } @@ -44,6 +45,7 @@ pipeline { } steps { script { + checkout scm withCredentials([string(credentialsId: 'eea-jenkins-token', variable: 'GITHUB_TOKEN')]) { check_result = sh script: '''docker run --pull always -i --rm --name="$IMAGE_NAME-gitflow-check" -e GIT_TOKEN="$GITHUB_TOKEN" -e GIT_BRANCH="$BRANCH_NAME" -e GIT_ORG="$GIT_ORG" -e GIT_NAME="$GIT_NAME" eeacms/gitflow /check_if_testing_needed.sh''', returnStatus: true @@ -61,7 +63,6 @@ pipeline { allOf { not { environment name: 'CHANGE_ID', value: '' } environment name: 'CHANGE_TARGET', value: 'develop' - environment name: 'SKIP_TESTS', value: '' } allOf { environment name: 'CHANGE_ID', value: '' @@ -69,25 +70,27 @@ pipeline { not { changelog '.*^Automated release [0-9\\.]+$' } branch 'master' } - environment name: 'SKIP_TESTS', value: '' } } } - stages { - stage('Build test image') { - steps { - checkout scm - sh '''docker build --pull --build-arg="VOLTO_VERSION=$VOLTO" --build-arg="ADDON_NAME=$NAMESPACE/$GIT_NAME" --build-arg="ADDON_PATH=$GIT_NAME" . -t $IMAGE_NAME-frontend''' + parallel { + + stage('Volto 17') { + agent { node { label 'docker-1.13'} } + stages { + stage('Build test image') { + steps { + sh '''docker build --pull --build-arg="VOLTO_VERSION=$VOLTO" --build-arg="ADDON_NAME=$NAMESPACE/$GIT_NAME" --build-arg="ADDON_PATH=$GIT_NAME" . -t $IMAGE_NAME-frontend''' + } } - } - - stage('Fix code') { - when { + + stage('Fix code') { + when { environment name: 'CHANGE_ID', value: '' not { branch 'master' } - } - steps { - script { + } + steps { + script { fix_result = sh(script: '''docker run --name="$IMAGE_NAME-fix" --entrypoint=make --workdir=/app/src/addons/$GIT_NAME $IMAGE_NAME-frontend ci-fix''', returnStatus: true) sh '''docker cp $IMAGE_NAME-fix:/app/src/addons/$GIT_NAME/src .''' sh '''docker rm -v $IMAGE_NAME-fix''' @@ -105,31 +108,31 @@ pipeline { sh '''exit 1''' } } + } } - } - stage('ES lint') { - steps { - sh '''docker run --rm --name="$IMAGE_NAME-eslint" --entrypoint=make --workdir=/app/src/addons/$GIT_NAME $IMAGE_NAME-frontend lint''' + stage('ES lint') { + when { environment name: 'SKIP_TESTS', value: '' } + steps { + sh '''docker run --rm --name="$IMAGE_NAME-eslint" --entrypoint=make --workdir=/app/src/addons/$GIT_NAME $IMAGE_NAME-frontend lint''' + } } - } - stage('Style lint') { - steps { - sh '''docker run --rm --name="$IMAGE_NAME-stylelint" --entrypoint=make --workdir=/app/src/addons/$GIT_NAME $IMAGE_NAME-frontend stylelint''' + stage('Style lint') { + when { environment name: 'SKIP_TESTS', value: '' } + steps { + sh '''docker run --rm --name="$IMAGE_NAME-stylelint" --entrypoint=make --workdir=/app/src/addons/$GIT_NAME $IMAGE_NAME-frontend stylelint''' + } } - } - stage('Prettier') { - steps { - sh '''docker run --rm --name="$IMAGE_NAME-prettier" --entrypoint=make --workdir=/app/src/addons/$GIT_NAME $IMAGE_NAME-frontend prettier''' + stage('Prettier') { + when { environment name: 'SKIP_TESTS', value: '' } + steps { + sh '''docker run --rm --name="$IMAGE_NAME-prettier" --entrypoint=make --workdir=/app/src/addons/$GIT_NAME $IMAGE_NAME-frontend prettier''' + } } - } - - stage('Coverage Tests') { - parallel { - - stage('Unit tests') { + stage('Unit tests') { + when { environment name: 'SKIP_TESTS', value: '' } steps { script { try { @@ -155,17 +158,24 @@ pipeline { } } } - } + } - stage('Integration tests') { + stage('Integration tests') { + when { environment name: 'SKIP_TESTS', value: '' } steps { script { try { sh '''docker run --pull always --rm -d --name="$IMAGE_NAME-plone" -e SITE="Plone" -e PROFILES="$BACKEND_PROFILES" -e ADDONS="$BACKEND_ADDONS" eeacms/plone-backend''' - sh '''docker run -d --shm-size=3g --link $IMAGE_NAME-plone:plone --name="$IMAGE_NAME-cypress" -e "RAZZLE_INTERNAL_API_PATH=http://plone:8080/Plone" --entrypoint=make --workdir=/app/src/addons/$GIT_NAME $IMAGE_NAME-frontend start-ci''' + sh '''docker run -d --shm-size=4g --link $IMAGE_NAME-plone:plone --name="$IMAGE_NAME-cypress" -e "RAZZLE_INTERNAL_API_PATH=http://plone:8080/Plone" --entrypoint=make --workdir=/app/src/addons/$GIT_NAME $IMAGE_NAME-frontend start-ci''' + frontend = sh script:'''docker exec --workdir=/app/src/addons/${GIT_NAME} $IMAGE_NAME-cypress make check-ci''', returnStatus: true + if ( frontend != 0 ) { + sh '''docker logs $IMAGE_NAME-cypress; exit 1''' + } + sh '''timeout -s 9 1800 docker exec --workdir=/app/src/addons/${GIT_NAME} $IMAGE_NAME-cypress make cypress-ci''' } finally { try { + if ( frontend == 0 ) { sh '''rm -rf cypress-videos cypress-results cypress-coverage cypress-screenshots''' sh '''mkdir -p cypress-videos cypress-results cypress-coverage cypress-screenshots''' videos = sh script: '''docker cp $IMAGE_NAME-cypress:/app/src/addons/$GIT_NAME/cypress/videos cypress-videos/''', returnStatus: true @@ -189,6 +199,7 @@ pipeline { sh '''for file in $(find cypress-results -name *.xml); do if [ $(grep -E 'failures="[1-9].*"' $file | wc -l) -eq 0 ]; then testname=$(grep -E 'file=.*failures="0"' $file | sed 's#.* file=".*\\/\\(.*\\.[jsxt]\\+\\)" time.*#\\1#' ); rm -f cypress-videos/videos/$testname.mp4; fi; done''' archiveArtifacts artifacts: 'cypress-videos/**/*.mp4', fingerprint: true, allowEmptyArchive: true } + } } finally { catchError(buildResult: 'SUCCESS', stageResult: 'SUCCESS') { junit testResults: 'cypress-results/**/*.xml', allowEmptyResults: true @@ -204,16 +215,7 @@ pipeline { } } } - } } - } - } - post { - always { - sh script: "docker rmi $IMAGE_NAME-frontend", returnStatus: true - } - } - } stage('Report to SonarQube') { when { @@ -221,9 +223,11 @@ pipeline { allOf { not { environment name: 'CHANGE_ID', value: '' } environment name: 'CHANGE_TARGET', value: 'develop' + environment name: 'SKIP_TESTS', value: '' } allOf { environment name: 'CHANGE_ID', value: '' + environment name: 'SKIP_TESTS', value: '' anyOf { allOf { branch 'develop' @@ -248,14 +252,107 @@ pipeline { } } + + } + } + + stage('Volto 16') { + agent { node { label 'integration'} } + when { + environment name: 'SKIP_TESTS', value: '' + not { environment name: 'VOLTO16_BREAKING_CHANGES', value: 'yes' } + } + stages { + stage('Build test image') { + steps { + sh '''docker build --pull --build-arg="VOLTO_VERSION=16" --build-arg="ADDON_NAME=$NAMESPACE/$GIT_NAME" --build-arg="ADDON_PATH=$GIT_NAME" . -t $IMAGE_NAME-frontend16''' + } + } + + stage('Unit tests Volto 16') { + steps { + script { + try { + sh '''docker run --name="$IMAGE_NAME-volto16" --entrypoint=make --workdir=/app/src/addons/$GIT_NAME $IMAGE_NAME-frontend16 test-ci''' + sh '''rm -rf xunit-reports16''' + sh '''mkdir -p xunit-reports16''' + sh '''docker cp $IMAGE_NAME-volto16:/app/junit.xml xunit-reports16/''' + } finally { + catchError(buildResult: 'SUCCESS', stageResult: 'SUCCESS') { + junit testResults: 'xunit-reports16/junit.xml', allowEmptyResults: true + } + sh script: '''docker rm -v $IMAGE_NAME-volto16''', returnStatus: true + } + } + } + } + + stage('Integration tests Volto 16') { + steps { + script { + try { + sh '''docker run --pull always --rm -d --name="$IMAGE_NAME-plone16" -e SITE="Plone" -e PROFILES="$BACKEND_PROFILES" -e ADDONS="$BACKEND_ADDONS" eeacms/plone-backend''' + sh '''docker run -d --shm-size=4g --link $IMAGE_NAME-plone16:plone --name="$IMAGE_NAME-cypress16" -e "RAZZLE_INTERNAL_API_PATH=http://plone:8080/Plone" --entrypoint=make --workdir=/app/src/addons/$GIT_NAME $IMAGE_NAME-frontend16 start-ci''' + frontend = sh script:'''docker exec --workdir=/app/src/addons/${GIT_NAME} $IMAGE_NAME-cypress16 make check-ci''', returnStatus: true + if ( frontend != 0 ) { + sh '''docker logs $IMAGE_NAME-cypress16; exit 1''' + } + sh '''timeout -s 9 1800 docker exec --workdir=/app/src/addons/${GIT_NAME} $IMAGE_NAME-cypress16 make cypress-ci''' + } finally { + try { + if ( frontend == 0 ) { + sh '''rm -rf cypress-videos16 cypress-results16 cypress-coverage16 cypress-screenshots16''' + sh '''mkdir -p cypress-videos16 cypress-results16 cypress-coverage16 cypress-screenshots16''' + videos = sh script: '''docker cp $IMAGE_NAME-cypress16:/app/src/addons/$GIT_NAME/cypress/videos cypress-videos16/''', returnStatus: true + sh '''docker cp $IMAGE_NAME-cypress16:/app/src/addons/$GIT_NAME/cypress/reports cypress-results16/''' + screenshots = sh script: '''docker cp $IMAGE_NAME-cypress16:/app/src/addons/$GIT_NAME/cypress/screenshots cypress-screenshots16''', returnStatus: true + + archiveArtifacts artifacts: 'cypress-screenshots16/**', fingerprint: true, allowEmptyArchive: true + + if ( videos == 0 ) { + sh '''for file in $(find cypress-results16 -name *.xml); do if [ $(grep -E 'failures="[1-9].*"' $file | wc -l) -eq 0 ]; then testname=$(grep -E 'file=.*failures="0"' $file | sed 's#.* file=".*\\/\\(.*\\.[jsxt]\\+\\)" time.*#\\1#' ); rm -f cypress-videos16/videos/$testname.mp4; fi; done''' + archiveArtifacts artifacts: 'cypress-videos16/**/*.mp4', fingerprint: true, allowEmptyArchive: true + } + } + } finally { + catchError(buildResult: 'SUCCESS', stageResult: 'SUCCESS') { + junit testResults: 'cypress-results16/**/*.xml', allowEmptyResults: true + } + catchError(buildResult: 'SUCCESS', stageResult: 'SUCCESS') { + sh '''docker logs $IMAGE_NAME-cypress16''' + } + sh script: "docker stop $IMAGE_NAME-cypress16", returnStatus: true + sh script: "docker stop $IMAGE_NAME-plone16", returnStatus: true + sh script: "docker rm -v $IMAGE_NAME-plone16", returnStatus: true + sh script: "docker rm -v $IMAGE_NAME-cypress16", returnStatus: true + } + } + } + } + } + + } + } + } + post { + always { + sh script: "docker rmi $IMAGE_NAME-frontend", returnStatus: true + sh script: "docker rmi $IMAGE_NAME-frontend16", returnStatus: true + } + } + } + + stage('SonarQube compare to master') { when { anyOf { allOf { not { environment name: 'CHANGE_ID', value: '' } environment name: 'CHANGE_TARGET', value: 'develop' + environment name: 'SKIP_TESTS', value: '' } allOf { + environment name: 'SKIP_TESTS', value: '' environment name: 'CHANGE_ID', value: '' branch 'develop' not { changelog '.*^Automated release [0-9\\.]+$' } @@ -316,3 +413,4 @@ pipeline { } } } + diff --git a/Makefile b/Makefile index efbf2fb..522b577 100644 --- a/Makefile +++ b/Makefile @@ -46,7 +46,7 @@ endif DIR=$(shell basename $$(pwd)) NODE_MODULES?="../../../node_modules" PLONE_VERSION?=6 -VOLTO_VERSION?=16 +VOLTO_VERSION?=17 ADDON_PATH="${DIR}" ADDON_NAME="@eeacms/${ADDON_PATH}" DOCKER_COMPOSE=PLONE_VERSION=${PLONE_VERSION} VOLTO_VERSION=${VOLTO_VERSION} ADDON_NAME=${ADDON_NAME} ADDON_PATH=${ADDON_PATH} docker compose @@ -86,7 +86,7 @@ cypress-open: ## Open cypress integration tests .PHONY: cypress-run cypress-run: ## Run cypress integration tests - CYPRESS_API_PATH="${RAZZLE_DEV_PROXY_API_PATH}" NODE_ENV=development $(NODE_MODULES)/cypress/bin/cypress run --browser chromium + CYPRESS_API_PATH="${RAZZLE_DEV_PROXY_API_PATH}" NODE_ENV=development $(NODE_MODULES)/cypress/bin/cypress run .PHONY: test test: ## Run jest tests @@ -98,7 +98,7 @@ test-update: ## Update jest tests snapshots .PHONY: stylelint stylelint: ## Stylelint - $(NODE_MODULES)/stylelint/bin/stylelint.js --allow-empty-input 'src/**/*.{css,less}' + $(NODE_MODULES)/.bin/stylelint --allow-empty-input 'src/**/*.{css,less}' .PHONY: stylelint-overrides stylelint-overrides: @@ -106,7 +106,7 @@ stylelint-overrides: .PHONY: stylelint-fix stylelint-fix: ## Fix stylelint - $(NODE_MODULES)/stylelint/bin/stylelint.js --allow-empty-input 'src/**/*.{css,less}' --fix + $(NODE_MODULES)/.bin/stylelint --allow-empty-input 'src/**/*.{css,less}' --fix $(NODE_MODULES)/.bin/stylelint --custom-syntax less --allow-empty-input 'theme/**/*.overrides' 'src/**/*.overrides' --fix .PHONY: prettier @@ -119,11 +119,11 @@ prettier-fix: ## Fix prettier .PHONY: lint lint: ## ES Lint - $(NODE_MODULES)/eslint/bin/eslint.js --max-warnings=0 'src/**/*.{js,jsx}' + $(NODE_MODULES)/.bin/eslint --max-warnings=0 'src/**/*.{js,jsx}' .PHONY: lint-fix lint-fix: ## Fix ES Lint - $(NODE_MODULES)/eslint/bin/eslint.js --fix 'src/**/*.{js,jsx}' + $(NODE_MODULES)/.bin/eslint --fix 'src/**/*.{js,jsx}' .PHONY: i18n i18n: ## i18n @@ -155,8 +155,11 @@ start-ci: cd ../.. yarn start +.PHONY: check-ci +check-ci: + $(NODE_MODULES)/.bin/wait-on -t 240000 http://localhost:3000 + .PHONY: cypress-ci cypress-ci: $(NODE_MODULES)/.bin/wait-on -t 240000 http://localhost:3000 - NODE_ENV=development make cypress-run - + CYPRESS_API_PATH="${RAZZLE_DEV_PROXY_API_PATH}" NODE_ENV=development $(NODE_MODULES)/cypress/bin/cypress run --browser chromium diff --git a/cypress/support/e2e.js b/cypress/support/e2e.js index f696418..f8f752c 100644 --- a/cypress/support/e2e.js +++ b/cypress/support/e2e.js @@ -35,10 +35,6 @@ export const slateBeforeEach = (contentType = 'Document') => { path: 'cypress', }); cy.visit('/cypress/my-page'); - cy.waitForResourceToLoad('@navigation'); - cy.waitForResourceToLoad('@breadcrumbs'); - cy.waitForResourceToLoad('@actions'); - cy.waitForResourceToLoad('@types'); cy.waitForResourceToLoad('my-page'); cy.navigate('/cypress/my-page/edit'); }; diff --git a/jest-addon.config.js b/jest-addon.config.js index 3c86610..df1f9bd 100644 --- a/jest-addon.config.js +++ b/jest-addon.config.js @@ -1,3 +1,5 @@ +require('dotenv').config({ path: __dirname + '/.env' }) + module.exports = { testMatch: ['**/src/addons/**/?(*.)+(spec|test).[jt]s?(x)'], collectCoverageFrom: [ @@ -9,18 +11,26 @@ module.exports = { '@plone/volto/cypress': '/node_modules/@plone/volto/cypress', '@plone/volto/babel': '/node_modules/@plone/volto/babel', '@plone/volto/(.*)$': '/node_modules/@plone/volto/src/$1', - '@package/(.*)$': '/src/$1', - '@root/(.*)$': '/src/$1', + '@package/(.*)$': '/node_modules/@plone/volto/src/$1', + '@root/(.*)$': '/node_modules/@plone/volto/src/$1', '@plone/volto-quanta/(.*)$': '/src/addons/volto-quanta/src/$1', + '@eeacms/search/(.*)$': '/src/addons/volto-searchlib/searchlib/$1', + '@eeacms/search': '/src/addons/volto-searchlib/searchlib', '@eeacms/(.*?)/(.*)$': '/node_modules/@eeacms/$1/src/$2', - '@plone/volto-slate': + '@plone/volto-slate$': '/node_modules/@plone/volto/packages/volto-slate/src', + '@plone/volto-slate/(.*)$': + '/node_modules/@plone/volto/packages/volto-slate/src/$1', '~/(.*)$': '/src/$1', 'load-volto-addons': '/node_modules/@plone/volto/jest-addons-loader.js', }, + transformIgnorePatterns: [ + '/node_modules/(?!(@plone|@root|@package|@eeacms)/).*/', + ], transform: { '^.+\\.js(x)?$': 'babel-jest', + '^.+\\.ts(x)?$': 'babel-jest', '^.+\\.(png)$': 'jest-file', '^.+\\.(jpg)$': 'jest-file', '^.+\\.(svg)$': './node_modules/@plone/volto/jest-svgsystem-transform.js', @@ -33,4 +43,9 @@ module.exports = { statements: 5, }, }, -}; + ...(process.env.JEST_USE_SETUP === 'ON' && { + setupFilesAfterEnv: [ + '/node_modules/@eeacms/volto-widget-toggle/jest.setup.js', + ], + }), +} diff --git a/jest.setup.js b/jest.setup.js new file mode 100644 index 0000000..85b16f7 --- /dev/null +++ b/jest.setup.js @@ -0,0 +1,65 @@ +import { jest } from '@jest/globals'; +import configureStore from 'redux-mock-store'; +import thunk from 'redux-thunk'; +import { blocksConfig } from '@plone/volto/config/Blocks'; +import installSlate from '@plone/volto-slate/index'; + +var mockSemanticComponents = jest.requireActual('semantic-ui-react'); +var mockComponents = jest.requireActual('@plone/volto/components'); +var config = jest.requireActual('@plone/volto/registry').default; + +config.blocks.blocksConfig = { + ...blocksConfig, + ...config.blocks.blocksConfig, +}; + +jest.doMock('semantic-ui-react', () => ({ + __esModule: true, + ...mockSemanticComponents, + Popup: ({ content, trigger }) => { + return ( +
+
{trigger}
+
{content}
+
+ ); + }, +})); + +jest.doMock('@plone/volto/components', () => { + return { + __esModule: true, + ...mockComponents, + SidebarPortal: ({ children }) => , + }; +}); + +jest.doMock('@plone/volto/registry', () => + [installSlate].reduce((acc, apply) => apply(acc), config), +); + +const mockStore = configureStore([thunk]); + +global.fetch = jest.fn(() => + Promise.resolve({ + json: () => Promise.resolve({}), + }), +); + +global.store = mockStore({ + intl: { + locale: 'en', + messages: {}, + formatMessage: jest.fn(), + }, + content: { + create: {}, + subrequests: [], + }, + connected_data_parameters: {}, + screen: { + page: { + width: 768, + }, + }, +}); diff --git a/package.json b/package.json index cdd9737..28d02b4 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "@cypress/code-coverage": "^3.10.0", "@plone/scripts": "*", "babel-plugin-transform-class-properties": "^6.24.1", + "dotenv": "^16.3.2", "husky": "^8.0.3", "lint-staged": "^14.0.1", "md5": "^2.3.0" From b1db5088cca5e0a580b97a00836365e8b2c39921 Mon Sep 17 00:00:00 2001 From: alin Date: Mon, 22 Apr 2024 20:54:59 +0300 Subject: [PATCH 12/13] feat: Release 4.0.0 - Volto 17 support --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 28d02b4..aba1ba5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@eeacms/volto-widget-toggle", - "version": "3.1.4", + "version": "4.0.0", "description": "volto-widget-toggle: Volto add-on to replace checkboxes with toggle buttons", "main": "src/index.js", "author": "European Environment Agency: IDM2 A-Team", From acfc49fbfb9468e32151f7046284527c3e3c624a Mon Sep 17 00:00:00 2001 From: EEA Jenkins <@users.noreply.github.com> Date: Mon, 22 Apr 2024 18:18:08 +0000 Subject: [PATCH 13/13] Automated release 4.0.0 --- CHANGELOG.md | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 82d296c..a555aed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,19 @@ All notable changes to this project will be documented in this file. Dates are d Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). +### [4.0.0](https://github.com/eea/volto-widget-toggle/compare/3.1.4...4.0.0) - 22 April 2024 + +#### :rocket: New Features + +- feat: Release 4.0.0 - Volto 17 support [alin - [`b1db508`](https://github.com/eea/volto-widget-toggle/commit/b1db5088cca5e0a580b97a00836365e8b2c39921)] +- feat: Volto 17 support - refs #264527 [EEA Jenkins - [`06fd934`](https://github.com/eea/volto-widget-toggle/commit/06fd9344ec36b88810c16288030bf91ce1a854a8)] + +#### :house: Internal changes + +- chore: husky, lint-staged use fixed versions [valentinab25 - [`78c47fe`](https://github.com/eea/volto-widget-toggle/commit/78c47fea7a704d1addd796ac5f515d262379da92)] + +#### :hammer_and_wrench: Others + ### [3.1.4](https://github.com/eea/volto-widget-toggle/compare/3.1.3...3.1.4) - 16 October 2023 #### :house: Internal changes @@ -28,7 +41,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). - test: EN locales, pre-commit fix, feature PRs checks Refs #257193 [valentinab25 - [`b2f509e`](https://github.com/eea/volto-widget-toggle/commit/b2f509eb236e0beeccfc8bc89f4c6527a3fca223)] - test: Fix package.json scripts to use makefile [Alin Voinea - [`72e8245`](https://github.com/eea/volto-widget-toggle/commit/72e8245a4741988849eaa73e5fd238ff6d340fa9)] -- test: Fix eslint and yarn i18n [Alin Voinea - [`034eaf8`](https://github.com/eea/volto-widget-toggle/commit/034eaf890faa3a9c09aa6f4ddca1bc04e46782a8)] - i18n: Add en [Alin Voinea - [`e60d799`](https://github.com/eea/volto-widget-toggle/commit/e60d799a64230544e37e1f4796dc73bbc0e674c6)] - test: Update Makefile and docker-compose to align it with Jenkinsfile [valentinab25 - [`f86b2f7`](https://github.com/eea/volto-widget-toggle/commit/f86b2f7119f24b637e8bc8101effc2c2c3416a65)] ### [3.1.2](https://github.com/eea/volto-widget-toggle/compare/3.1.1...3.1.2) - 24 July 2023 @@ -39,20 +51,11 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). - test: jest should look for addons in node_modules Refs #253277 [valentinab25 - [`da228a9`](https://github.com/eea/volto-widget-toggle/commit/da228a925ea784b4b418f37ea07418de87759670)] - test: Fix test config, coverage Refs #253277 [valentinab25 - [`b4f3492`](https://github.com/eea/volto-widget-toggle/commit/b4f3492448826968dfbb979fad00f0b65d644017)] -- Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`08bfec1`](https://github.com/eea/volto-widget-toggle/commit/08bfec176ebdf6dff13a7db969a73ca9d8415ee8)] -- Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`1324cce`](https://github.com/eea/volto-widget-toggle/commit/1324cceab3305bf02ab2004a4ff77d492f44481e)] -- Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`13d684d`](https://github.com/eea/volto-widget-toggle/commit/13d684daf218103723779a470ff3dc7f101e93c1)] ### [3.1.0](https://github.com/eea/volto-widget-toggle/compare/3.0.1...3.1.0) - 27 March 2023 #### :hammer_and_wrench: Others -- Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`11a80c7`](https://github.com/eea/volto-widget-toggle/commit/11a80c7ce1f66aa0c7ec600c626875ab7ac8c1cb)] -- Add Sonarqube tag using advisory-board-frontend addons list [EEA Jenkins - [`c353ca1`](https://github.com/eea/volto-widget-toggle/commit/c353ca1794b99b2e5f6681ad93ab844ef33e117e)] -- Add Sonarqube tag using advisory-board-frontend addons list [EEA Jenkins - [`143e5be`](https://github.com/eea/volto-widget-toggle/commit/143e5be8400af60658baa34a7934f707df121f83)] - test(Jenkins): Run tests and cypress with latest canary @plone/volto [Alin Voinea - [`c658d9f`](https://github.com/eea/volto-widget-toggle/commit/c658d9f0fc0fc6cc4b26041b79c93c0982b152c5)] -- Add Sonarqube tag using cca-frontend addons list [EEA Jenkins - [`6f8b43e`](https://github.com/eea/volto-widget-toggle/commit/6f8b43e0fe92d2065725be355b800446fedf2992)] -- yarn 3 [Alin Voinea - [`02d53da`](https://github.com/eea/volto-widget-toggle/commit/02d53daff4ee2886f5533ce8afd0d4e67cd0a9f1)] -- Add Sonarqube tag using demo-kitkat-frontend addons list [EEA Jenkins - [`42059ef`](https://github.com/eea/volto-widget-toggle/commit/42059efe39cf11c31b1a48ddf6503aaf9da14db7)] ### [3.0.1](https://github.com/eea/volto-widget-toggle/compare/3.0.0...3.0.1) - 16 November 2022 #### :hammer_and_wrench: Others @@ -65,21 +68,15 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). - Cleanup [Alin Voinea - [`f0bfe89`](https://github.com/eea/volto-widget-toggle/commit/f0bfe892db782472d0911b3562346d80bed2fb94)] - Typo [Miu Razvan - [`f1faa3d`](https://github.com/eea/volto-widget-toggle/commit/f1faa3d1c0239d377a75b375dcf092cea048c121)] - Use latest cypress [Miu Razvan - [`165ef4a`](https://github.com/eea/volto-widget-toggle/commit/165ef4a017833e757a69da734985acd18155228e)] -- Add Sonarqube tag using marine-frontend addons list [EEA Jenkins - [`45037b0`](https://github.com/eea/volto-widget-toggle/commit/45037b01295d0593929af9ff6f53823e51129f43)] -- Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`de17f98`](https://github.com/eea/volto-widget-toggle/commit/de17f983029cda87580f39b6ab7b1a0139e080cd)] - update(jest): add @plone/volto-slate resolver refs- #153447 [nileshgulia1 - [`b5e6889`](https://github.com/eea/volto-widget-toggle/commit/b5e6889bc22efaeec2025bd79dfe2a839650e4a6)] ### [2.2.7](https://github.com/eea/volto-widget-toggle/compare/2.2.6...2.2.7) - 30 June 2022 #### :hammer_and_wrench: Others -- Add Sonarqube tag using circularity-frontend addons list [EEA Jenkins - [`78e846a`](https://github.com/eea/volto-widget-toggle/commit/78e846a63de32fc42db181a07859a886b10d8b4e)] -- Add Sonarqube tag using clms-frontend addons list [EEA Jenkins - [`75191c3`](https://github.com/eea/volto-widget-toggle/commit/75191c366506d17db335e2b305e5ea8f058e9dfb)] -- Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`3806c6c`](https://github.com/eea/volto-widget-toggle/commit/3806c6c481c069ab939b7603c7d3e102563276dd)] ### [2.2.6](https://github.com/eea/volto-widget-toggle/compare/2.2.5...2.2.6) - 3 January 2022 #### :hammer_and_wrench: Others -- Add Sonarqube tag using freshwater-frontend addons list [EEA Jenkins - [`c2e3484`](https://github.com/eea/volto-widget-toggle/commit/c2e3484b3396dbabf38a8b9e8f6df0b89d4aa663)] ### [2.2.5](https://github.com/eea/volto-widget-toggle/compare/2.2.4...2.2.5) - 16 December 2021 ### [2.2.4](https://github.com/eea/volto-widget-toggle/compare/2.2.3...2.2.4) - 10 December 2021 @@ -87,13 +84,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). #### :hammer_and_wrench: Others - Refs #142010 - Optimize Volto-addons gitflow pipelines [valentinab25 - [`2bd2039`](https://github.com/eea/volto-widget-toggle/commit/2bd203979963ee5cb15592470e1d341d1bd65291)] -- Add Sonarqube tag using industry-frontend addons list [EEA Jenkins - [`af5afe1`](https://github.com/eea/volto-widget-toggle/commit/af5afe1263aff21801bbb8239163ac01644f2a7e)] -- Add Sonarqube tag using clms-frontend addons list [EEA Jenkins - [`2d60373`](https://github.com/eea/volto-widget-toggle/commit/2d60373b280dcb2f902e4dc6fff0bdb8ea7d7ac7)] -- Add Sonarqube tag using bise-frontend addons list [EEA Jenkins - [`80527c1`](https://github.com/eea/volto-widget-toggle/commit/80527c1f72bd8cc325ff1c072def18d24c3e99ae)] -- Add Sonarqube tag using sustainability-frontend addons list [EEA Jenkins - [`bc52e72`](https://github.com/eea/volto-widget-toggle/commit/bc52e72e32197ca82f93bac645f0094bc7db7ab1)] -- Add Sonarqube tag using climate-energy-frontend addons list [EEA Jenkins - [`30397bd`](https://github.com/eea/volto-widget-toggle/commit/30397bde9a045be3c2e6614af798ce11f18e3039)] -- Add Sonarqube tag using ims-frontend addons list [EEA Jenkins - [`dd3fb67`](https://github.com/eea/volto-widget-toggle/commit/dd3fb67693900db1ce6d8f631c61a2a5c25d9b70)] -- Add Sonarqube tag using frontend addons list [EEA Jenkins - [`54d09d1`](https://github.com/eea/volto-widget-toggle/commit/54d09d164591f1cf3d47a69838ccbd9abb8f22b6)] ### [2.2.3](https://github.com/eea/volto-widget-toggle/compare/2.2.2...2.2.3) - 28 June 2021 #### :hammer_and_wrench: Others @@ -127,7 +117,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). - Release 1.0.1 [Alin Voinea - [`454220f`](https://github.com/eea/volto-widget-toggle/commit/454220fa61495427f874fb9b56401fe69689f4fe)] - Auto-release npm [Alin Voinea - [`10b31b3`](https://github.com/eea/volto-widget-toggle/commit/10b31b3b64330d41f69a033a45030e49d20c16b5)] -- yarn prettier [Alin Voinea - [`5136059`](https://github.com/eea/volto-widget-toggle/commit/51360595bf452c815e526ce10f15aa8a84ad186f)] ## [1.0.0](https://github.com/eea/volto-widget-toggle/compare/0.1.0...1.0.0) - 29 September 2020 #### :hammer_and_wrench: Others