运行 Cypress 组件可以在 Amplify 控制台上测试(不是 e2e 测试)吗?
Can run Cypress component test (not e2e test) on Amplify console?
最近开始使用 Cypress
和 @cypress/vue
,我的组件通过以下脚本在本地环境中测试 运行 ok:
"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
。
有人设法 run-ct
在 Amplify 控制台上吗?或者还不支持?
这是我们的做法。我们使用 NPM,但这不重要...
test:
phases:
preTest:
commands:
- npm ci
- "npm start & npx wait-on http://localhost:3000"
test:
commands:
- "npm run e2e:amplify"
postTest:
commands:
- npx mochawesome-merge cypress/report/mochawesome-report/mochawesome*.json > cypress/report/mochawesome.json
artifacts:
baseDirectory: cypress
configFilePath: "**/mochawesome.json"
和 npm 运行 e2e:amplify 脚本...
"e2e:amplify": "npx cypress 运行 --reporter mochawesome --reporter-options "reportDir=cypress/report/mochawesome-report,overwrite=false,html=false ,json=真,时间戳=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,overwrite=false,html=false,json=true,timestamp=mmddyyyy_HHMMss"'
postTest:
commands:
- npx mochawesome-merge cypress/report/mochawesome-report/mochawesome*.json > cypress/report/mochawesome.json
- npx pm2 kill
现在所有的 cypress 组件测试和 e2e 测试 运行 好的,如果任何测试失败,Amplify 控制台将停止部署。
最近开始使用 Cypress
和 @cypress/vue
,我的组件通过以下脚本在本地环境中测试 运行 ok:
"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
。
有人设法 run-ct
在 Amplify 控制台上吗?或者还不支持?
这是我们的做法。我们使用 NPM,但这不重要...
test:
phases:
preTest:
commands:
- npm ci
- "npm start & npx wait-on http://localhost:3000"
test:
commands:
- "npm run e2e:amplify"
postTest:
commands:
- npx mochawesome-merge cypress/report/mochawesome-report/mochawesome*.json > cypress/report/mochawesome.json
artifacts:
baseDirectory: cypress
configFilePath: "**/mochawesome.json"
和 npm 运行 e2e:amplify 脚本...
"e2e:amplify": "npx cypress 运行 --reporter mochawesome --reporter-options "reportDir=cypress/report/mochawesome-report,overwrite=false,html=false ,json=真,时间戳=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,overwrite=false,html=false,json=true,timestamp=mmddyyyy_HHMMss"'
postTest:
commands:
- npx mochawesome-merge cypress/report/mochawesome-report/mochawesome*.json > cypress/report/mochawesome.json
- npx pm2 kill
现在所有的 cypress 组件测试和 e2e 测试 运行 好的,如果任何测试失败,Amplify 控制台将停止部署。