Cumulocity-IoT / cumulocity-cypress

Collection of commands and utilities to be used for automating tests for Cumulocity with Cypress.
Apache License 2.0
8 stars 2 forks source link

Fix c8yclient authentication error #1

Closed thomaswinkler closed 1 year ago

thomaswinkler commented 1 year ago

If c8yclient authentication fails in authenticateClient, the error is not mapped to CypressError. This results in wrong and unreadable error output.

Error
the object {
  "codeFrame": {
    "absoluteFile": "/Users/twi/Projects/oee/oee-ui/node_modules/@iota/cumulocity-cypress-shared-dev/lib/commands/c8yclient.js"
    "column": 1
    "frame": "  229 | // Cookie authentication. Client.authenticate() only works with BasicAuth\n  230 | function authenticateClient(auth, baseUrl) {\n> 231 |   return cy.then(async () => {\n      | ^\n  232 |     const clientCore = new FetchClient(auth, baseUrl);\n  233 |     clientCore.defaultHeaders = {\n  234 |       "content-type": "application/json","
    "language": "js"
    "line": 231
    "originalFile": "node_modules/@iota/cumulocity-cypress-shared-dev/lib/commands/c8yclient.js"
    "relativeFile": "node_modules/@iota/cumulocity-cypress-shared-dev/lib/commands/c8yclient.js"
  }

  "isCyFailErr": true
  "isPending": true
  "name": "CypressError"
  "parsedStack": [
    {
      "message": "[object Object]"
      "whitespace": ""
    }
    {
      "message": "From Your Spec Code:"
      "whitespace": ""
    }
    {
      "absoluteFile": "/Users/twi/Projects/oee/oee-ui/node_modules/@iota/cumulocity-cypress-shared-dev/lib/commands/c8yclient.js"
      "column": 0
      "fileUrl": "http://localhost:9000/__cypress/tests?p=cypress/support/e2e.ts"
      "function": "authenticateClient"
      "line": 231
      "originalFile": "webpack://oee/./node_modules/@iota/cumulocity-cypress-shared-dev/lib/commands/c8yclient.js"
      "relativeFile": "node_modules/@iota/cumulocity-cypress-shared-dev/lib/commands/c8yclient.js"
      "whitespace": "    "
    }
    {
      "absoluteFile": "/Users/twi/Projects/oee/oee-ui/node_modules/@iota/cumulocity-cypress-shared-dev/lib/commands/c8yclient.js"
      "column": 0
      "fileUrl": "http://localhost:9000/__cypress/tests?p=cypress/support/e2e.ts"
      "function": "Context.eval"
      "line": 203
      "originalFile": "webpack://oee/./node_modules/@iota/cumulocity-cypress-shared-dev/lib/commands/c8yclient.js"
      "relativeFile": "node_modules/@iota/cumulocity-cypress-shared-dev/lib/commands/c8yclient.js"
      "whitespace": "    "
    }
  ]
  "res": "[object Response]"
  "stack": "[object Object]\nFrom Your Spec Code:\n    at authenticateClient (webpack://oee/./node_modules/@iota/cumulocity-cypress-shared-dev/lib/commands/c8yclient.js:231:0)\n    at Context.eval (webpack://oee/./node_modules/@iota/cumulocity-cypress-shared-dev/lib/commands/c8yclient.js:203:0)"
} was thrown, throw an Error :)

Because this error occurred during a before all hook we are skipping all of the remaining tests.