Cypress 提供了安装和配置多个报告器的手册:https ://docs.cypress.io/guides/tooling/reporters#Merging-reports-across-spec-files
我的目标是让它在 Docker 容器中工作并将结果提供给主机。为此目的做了什么:
Dockerfile:
FROM cypress/base:14.17.0 RUN mkdir /cypress-docker WORKDIR /cypress-docker COPY . /cypress-docker RUN npm install --save-dev cypress RUN $(npm bin)/cypress verify RUN ["npm", "run", "cypress:e2e"]
记者-config.json:
{ "reporterEnabled": "mocha-junit-reporter, mochawesome", "mochaJunitReporterReporterOptions": { "mochaFile": "cypress/results/junit/results-[hash].xml" }, "reporterOptions": { "reportDir": "cypress/results/mochawesome", "overwrite": false, "html": false, "json": true } }
码头工人-compose.yml:
version: '3.7' services: cypress_test: image: cypress_compose build: context: . dockerfile: ./Dockerfile volumes: - ./dockerReports:/cypress-docker/cypress/results - ./dockerReports:/cypress-docker/mochawesome-report
包.json:
{ "name": "cypress-docker", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "delete:reports": "rimraf cypress/results && mkdirp cypress/results", "prereport": "npm run delete:reports", "mochawesome:merge": "npx mochawesome-merge \"cypress/results/mochawesome/*.json\" > mochawesome.json && npx marge mochawesome.json", "junit:merge": "npx junit-merge -d cypress/results/junit -o cypress/results/junit/result.xml", "cypress:run": "npm run prereport && npx cypress run", "cypress:e2e": "npm run cypress:run && npm run junit:merge && npm run mochawesome:merge" }, "author": "", "license": "ISC", "devDependencies": { "cypress": "^8.2.0", "cypress-multi-reporters": "^1.5.0", "junit-merge": "^2.0.0", "mocha": "^7.8.1", "mocha-junit-reporter": "^2.0.0", "mochawesome": "^6.2.2", "mochawesome-merge": "^4.2.0", "mochawesome-report-generator": "^5.2.0" } }
所以,我希望在运行命令dockerReports
后在主机上有一个包含合并的 JUnit 和 Mochawesome 报告的目录。docker-compose up
这个目录确实出现了,但它是空的。是什么原因?