1 | Contributing Guide
|
2 | ==================
|
3 |
|
4 | Thanks for your interest in contributing to this project! This document aims to
|
5 | serve as a friendly guide for making your first contribution.
|
6 |
|
7 | ### Cloning the project
|
8 |
|
9 | ```sh
|
10 | git clone https://github.com/balena-io-modules/rendition.git
|
11 | cd rendition
|
12 | ```
|
13 |
|
14 | ### Installing npm dependencies
|
15 |
|
16 | ```sh
|
17 | npm install
|
18 | ```
|
19 |
|
20 | ### Installing docker
|
21 |
|
22 | [Docker][Docker] is required to run [visual regresion tests](#visual-testing)
|
23 | and to generate new screenshots. See the [docker installation
|
24 | documentation][Docker install] for information on how to install Docker in your
|
25 | environment.
|
26 |
|
27 | ### Running the storybook
|
28 |
|
29 | The interactive storybook can be launched by running:
|
30 |
|
31 | ```sh
|
32 | npm run build
|
33 | npm run start
|
34 | ```
|
35 |
|
36 | The storybook can be accessed at http://localhost:6006.
|
37 |
|
38 | Adding new components
|
39 | ---------------------
|
40 |
|
41 | Please open an issue to discuss any new components before starting work on
|
42 | them.
|
43 |
|
44 | Testing
|
45 | -------
|
46 |
|
47 | To run the test suite, run the following command:
|
48 |
|
49 | ```sh
|
50 | npm test
|
51 | ```
|
52 |
|
53 | We encourage our contributors to test the library before sending a pull request.
|
54 |
|
55 | We use [Jest snapshot testing](https://jestjs.io/docs/en/snapshot-testing) to
|
56 | help prevent regression bugs. If your change affects the html output of
|
57 | a component you may needs to update a snapshot, you can do this by running the
|
58 | following command:
|
59 |
|
60 | ```sh
|
61 | npm run jest -- -u
|
62 | ```
|
63 |
|
64 | *The test suite is run automatically by CI servers when you send a pull
|
65 | request.*
|
66 |
|
67 | Code is automatically linted and formatted by [Husky][husky] as a pre-commit hook.
|
68 |
|
69 | We make use of [EditorConfig] to communicate indentation, line endings and
|
70 | other text editing default. We encourage you to install the relevant plugin in
|
71 | your text editor of choice to avoid having to fix any issues during the review
|
72 | process.
|
73 |
|
74 |
|
75 | ### Visual testing
|
76 |
|
77 | You can run a screenshot test using the command:
|
78 |
|
79 | ```
|
80 | npm run test:local-visual
|
81 | ```
|
82 |
|
83 | A report will be generated and saved to `visual-testing-report.html`.
|
84 |
|
85 | If you have made changes to a component that will affect the way it
|
86 | looks in a story, screenshots should be generated using the command:
|
87 |
|
88 | ```
|
89 | npm run generate-screenshots
|
90 | ```
|
91 |
|
92 | This command will spawn a docker container, generate screenshots
|
93 | and copy them back to your local file system.
|
94 |
|
95 | Visual testing relies on a consistent execution environment, ensuring that
|
96 | control inputs and fonts are always rendered the same way. To ensure this
|
97 | happens both screenshot generation and testing steps are run inside a docker
|
98 | container.
|
99 |
|
100 | Screenshots of each story are stored in the `__screenshots__` directory. When
|
101 | the test suite runs, new screenshots are created and compared against the
|
102 | existing ones in the `__screenshots__` directory. Any differences will cause the
|
103 | tests to fail, as it indicates an unexpected visual change to a component.
|
104 |
|
105 | Updating documentation
|
106 | ----------------------
|
107 |
|
108 | All components have a corresponding markdown file that documents their API. The
|
109 | markdown files are found in `src/stories/README/`. The markdown files are
|
110 | displayed in the interactive storybook and also aggregated into the main README
|
111 | file. After making any changes to a component, make sure the corresponding
|
112 | markdown file is up to date and then update the README using the following
|
113 | command:
|
114 |
|
115 | ```sh
|
116 | npm run build:docs
|
117 | ```
|
118 |
|
119 | Commit Guidelines
|
120 | -----------------
|
121 |
|
122 | See [COMMIT-GUIDELINES.md][COMMIT-GUIDELINES] for a thorough guide on how to
|
123 | write commit messages.
|
124 |
|
125 | Sending a pull request
|
126 | ----------------------
|
127 |
|
128 | When sending a pull request, consider the following guidelines:
|
129 |
|
130 | - Write a concise commit message explaining your changes.
|
131 |
|
132 | - If applies, write more descriptive information in the commit body.
|
133 |
|
134 | - If your change affects the visuals of the library, consider attaching a
|
135 | screenshot.
|
136 |
|
137 | - Refer to the issue/s your pull request fixes, so they're closed automatically
|
138 | when your pull request is merged.
|
139 |
|
140 | - Write a descriptive pull request title.
|
141 |
|
142 | - Squash commits when possible, for example, when committing review changes.
|
143 |
|
144 | Before your pull request can be merged, the following conditions must hold:
|
145 |
|
146 | - The linter doesn't throw any warning.
|
147 |
|
148 | - All the tests pass.
|
149 |
|
150 | - The coding style aligns with the project's convention.
|
151 |
|
152 | Don't hesitate to get in touch if you have any questions or need any help!
|
153 |
|
154 | [COMMIT-GUIDELINES]: COMMIT-GUIDELINES.md
|
155 | [EditorConfig]: http://editorconfig.org
|
156 | [Docker]: https://www.docker.com/
|
157 | [Docker install]: https://docs.docker.com/install/
|