Add generateQuantityTypeSamples utility for simulator test data
Simulator testing is difficult without health data. This adds a utility to generate realistic quantity samples for testing.
Changes
-
New function
generateQuantityTypeSamples(quantityType, numberOfSamples, options?)- Generates samples with realistic value ranges for 60+ health metrics (steps, heart rate, calories, etc.)
- Distributes samples evenly across time period (defaults to last 30 days)
- Returns boolean indicating success
-
Options interface with
fromDateandtoDatefor custom date ranges -
Exported from both iOS and cross-platform entry points
Usage
import { generateQuantityTypeSamples } from '@kingstinct/react-native-healthkit'
// Generate 30 days of step data
await generateQuantityTypeSamples('HKQuantityTypeIdentifierStepCount', 30)
// Custom date range
await generateQuantityTypeSamples(
'HKQuantityTypeIdentifierHeartRate',
7,
{ fromDate: new Date('2024-01-01'), toDate: new Date('2024-01-07') }
)
Value ranges are predefined per quantity type (e.g., heart rate: 60-100 bpm, steps: 1000-15000).
Original prompt
This section details on the original issue you should resolve
<issue_title>Health data generation</issue_title> <issue_description>Thanks for the nice modern lib in TypeScript!
How do you handle testing on the simulator, given that it has no health data? Would it make sense to have an ability to generate test data?</issue_description>
<agent_instructions>Add a function to add quantitySamples with realistic inputs, along these lines
type Options = { fromDate, toDate } // default to last 30 days, and spread out the generation of data over this time period generateQuantityTypeSamples(quantityType, numberOfSamples, options?: Options) ```</agent_instructions> ## Comments on the Issue (you are @copilot in this section) <comments> <comment_new><author>@robertherber</author><body> That's a great idea! I don't have time to look at it right now - but would be more than happy to merge a pull request :)</body></comment_new> </comments>
- Fixes kingstinct/react-native-healthkit#8
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.
⚠️ No Changeset found
Latest commit: d96d927abb73e5028535fa4e1b1211a6b293de41
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
npm i https://pkg.pr.new/kingstinct/react-native-healthkit/@kingstinct/react-native-healthkit@263
commit: d96d927