archfz / cypress-terminal-report

Plugin for cypress. Logs to terminal and files, mimicking cypress UI.
MIT License
499 stars 39 forks source link

cy:xhr logs show "undefined" in Cypress 13 #209

Closed matmannion closed 1 year ago

matmannion commented 1 year ago

Behaviour with Cypress 12, XHR logs show only failed requests:

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Cypress:        12.17.4                                                                        │
  │ Browser:        Edge 116 (headless)                                                            │
  │ Node Version:   v18.17.1 (/usr/local/bin/node)                                                 │
...
  │ Experiments:    experimentalMemoryManagement=true                                              │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────

  Running:  fct-activity-channel.feature                                                   (1 of 16)
  cypress:server:browsers browsers.kill called with no active instance +0ms
  cypress:server:browsers getBrowserLauncher { browser: { name: 'edge', family: 'chromium', channel: 'stable', displayName: 'Edge', version: '116.0.1938.62', path: 'edge', minSupportedVersion: 79, majorVersion: '116', isHeadless: true, isHeaded: false } } +1ms
  cypress:server:browsers opening browser { name: 'edge', family: 'chromium', channel: 'stable', displayName: 'Edge', version: '116.0.1938.62', path: 'edge', minSupportedVersion: 79, majorVersion: '116', isHeadless: true, isHeaded: false } +5ms
  cypress:server:browsers browser opened +1s
  Activity Channel
          cy:xhr ✘  GET https://isda-isda-frontend-test-8084-comment-ltiuxb.dev.i.nakhoda.ai/api/v1/subAccounts/018a5010-d45c-4c6b-43eb-5e40cddfbc8f/negotiations/018a5010-047d-2638-f62b-a506137c3fd6/preview

Behaviour with Cypress 13:

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Cypress:        13.1.0                                                                         │
  │ Browser:        Edge 116 (headless)                                                            │
  │ Node Version:   v18.17.1 (/usr/local/bin/node)                                                 │
...
  │ Experiments:    experimentalMemoryManagement=true                                              │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘

  Running:  fct-activity-channel.feature                                                   (1 of 16)
  cypress:server:browsers browsers.kill called with no active instance +0ms
  cypress:server:browsers getBrowserLauncher { browser: { name: 'edge', family: 'chromium', channel: 'stable', displayName: 'Edge', version: '116.0.1938.69', path: 'edge', minSupportedVersion: 79, majorVersion: '116', isHeadless: true, isHeaded: false } } +0ms
  cypress:server:browsers opening browser { name: 'edge', family: 'chromium', channel: 'stable', displayName: 'Edge', version: '116.0.1938.69', path: 'edge', minSupportedVersion: 79, majorVersion: '116', isHeadless: true, isHeaded: false } +4ms
  cypress:server:browsers browser opened +2s
  Activity Channel
          cy:xhr ❖  undefined undefined
          cy:xhr ❖  undefined undefined
          cy:xhr ❖  undefined undefined
          cy:xhr ❖  undefined undefined
          cy:xhr ❖  undefined undefined
          cy:xhr ❖  undefined undefined
          cy:xhr ❖  undefined undefined
          cy:xhr ❖  undefined undefined
          cy:xhr ❖  undefined undefined
          cy:xhr ❖  undefined undefined
          cy:xhr ❖  undefined undefined
          cy:xhr ❖  undefined undefined
          cy:xhr ❖  undefined undefined
...etc

Setup:

import installLogsCollector from 'cypress-terminal-report/src/installLogsCollector'

// Logs Cypress output to STDOUT for CI logs when using cypress run
installLogsCollector({
  collectTypes: ['cy:log', 'cy:xhr', 'cy:request', 'cy:intercept', 'cy:command'],
  debug: false,
  enableExtendedCollector: false,
  filterLog([type, message, severity]) {
    // Always print steps
    if (type === 'cy:command') {
      return message.startsWith('step\t')
    }

    // Always print cy:log
    if (type === 'cy:log') {
      return true
    }

    if (type === 'cy:xhr' && severity === 'error' && message.endsWith(' - ABORTED')) {
      // Don't show ABORTED requests
      return false
    }

    return ['error', 'warning'].includes(severity)
  },
})
archfz commented 1 year ago

They probably made some breaking change. Contribution is welcome.

matmannion commented 1 year ago

Working on a PR for this, the logs are under an extra key "props" so I think this will be a breaking change for Cypress 13:

{
  "displayName": "xhr",
  "name": "request",
  "type": "parent",
  "event": true,
  "url": "https://createiq.local/api/v1/user/context",
  "method": "GET",
  "timeout": 0,
  "message": "[data-qa=\"email\"]",
  "id": "log-https://createiq.local-199",
  "state": "passed",
  "instrument": "command",
  "hookId": "r3",
  "testId": "r3",
  "testCurrentRetry": 0,
  "viewportWidth": 1366,
  "viewportHeight": 768,
  "wallClockStartedAt": "2023-09-07T10:23:09.340Z",
  "createdAtTimestamp": 1694082189340.3,
  "updatedAtTimestamp": 1694082192165.5,
  "group": "log-https://createiq.local-23",
  "groupLevel": 3,
  "chainerId": "ch-https://createiq.local-77",
  "ended": true,
  "snapshot": false,
  "consoleProps": {
    "name": "request",
    "type": "event",
    "props": {
      "Resource Type": "xhr",
      "Method": "GET",
      "URL": "https://createiq.local/api/v1/user/context",
      "Request went to origin?": "yes",
      "Request Headers": {
        "sec-ch-ua": "\"Chromium\";v=\"116\", \"Not)A;Brand\";v=\"24\", \"Google Chrome\";v=\"116\"",
        "Accept": "application/json, text/plain, */*",
        "Referer": "https://createiq.local/redesign/active",
        "sec-ch-ua-mobile": "?0",
        "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36",
        "sec-ch-ua-platform": "\"macOS\""
      },
      "Response Status Code": 401,
      "Response Headers": {
        "date": "Thu, 07 Sep 2023 10:23:06 GMT",
        "x-content-type-options": "nosniff",
        "x-permitted-cross-domain-policies": "master-only",
        "Transfer-Encoding": "chunked",
        "Connection": "keep-alive",
        "x-xss-protection": "1; mode=block",
        "x-request-id": "018a6f2ac7f298acd32fbd5b65d1d632",
        "pragma": "no-cache",
        "referrer-policy": "strict-origin-when-cross-origin",
        "server": "nginx",
        "Vary": "Origin, Accept-Encoding",
        "content-type": "application/json",
        "cache-control": "no-cache, no-store, must-revalidate, max-age=0, s-maxage=0",
        "permissions-policy": "camera=(), microphone=(), geolocation=(), browsing-topics=()",
        "Keep-Alive": "timeout=5",
        "expires": "0"
      }
    }
  },
  "renderProps": {
    "indicator": "bad",
    "message": "GET 401 /api/v1/user/context",
    "wentToOrigin": true,
    "interceptions": []
  }
}
archfz commented 1 year ago

I wonder if we use consoleProps in other commands logs as well.

matmannion commented 1 year ago

I had a look through but couldn't see any usage outside of XHR and fetch