test: add tests for project-cache and env-file modules#200
Merged
Conversation
Add comprehensive tests for two previously uncovered modules: ## db/project-cache.ts (19 tests) - getCachedProject: undefined on miss, returns cached data on hit - setCachedProject: creates entries, upserts on conflict, stores timestamps - getCachedProjectByDsnKey: separate key namespace for DSN lookups - setCachedProjectByDsnKey: stores by DSN public key - clearProjectCache: clears all entries - Cache key uniqueness and edge cases (special chars, numeric IDs) ## dsn/env-file.ts (35 tests) Property-based tests: - Extracts DSN from unquoted, double-quoted, single-quoted values - Returns null when no SENTRY_DSN present - Handles whitespace around equals sign Unit tests for edge cases: - Empty content, comments, trailing comments - Windows line endings, values with equals signs - Multiple SENTRY_DSN declarations (first wins) Integration tests with temp directories: - detectFromEnvFiles: priority order (.env.local > .env) - detectFromAllEnvFiles: collects all DSNs, returns mtimes - detectFromMonorepoEnvFiles: scans packages/, apps/ subdirs Coverage improvements (when run individually): - project-cache.ts: 9.90% → 100% - env-file.ts: 13.73% → 99.19%
Contributor
Codecov Results 📊✅ Patch coverage is 100.00%. Project has 1746 uncovered lines. Files with missing lines (34)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 77.97% 77.99% +0.02%
==========================================
Files 58 58 —
Lines 7933 7933 —
Branches 0 0 —
==========================================
+ Hits 6185 6187 +2
- Misses 1748 1746 -2
- Partials 0 0 —Generated by Codecov Action |
Contributor
Semver Impact of This PR⚪ None (no version bump detected) 📋 Changelog PreviewThis is how your changes will appear in the changelog.
🤖 This preview updates automatically when you update the PR. |
Address PR review comment - verify exactly 2 DSNs are returned and check both specific DSN values are present.
- project-cache.test.ts: Use correct env var SENTRY_CONFIG_DIR (not SENTRY_CLI_CONFIG_DIR) for proper database isolation between tests - env-file.test.ts: Move beforeEach/afterEach hooks inside integration test describe block so pure function tests don't create unnecessary temp directories. Also removed unused SENTRY_CLI_CONFIG_DIR setting since env-file functions don't use the database.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
Add closeDatabase() call in afterEach to release SQLite WAL-mode file handles before deleting temp directories. This prevents orphaned temp directories on Windows where locked files can't be deleted.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add comprehensive tests for two previously uncovered modules, bringing 54 new tests total.
Tests Added
db/project-cache.ts(19 tests)getCachedProjectsetCachedProjectgetCachedProjectByDsnKeysetCachedProjectByDsnKeyclearProjectCacheCoverage: 9.90% → 100% (when run individually)
dsn/env-file.ts(35 tests)Property-based tests (6):
Edge case unit tests (12):
Integration tests with temp directories (17):
detectFromEnvFiles: priority order (.env.local > .env), handles missing filesdetectFromAllEnvFiles: collects all DSNs, returns source mtimesdetectFromMonorepoEnvFiles: scans packages/, apps/ subdirectoriesENV_FILESconstant: correct priority orderCoverage: 13.73% → 99.19% (when run individually)
Running the Tests