Skip to content

👷 Load BrowserStack credentials from .env file#4189

Merged
thomas-lebeau merged 1 commit intomainfrom
thomas.lebeau/safer-bs-credentials
Feb 17, 2026
Merged

👷 Load BrowserStack credentials from .env file#4189
thomas-lebeau merged 1 commit intomainfrom
thomas.lebeau/safer-bs-credentials

Conversation

@thomas-lebeau
Copy link
Collaborator

@thomas-lebeau thomas-lebeau commented Feb 16, 2026

Motivation

BrowserStack credentials (BS_USERNAME and BS_ACCESS_KEY) currently need to be manually exported as environment variables before running BS tests. This is error-prone and credentials can accidentally end up in shell history.

Changes

  • Add --env-file-if-exists=.env flag to test:unit:bs and test:e2e:bs scripts so Node.js automatically loads variables from a .env file when present
  • Add .env* to .gitignore (with !.env.example exception) to prevent credential leaks
  • Add .env.example documenting the expected variables

This is fully opt-in — exporting env vars manually as before still works. The .env file is only loaded if it exists (--env-file-if-exists).

1Password Environments

For a more secure setup, you can use 1Password Environments to manage the .env file. 1Password can mount the file on the filesystem on demand and will ask for permission before

Test instructions

  1. Create a .env file at the repo root with your BrowserStack credentials:
    BS_USERNAME=your_username
    BS_ACCESS_KEY=your_key
    
  2. Run yarn test:unit:bs or yarn test:e2e:bs — credentials should be loaded automatically
  3. Verify the .env file is not tracked by git (git status should not show it)

Checklist

  • Tested locally
  • Tested on staging
  • Added unit tests for this change.
  • Added e2e/integration tests for this change.
  • Updated documentation and/or relevant AGENTS.md file

- Add --env-file-if-exists=.env to test:unit:bs and test:e2e:bs scripts
- Gitignore .env files to prevent accidental credential leaks
- Add .env.example to document expected environment variables
@thomas-lebeau thomas-lebeau requested a review from a team as a code owner February 16, 2026 08:08
@thomas-lebeau thomas-lebeau merged commit c52821b into main Feb 17, 2026
22 checks passed
@thomas-lebeau thomas-lebeau deleted the thomas.lebeau/safer-bs-credentials branch February 17, 2026 10:46
@github-actions github-actions bot locked and limited conversation to collaborators Feb 17, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments