Skip to content

add default value to profile env variable - #3443

Merged
DavertMik merged 2 commits into
codeceptjs:3.xfrom
dwentland24:undefined-profile-env-variable
Oct 24, 2022
Merged

add default value to profile env variable#3443
DavertMik merged 2 commits into
codeceptjs:3.xfrom
dwentland24:undefined-profile-env-variable

Conversation

@dwentland24

Copy link
Copy Markdown
Contributor

Motivation/Description of the PR

Assignment of undefined profile to env variable with process.env.profile resulted in a string of "undefined".
This results in mysterious behaviors with code like const profile = process.env.profile || 'chrome'. The env variable cannot evaluate to false as it holds the string undefined.

This PR sets as empty string as default value, so not setting any profile in the command results in an empty string of the profile env variable.

Resolves #3339

Applicable helpers:

  • WebDriver
  • Puppeteer
  • Nightmare
  • REST
  • FileHelper
  • Appium
  • Protractor
  • TestCafe
  • Playwright

Applicable plugins:

  • allure
  • autoDelay
  • autoLogin
  • customLocator
  • pauseOnFail
  • coverage
  • retryFailedStep
  • screenshotOnFail
  • selenoid
  • stepByStepReport
  • stepTimeout
  • wdio
  • subtitles

Type of change

  • 🔥 Breaking changes
  • 🚀 New functionality
  • 🐛 Bug fix
  • 📋 Documentation changes/updates
  • ♨️ Hot fix
  • 🔨 Markdown files fix - not related to source code
  • 💅 Polish code

Checklist:

  • Tests have been added
  • Documentation has been added (Run npm run docs)
  • Lint checking (Run npm run lint)
  • Local tests are passed (Run npm test)

@mirao

mirao commented Oct 13, 2022

Copy link
Copy Markdown
Contributor

Wouldn't be better to return value undefined (of type undefined) instead of '' (an empty string)?
I know that const profile = process.env.profile || 'chrome' works the same way for undefined or ''.
But e.g. if you use if (process.env.profile === undefined) it won't work with your solution.

@dwentland24

Copy link
Copy Markdown
Contributor Author

@mirao Yes, you are right.

I would propose to set the env variable only if options.profile is not empty. So we have an unset env variable if options.profile is empty.

@DavertMik DavertMik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@DavertMik
DavertMik merged commit e4c1273 into codeceptjs:3.x Oct 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

process.env.profile is the string "undefined" when no --profile is specified

5 participants