0

Recently started to use Cypress and @cypress/vue, my component tests run ok on local environment by script below:

"cy:run-ct": "cypress run-ct"

My project is hosted by Amplify console and I wanted to run them (component tests not e2e tests) on each deploy, so tried to add yarn cy:run-ct to amplify.yml:

frontend:
  phases:
    preBuild:
      commands:
        - yarn install
        - yarn test
        - yarn cy:run-ct

which gives me an error The cypress npm package is installed, but the Cypress binary is missing.

Anyone managed to run-ct on Amplify console? Or is it not supported yet?

bob
  • 2,674
  • 1
  • 29
  • 46

2 Answers2

1

Got it working, cypress component tests (yarn cy:run-ct) could be run in test.phases.test.commands section in amplify.yml as below:

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

Now all cypress component tests and e2e tests run ok, Amplify console would stop deploy if any test failed.

bob
  • 2,674
  • 1
  • 29
  • 46
0

Here is how we do it. We use NPM, but that shouldn't matter...

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"

And the npm run e2e:amplify script...

"e2e:amplify": "npx cypress run --reporter mochawesome --reporter-options "reportDir=cypress/report/mochawesome-report,overwrite=false,html=false,json=true,timestamp=mmddyyyy_HHMMss"",

Alex
  • 952
  • 7
  • 12
  • Thanks for the answer but I'm asking about component test not e2e test. Maybe I need to clarify on my question. – bob Jun 22 '21 at 20:56