Skip to content

add default value to profile env variable #3443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 24, 2022

Conversation

dwentland24
Copy link
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
Copy link
Contributor

mirao commented Oct 13, 2022

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
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.

Copy link
Contributor

@DavertMik DavertMik left a comment

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