Skip to content
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

Architecture overview #132

Merged
merged 1 commit into from
Jun 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions docs/Guide.Contributing.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Contributing to detox


### Clone detox and submodules

```sh
Expand All @@ -26,7 +25,7 @@ npm install -g react-native-cli

For all the internal projects (detox, detox-server, detox-cli, demos, test) `lerna` will create symbolic links in `node_modules` instead of `npm` copying the content of the projects. This way, any change you do on any code is there immediately. There is no need to update node modules or copy files between projects.

### Install `fbsimctl`
### Install `fbsimctl`

```sh
brew tap facebook/fb
Expand Down Expand Up @@ -58,7 +57,7 @@ lerna run test

Detox JS code is 100% test covered and is set to break the build if coverage gets below, so make sure you run unit tests (`lerna run test`) locally before pushing.

Alternatively, to run only the JS tests, run the following from the `detox/detox` directory:
Alternatively, to run only the JS tests, run the following from the `detox/detox` directory:

```sh
npm run unit
Expand Down Expand Up @@ -93,5 +92,3 @@ To run the e2e tests, after the application was built.
```sh
npm run e2e
```

**NOTE: The updated flow can always be found in [our CI build script](../scripts/ci.sh)**
19 changes: 19 additions & 0 deletions docs/Introduction.HowDetoxWorks.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,22 @@ Detox eliminates flakiness by automatically synchronizing your tests with the ap
* Keeping track of the React Native bridge which carries asynchronous messages
* Keeping track of asynchronous React Native layout and the shadow queue
* Keeping track of the JavaScript event loop which may contain pending asynchronous actions


### Architecture
The sequence diagram below shows the general communication scheme between the components in Detox.
![architecture overview](img/action-sequence.mmd.png)

To understand this topic more thoroughly we need to have a look at an example action in detail. The numbers in the listing below correlate with the ones in the diagram.

### Action (`element.tap`)

1. `element.tap()` in your test case is invoked.
2. `TapAction` in [`expect.js`](https://github.com/wix/detox/blob/master/detox/src/ios/expect.js) gets invoked
3. `TapAction` instance gets passed to [`invoke.js`](https://github.com/wix/detox/blob/master/detox/src/invoke.js), where it gets transformed to JSON. The resulting JSON correlates more with the native code than with the JS code for better extensibility.
4. JSON gets send to detox-server by [`Client.js`](https://github.com/wix/detox/blob/master/detox/src/client/Client.js)
6. detox-server forwards it to the testee in [`DetoxServer.js`](https://github.com/wix/detox/blob/master/detox-server/src/DetoxServer.js)
7. [`DetoxManager.m`](https://github.com/wix/detox/blob/master/detox/ios/Detox/DetoxManager.m) invokes the [`TestRunner.m`](https://github.com/wix/detox/blob/master/detox/ios/Detox/TestRunner.m). `TestRunner.m` uses [`MethodInvocation.m`](https://github.com/wix/detox/blob/master/detox/ios/Detox/MethodInvocation.m) to map the JSON representation of the native commands into the actual native command and executes it. *(8)*


*NOTE: the images can be updated with [mermaid](http://knsv.github.io/mermaid/#mermaid). The files can be found under `img-src`*
19 changes: 19 additions & 0 deletions docs/img-src/action-sequence.mmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
sequenceDiagram
participant Test Runner(1)
participant Tester(3)
participant Detox Server(5)
participant Testee(7)
participant Earl Grey(9)

%% Note over Test Runner(1),Detox Server(5): Runs on your computer
%% Note over Testee(7),Earl Grey(9): Runs on the device

Test Runner(1)->>Tester(3): assertion / action (2)
Tester(3)->>Detox Server(5): native code as JSON (4)
Detox Server(5)->>Testee(7): Websocket connection (6)
Testee(7)-x+Earl Grey(9): native invocation (8)
Note left of Earl Grey(9): EarlGrey waits for device to become idle again
Earl Grey(9)->>-Testee(7): (10)
Testee(7)->>Detox Server(5): (11)
Detox Server(5)->>Tester(3): (12)
Tester(3)->>Test Runner(1): (13)
3 changes: 3 additions & 0 deletions docs/img-src/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
Copy link
Member

Choose a reason for hiding this comment

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

I may be too picky, but the img output is not pretty enough. I imagine something slicker :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you know a better alternative for mermaid? I would love to have something with a source code, because it makes the whole thing extensible to other developers. (in contrast to a PS file or something)

Copy link
Member

Choose a reason for hiding this comment

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

Mermeid might be a good solution, but we need to either restructure the diagram, or at least remove the arrows going from one end point to itself, it makes the diagram much clearer IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, I will try a few more ways and link them here so we can discuss it on a visual basis

Copy link
Member

Choose a reason for hiding this comment

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

The new way is much nicer!


mermaid -o '../img' *.mmd
Binary file added docs/img/action-sequence.mmd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.