0

最近开始使用Cypressand @cypress/vue,我的组件测试通过以下脚本在本地环境中运行正常:

“cy:run-ct”:“柏树运行-ct”

我的项目由托管Amplify console,我想在每次部署时运行它们(组件测试而不是 e2e 测试),因此尝试添加yarn cy:run-ctamplify.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 控制台吗?还是还不支持?

4

2 回答 2

0

这是我们如何做到的。我们使用 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 run --reporter mochawesome --reporter-options "reportDir=cypress/report/mochawesome-report,overwrite=false,html=false,json=true,timestamp=mmddyyyy_HHMMss"",

于 2021-06-22T14:29:25.350 回答
0

得到它的工作,赛普拉斯组件测试(yarn cy:run-ct)可以在 test.phases.test.commands 部分运行,amplify.yml如下所示:

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 控制台将停止部署。

于 2021-06-26T06:03:56.253 回答