Skip to content

test: isolate tests from the real keychain and home directory - #741

Open
arjankowski wants to merge 1 commit into
mainfrom
fix/isolate-tests-from-keychain
Open

arjankowski wants to merge 1 commit into
mainfrom
fix/isolate-tests-from-keychain

Conversation

@arjankowski

Copy link
Copy Markdown
Contributor

Running npm test could delete your Box CLI environments.

After #731, some login and logout tests that never ran before started running. A few of them start the CLI with no environments set up. The CLI then saves an empty list of environments, and in tests that list went straight to your real system keychain, replacing whatever you had there. Other tests also wrote files into your real ~/.box and ~/Downloads.

Tests now run in a sandbox. Before any test starts, test/helpers/isolate-environment.js:

  • gives the tests a temporary home folder instead of your real one, and empties it before each test;
  • swaps the system keychain for a simple in-memory one.

Your real keychain and home folder are no longer touched.

A few tests only passed because an earlier test had left a file or folder behind. They now set up what they need themselves.

Running `npm test` could delete your Box CLI environments.

After #731, some `login` and `logout` tests that never ran before started
running. A few of them start the CLI with no environments set up. The CLI
then saves an empty list of environments, and in tests that list went
straight to your real system keychain, replacing whatever you had there.
Other tests also wrote files into your real `~/.box` and `~/Downloads`.

Tests now run in a sandbox. Before any test starts,
`test/helpers/isolate-environment.js`:

- gives the tests a temporary home folder instead of your real one, and
  empties it before each test;
- swaps the system keychain for a simple in-memory one.

Your real keychain and home folder are no longer touched.

A few tests only passed because an earlier test had left a file or folder
behind. They now set up what they need themselves.
@arjankowski
arjankowski requested a review from a team November 13, 2026 11:26
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 43417052076

Coverage decreased (-0.03%) to 87.022%

Details

  • Coverage decreased (-0.03%) from the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • 2 coverage regressions across 1 file.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

2 previously-covered lines in 1 file lost coverage.

File Lines Losing Coverage Coverage
src/box-command.js 2 75.66%

Coverage Stats

Coverage Status
Relevant Lines: 6061
Covered Lines: 5498
Line Coverage: 90.71%
Relevant Branches: 2153
Covered Branches: 1650
Branch Coverage: 76.64%
Branches in Coverage %: Yes
Coverage Strength: 665.79 hits per line

💛 - Coveralls

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.

2 participants