1

All my tests are running and passing as expected locally; however, there is one test that is failing when running on GitHub actions. The error I'm getting is:

CypressError: Timed out retrying after 60000ms: 
`cy.wait()` timed out waiting `60000ms` for the 1st request to the route:
 `addCustomerMutation`. No request ever occurred.

My code looks like this:

// IMPORTS

cy.intercept('POST', URL, (req) => {
  delete req.headers['if-none-match'];
  const addCustomerOp = 'addCustomerMutation';
  const { body } = req;
  if (body.hasOwnProperty('operationName' && body.operationName === addCustomerOp) {
    req.alias = addCustomerOp;
    req.reply({ data: addCustomer });
   }
});

// FILL UP A FORM

cy.get('[data-testid="customer-save-button"]').click();

cy.wait('@addCustomerMutation', { timeout: 60000 })
  .its('request.body.variables')
  .should('deep.equal', {
    clientId: 'client_id',
    customer: {
      firstName: 'test',
      lastName: 'tester',
      email: 'test@test.com',
      phone: {
        name: '',
        number: '(531) 731-3151',
       },
       alternatePhones: [],
    },
});

How can I resolve this issue? So far I tried:

None of them worked. However, the local tests ran and passes with all these options as well.

My GitHub Actions workflow look like this if it helps:

jobs:
  test:
    concurrency: test # so that we don't run tests for another branch at the same time
    runs-on: ubuntu-latest
    container: cypress/browsers
    steps:
      - name: Checkout code
        uses:  actions/checkout@v3
      - name: Setup npm token
        run: |
            echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN_RO }}" >> ./.npmrc
      - name: Setup node
        uses: actions/setup-node@v3
        with:
            node-version-file: '.nvmrc'
            registry-url: 'https://registry.npmjs.org'
            cache: npm
      - name: Npm install
        run: npm ci
      - name: Run tests
        uses: cypress-io/github-action@v5
        with:
          env: username=${{ secrets.CYPRESS_TEST_USER }},password=${{ secrets.CYPRESS_TEST_PASSWORD }},REACT_APP_URI=${{ secrets.REACT_APP_URI }}
          install-command: | # TODO: check node modules before you npm ci here
            npm ci --production=false
          browser: chrome
          spec: cypress/integration/*.spec.*
          start: npm run start:cypress
          wait-on: npx wait-on http://localhost:3000
      - name: Upload test screenshots 
        uses: actions/upload-artifact@v3
        if: failure()
        with:
          name: cypress-screenshots
          path: cypress/screenshots
      # Test run video was always captured, so this action uses "always()" condition
      - name: Upload test videos
        uses: actions/upload-artifact@v3
        if: always()
        with:
          name: cypress-videos
          path: cypress/videos

ege
  • 812
  • 6
  • 16
  • 1
    What's the value of `URL` locally vs. in GHA? – agoff Feb 06 '23 at 16:23
  • @agoff good catch, but they are the same and that shouldn't cause an issue – ege Feb 06 '23 at 19:00
  • 1
    It has to either be the URL, or you have different code on GH. The best way to check this out is to monitor all calls with a middleware intercept. BTW your long timeouts are a waste of time, `req.reply({ data: addCustomer })` means the request is never going to the server and if URL did match, it would reply immediately. – Lola Ichingbola Feb 06 '23 at 20:04
  • 1
    It was the URL... there was a one letter difference that I missed and surely told that wasn't the case. Thanks @agoff and Lola – ege Feb 19 '23 at 15:52

0 Answers0