这是indexloc提供的服务,不要输入任何密码
Skip to content

test(turborepo-analytics): improve unit test coverage #10651

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 4 commits into from
Jul 14, 2025

Conversation

anthonyshew
Copy link
Contributor

@anthonyshew anthonyshew commented Jul 9, 2025

Summary

Improves test coverage for from 87.50% to 90.57% (+3.07%) in turobrepo-analytics.

Changes

Added 3 new tests to cover previously untested code paths:

  • Tests the method to ensure it handles timeouts gracefully
  • Tests error handling when the analytics client fails to record events
  • Tests the utility function to ensure it properly sets session IDs

Coverage Impact

  • Before: 87.50% coverage (12 missed regions out of 96 total)
  • After: 90.57% coverage (10 missed regions out of 106 total)
  • Improvement: +3.07 percentage points

All tests pass and cover important error handling and utility function scenarios.

Add 3 new tests to increase coverage from 87.50% to 90.57%:

- test_close_with_timeout: Tests the close_with_timeout method
- test_client_error_handling: Tests error handling when client fails
- test_add_session_id: Tests the add_session_id utility function

These tests cover previously untested code paths including timeout handling,
error scenarios, and utility functions.
@anthonyshew anthonyshew requested a review from a team as a code owner July 9, 2025 02:00
Copy link

vercel bot commented Jul 9, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
examples-basic-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 14, 2025 2:48pm
examples-designsystem-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 14, 2025 2:48pm
examples-gatsby-web 🔄 Building (Inspect) Visit Preview 💬 Add feedback Jul 14, 2025 2:48pm
examples-kitchensink-blog ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 14, 2025 2:48pm
examples-native-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 14, 2025 2:48pm
examples-nonmonorepo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 14, 2025 2:48pm
examples-svelte-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 14, 2025 2:48pm
examples-tailwind-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 14, 2025 2:48pm
examples-vite-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 14, 2025 2:48pm
turbo-site ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 14, 2025 2:48pm

@anthonyshew anthonyshew changed the title test(turborepo-analytics): improve test coverage by 3.07% test(turborepo-analytics): improve unit test coverage Jul 9, 2025
Comment on lines 385 to 416
#[tokio::test]
async fn test_close_with_timeout() {
let (tx, _rx) = mpsc::unbounded_channel();

let client = DummyClient {
events: Default::default(),
tx,
};

let (analytics_sender, analytics_handle) = start_analytics(
APIAuth {
token: "foo".to_string(),
team_id: Some("bar".to_string()),
team_slug: None,
},
client.clone(),
);

// Send an event
analytics_sender
.send(AnalyticsEvent {
session_id: None,
source: CacheSource::Local,
event: CacheEvent::Hit,
hash: "".to_string(),
duration: 0,
})
.unwrap();

// Test close_with_timeout - should not panic
analytics_handle.close_with_timeout().await;
}
Copy link
Member

Choose a reason for hiding this comment

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

We can drop this test, I'm not sure what this tests that other ones don't already.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

SGTM

anthonyshew and others added 2 commits July 14, 2025 08:34
Co-authored-by: Chris Olszewski <chris.olszewski@vercel.com>
@anthonyshew anthonyshew enabled auto-merge (squash) July 14, 2025 14:35
@anthonyshew anthonyshew merged commit 518ce35 into main Jul 14, 2025
41 checks passed
@anthonyshew anthonyshew deleted the improve-analytics-coverage branch July 14, 2025 15:12
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