问题描述
最近开始使用Cypress
和@cypress/vue
,我的组件测试通过以下脚本在本地环境中运行正常:
"cy:run-ct": "cypress run-ct"
我的项目由 Amplify console
托管,我想在每次部署时运行它们(组件测试而不是 e2e 测试),因此尝试将 yarn cy:run-ct
添加到 amplify.yml
:
frontend:
phases:
preBuild:
commands:
- yarn install
- yarn test
- yarn cy:run-ct
这给了我一个错误 The cypress npm package is installed,but the Cypress binary is missing
。
有人在 Amplify 控制台上成功run-ct
吗?还是还不支持?
解决方法
这是我们如何做到的。我们使用 NPM,但这应该无关紧要...
The negative side to backlinks
- They may penalize your website by clearly violating Google Webmaster
Guidelines
- They may diminish the quality of your website’s link profile,causing your site to get an increased spam score and slowing down it’s progress over time
- May seem overwhelming
- Fake reviews and fraud are rampant
- Hard to truly know what you’re getting
- The best sellers may be too expensive
然后 npm 运行 e2e:amplify 脚本...
"e2e:amplify": "npx cypress run --reporter mochawesome --reporter-options "reportDir=cypress/report/mochawesome-report,overwrite=false,html=false,json=true,timestamp=mmddyyyy_HHMMss"",
,成功了,cypress 组件测试 (yarn cy:run-ct
) 可以在 amplify.yml
的 test.phases.test.commands 部分运行,如下所示:
version: 1
frontend:
phases:
preBuild:
commands:
- yarn install
build:
commands:
- yarn run build
artifacts:
# IMPORTANT - Please verify your build output directory
baseDirectory: dist
files:
- '**/*'
cache:
paths:
- node_modules/**/*
test:
artifacts:
baseDirectory: cypress
configFilePath: '**/mochawesome.json'
files:
- '**/*.png'
- '**/*.mp4'
phases:
preTest:
commands:
- npm install
- npm install wait-on
- npm install pm2
- npm install mocha@5.2.0 mochawesome mochawesome-merge mochawesome-report-generator
- npx pm2 start npm -- start
- 'npx wait-on http://localhost:3000'
test:
commands:
- 'yarn cy:run-ct'
- 'npx cypress run --reporter mochawesome --reporter-options "reportDir=cypress/report/mochawesome-report,timestamp=mmddyyyy_HHMMss"'
postTest:
commands:
- npx mochawesome-merge cypress/report/mochawesome-report/mochawesome*.json > cypress/report/mochawesome.json
- npx pm2 kill
现在所有 cypress 组件测试和 e2e 测试都运行正常,如果任何测试失败,Amplify 控制台将停止部署。