cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.85k stars 3.17k forks source link

Cypress crashes on trying to record with an empty key #14571

Closed bahmutov closed 3 years ago

bahmutov commented 3 years ago

Cypress v6.2.1

Cypress crashes if you pass an empty --key CLI parameter.

Reproduction steps:

Crash

token.slice is not a function
TypeError: token.slice is not a function
    at Object.hide (/Users/gleb/Library/Caches/Cypress/6.2.1/Cypress.app/Contents/Resources/app/packages/server/lib/util/keys.js:7:11)
    at /Users/gleb/Library/Caches/Cypress/6.2.1/Cypress.app/Contents/Resources/app/packages/server/lib/modes/record.js:406:26

Note: if you simply try

cypress run --record --key

The our CLI catches the empty parameter and shows a good message. You must follow --key by something else. Then it somehow evades our CLI argument checks. I can see in the crashing case

  cypress:cli spawning Cypress with executable: /Users/gleb/Library/Caches/Cypress/6.2.1/Cypress.app/Contents/MacOS/Cypress +3ms
  cypress:cli spawn args [ '--no-sandbox', '--', '--run-project', '/Users/gleb/git/cypress-test-tiny', '--ci-build-id', 'bar', '--key', '--parallel', '--record', true, '--cwd', '/Users/gleb/git/cypress-test-tiny' ] { detached: false, stdio: [ 'inherit', 'inherit', 'pipe' ] }

Why this matters

As we found with @estrada9166 if you pass an environment variable on CI that is undefined, it happily crashes

npx cypress run --record --key $KEY_DOES_NOT_EXIST --parallel
bahmutov commented 3 years ago

Funny that this crash happens when trying to print an error message when cannot record :)

bahmutov commented 3 years ago

Seems the --key by its presence gets cast as a boolean

  cypress:electron spawning /Users/gleb/git/cypress/packages/electron/dist/Cypress/Cypress.app/Contents/MacOS/Cypress with args [
  '--max-http-header-size=1048576',
  '--ciBuildId=bar',
  '--config={}',
  '--cwd=/Users/gleb/git/cypress/packages/server',
  '--key=true',
  '--parallel=true',
  '--record=true'
]

Looking at the CLI parsing the arguments, it gets confused :) I am looking at DEBUG=cypress:cli:cli

--key --parallel ...
{ key: '--parallel' }

then it passes the list of arguments to the app where it gets --key=true

cypress-bot[bot] commented 3 years ago

The code for this is done in cypress-io/cypress#14593, but has yet to be released. We'll update this issue and reference the changelog when it's released.

cypress-bot[bot] commented 3 years ago

Released in 6.3.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to Cypress v6.3.0, please open a new issue.