Add contributing docs

Reviewed By: danielbuechele

Differential Revision: D6976258

fbshipit-source-id: 71b3d0ab4a071ce0c4a9c1241cd6295aa6d52b8e
This commit is contained in:
Emil Sjölander
2018-02-13 07:06:31 -08:00
committed by Facebook Github Bot
parent 49f1d7b5f6
commit cac77e5ffa
6 changed files with 94 additions and 29 deletions

View File

@@ -0,0 +1,45 @@
---
path: "contributing/testing"
title: "Testing"
hasPlayground: false
---
# Testing
Yoga tries to be as close as possible to chrome in its flexbox behaviour.
To ensure this most of Yoga's test suite is automatically generateded from
running the corresponding layout in chrome using a webdriver which then generates
C++ test which asserts that Yoga will produce matching outputs for that layout.
## Running the Test Suite
1. Yoga builds with [buck](https://buckbuild.com). Follow their documentation to get up and running.
2. For testing Yoga relies on [gtest](https://github.com/google/googletest) as a submodule. After cloning Yoga run `git submodule init` followed by `git submodule update`.
3. In a terminal from the root of your Yoga checkout run `buck test //:yoga`.
## Adding a Test
Instead of manually writing a test which ensures parity with web implementations
of Flexbox we make use of a generated test suite. We use `gentest/gentest.rb` to
generate this test suite. Write the html which you want to verify in Yoga and put
it in the `gentest/fixtures` folder, such as the following.
```html
<div id="my_test" style="width: 100px; height: 100px; align-items: center;">
<div style="width: 50px; height: 50px;"></div>
</div>
```
Run `gentest/gentest.rb` to generate test code and re-run `buck test //:yoga`
to validate the behavior. One test case will be generated for every root `div`
in the input html with the string in the `id` corresponding to the test name.
You may need to install the latest watir gem (`gem install watir`) and
[ChromeDriver](https://sites.google.com/a/chromium.org/chromedriver/) to
run `gentest/gentest.rb` Ruby script.
## Manual test
For some aspects of Yoga we cannot generate a test using the test generation
infrastructure described earlier. For these cases we manually write a test in
the `/tests` directory.