mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2025-12-23 22:18:36 -05:00
523da746f2dce60bd631b3c340a6a0336da45711
* Several updates to testing * Restructured tests so they are in their own dir at the root * Added an integration test that mocks the response from inaturalistjs * Instead of mocking Realm, I mocked the Realm config so it writes to an in-memory database for tests * Added test data factories with factoria and faker TODO * Try mocking hooks to make a unit tests for the ObsList component; it should be possible to write unit tests for components with hooks * Data in the in-memory Realm db is probably sticking around between tests; we need a way to trash the db after each test * Tried to address logbox failure in Github Actions test run * Tried bumping the timeout for tests for github actions * Added skip duplicates and Slack notification to test action * Added unit test for ObsList * Seriously, how much time do you need to run a test... * Added missing factory import * Test fixes for context & providers * DRY out ObsList.test.js a bit * Made ObsList.test.js synchronous In theory I suspect all component tests should be synchronous because if you've mocked out all the hooks, there should be no reason to wait for effects to complete. Also removed subscriptionRef which didn't seem to be doing anything.
iNaturalistReactNative
Install packages and pods
- Run
npm install - Run
npx pod-install iosorcd ios && pod installfrom the root directory
Run build
- Run
npm start -- --reset-cache(npm startworks too, but resetting the cache each time makes for a lot less build issues) - Run
npm run iosornpm run android
Tests
# Run all tests
npm test
# Run test paths matching a pattern
./node_modules/.bin/jest MyObs
# Run individual tests matching a pattern
./node_modules/.bin/jest -t accessibility
We currently have two kinds of tests
tests/integration: Tests the test the integration of multiple modules, e.g. a list of observation that makes requests to a mocked API, persists the response data in local storage, retrieves the data from local storage and renders components.tests/unit: Tests that only test specific modules, like a single component, or a hook.
We're using Jest and React Native Testing Library for most of our tests, factoria and faker.js to generate test data for use with mocks. Local* model factories represent locally persisted data, while Remote* factories represent that kinds of records we get from an API or external package.
Troubleshooting
- Run
react-native clean-project. This will give you options to clean caches, clean builds, reinstall pods, and reinstall node_modules. Using this eliminates a lot of hard-to-diagnose build issues.
Description
Languages
Fluent
63.1%
JavaScript
19.6%
TypeScript
16.8%
Ruby
0.4%