The CavyTester app exercises the Cavy API
in a native mobile environment to test against regressions and make it safer to
modify existing features or add new ones.
You will need to install Cavy CLI to run the tests.
CavyTester can be run on its own to demonstrate Cavy running in a sample React
Native app. However, it's also valuable to have it run against a local version
of the cavy library when testing changes to Cavy itself. To do so, take the
following steps:
-
Clone the Cavy repo:
git clone https://github.com/pixielabs/cavy.git -
Clone this repo:
git clone https://github.com/pixielabs/cavy-tester.git -
Install dependencies:
cd cavy-testeryarn install -
Install wml - an alternative to symlinking (which React Native does not support):
yarn global add wml -
Link your local version of Cavy to
CavyTester's node modules:wml add {PATH_TO_CAVY} node_modules/cavy -
(For iOS testing) Install CocoaPods, then:
cd iospod installcd .. -
Start wml in one terminal:
wml start -
Start the Metro bundler in another terminal:
npx react-native start -
Run the tests in (yet) another terminal!
cavy run-ios --devor
cavy run-android --dev
You should then be able to make changes to your local version of Cavy, whilst running CavyTester tests in the background 🎉
- Create a new file under
src/scenarioswith a concise name describing your scenario. You can copysrc/scenarios/exists.jsas a starting point. - Export the following variables from your file:
key: A unique identifier for your set of tests. You can probably just use the filename.Screen: A React component which renders the UI necessary to exhibit the behavior you're testing.label: A short description of your scenario. Used for labeling the scenario inCavyTester's menu.spec: A Cavy spec which validates your scenario.
- In
scenarios/index.js, import your scenario and add it to thescenariosarray
Example CavyTester scenario for the spec.exists functionality:
// exists.js
import React from 'react';
import { Text } from 'react-native';
import { useCavy } from 'cavy';
// `key` is descriptive, concise, and alphanumeric
export const key = 'Exists';
const testId = `${key}.element`; // uses `key` as testId namespace
// `Screen` component is as minimal as necessary to validate scenario
export const Screen = () => {
const generateTestHook = useCavy();
return <Text ref={generateTestHook(testId)}>I am text that is present</Text>;
};
// `label` describes the scenario being tested
export const label = 'spec.exists checks for element';
export const spec = spec =>
// uses `key` for `describe` string
spec.describe(key, () =>
// uses `label` for `it` string
spec.it(label, async () => {
// validate scenario
await spec.exists(testId);
})
);Thanks goes to Ryan Stelly for CavyTester's
original design and implementation 🙌