|
| 1 | +# Firestore Spec Tests |
| 2 | + |
| 3 | +The Firestore Spec Tests are a suite of unit tests that fake out external |
| 4 | +sources of events so that they can be completely controlled from the tests |
| 5 | +themselves and verify the correct handling of these events. |
| 6 | + |
| 7 | +There are three sources of external events in the SDK: user writes, input from |
| 8 | +the persistence layer, and input from the watch stream. The spec tests fake all |
| 9 | +of these. Since these external events are asynchronous in nature, in the real |
| 10 | +world there is some non-determinism in the ordering of events. The spec tests |
| 11 | +allow these orderings to be specified explicitly, enabling orderings that are |
| 12 | +difficult or impossible to force when connected to a real backend. In addition, |
| 13 | +when running under Node, the IndexedDb persistence layer is faked. |
| 14 | + |
| 15 | +The Firestore Spec Tests are portable and must be kept in sync between the Web |
| 16 | +SDK (this SDK), Android SDK, and iOS SDK. The Web SDK contains the authoritative |
| 17 | +test definitions and they must be manually "exported" to the Android SDK and iOS |
| 18 | +SDK when they change. |
| 19 | + |
| 20 | +## Running the Tests |
| 21 | + |
| 22 | +The spec tests are part of the unit test suite of each SDK. Therefore, to run |
| 23 | +the spec tests simply run the entire unit test suite and the spec tests will be |
| 24 | +executed as a part of it. |
| 25 | + |
| 26 | +## Test Tags |
| 27 | + |
| 28 | +Each spec test can specify zero or many "tags" that influence the test's |
| 29 | +execution. Some of the commonly-used tags are documented here; see |
| 30 | +[describe_spec.ts](describe_spec.ts) for the full set of supported tags. |
| 31 | + |
| 32 | +- `exclusive` - Only run this spec test and skip all others. It can be useful |
| 33 | + to apply this tag to a test while it is under active development or debugging. |
| 34 | + Tests should never be checked into source control with this tag. |
| 35 | + |
| 36 | +- `no-android` and `no-ios` - Do not run this spec test on Android and/or iOS, |
| 37 | + respectively. It may be useful to specify these tags if the functionality has |
| 38 | + not been or never will be ported to these platforms. |
| 39 | + |
| 40 | +## Exporting the Tests |
| 41 | + |
| 42 | +To export the tests use the [generate_spec_json.sh](../generate_spec_json.sh) |
| 43 | +script, specifying a single argument whose value is the destination directory |
| 44 | +into which to place the generated files. |
| 45 | + |
| 46 | +#### Exporting the Tests to the Android SDK |
| 47 | + |
| 48 | +To export the spec tests to the Android SDK, run the following command: |
| 49 | + |
| 50 | +``` |
| 51 | +cd ~/firebase-js-sdk/packages/firestore/test/unit && |
| 52 | +./generate_spec_json.sh ~/firebase-android-sdk/firebase-firestore/src/test/resources/json |
| 53 | +``` |
| 54 | + |
| 55 | +This command assumes that this Git repository is cloned into `~/firebase-js-sdk` |
| 56 | +and the Android SDK is cloned into `~/firebase-android-sdk`. |
| 57 | + |
| 58 | +#### Exporting the Tests to the iOS SDK |
| 59 | + |
| 60 | +To export the spec tests to the iOS SDK, run the following command: |
| 61 | + |
| 62 | +``` |
| 63 | +cd ~/firebase-js-sdk/packages/firestore/test/unit && |
| 64 | +./generate_spec_json.sh ~/firebase-ios-sdk/Firestore/Example/Tests/SpecTests/json |
| 65 | +``` |
| 66 | + |
| 67 | +This command assumes that this Git repository is cloned into `~/firebase-js-sdk` |
| 68 | +and the iOS SDK is cloned into `~/firebase-ios-sdk`. |
0 commit comments