|
| 1 | +# Contributing Guide |
| 2 | + |
| 3 | +Before submitting your contribution, please make sure to take a moment and read through the following guidelines: |
| 4 | + |
| 5 | +- [Pull Request Guidelines](#pull-request-guidelines) |
| 6 | +- [Development Setup](#development-setup) |
| 7 | +- [Scripts](#scripts) |
| 8 | +- [Project Structure](#project-structure) |
| 9 | +- [Contributing Tests](#contributing-tests) |
| 10 | + |
| 11 | +## Pull Request Guidelines |
| 12 | + |
| 13 | +- The master branch is just a snapshot of the latest stable release. All development should be done in dedicated branches. Do not submit PRs against the master branch. |
| 14 | + |
| 15 | +- Checkout a topic branch from a base branch, e.g. `master`, and merge back against that branch. |
| 16 | + |
| 17 | +- If adding a new feature add accompanying test case. |
| 18 | + |
| 19 | +- It's OK to have multiple small commits as you work on the PR - GitHub can automatically squash them before merging. |
| 20 | + |
| 21 | +- Make sure tests pass! |
| 22 | + |
| 23 | +- Commit messages must follow the [commit message convention](./commit-convention.md). Commit messages are automatically validated before commit (by invoking [Git Hooks](https://git-scm.com/docs/githooks) via [husky](https://github.com/typicode/husky)). |
| 24 | + |
| 25 | +- No need to worry about code style as long as you have installed the dev dependencies - modified files are automatically formatted with Prettier on commit (by invoking [Git Hooks](https://git-scm.com/docs/githooks) via [husky](https://github.com/typicode/husky)). |
| 26 | + |
| 27 | +## Development Setup |
| 28 | + |
| 29 | +You will need [Node.js](https://nodejs.org) **version 16+**. |
| 30 | + |
| 31 | +After cloning the repo, run: |
| 32 | + |
| 33 | +```bash |
| 34 | +$ npm i # install the dependencies of the project |
| 35 | +``` |
| 36 | + |
| 37 | +A high level overview of tools used: |
| 38 | + |
| 39 | +- [Jest](https://jestjs.io/) for unit testing |
| 40 | +- [Prettier](https://prettier.io/) for code formatting |
| 41 | + |
| 42 | +## Scripts |
| 43 | + |
| 44 | +### `npm run lint` |
| 45 | + |
| 46 | +The `lint` script runs linter. |
| 47 | + |
| 48 | +```bash |
| 49 | +# lint files |
| 50 | +$ npm run lint |
| 51 | +# fix linter errors |
| 52 | +$ npm run lint:fix |
| 53 | +``` |
| 54 | + |
| 55 | +### `npm run test` |
| 56 | + |
| 57 | +The `test` script simply calls the `jest` binary, so all [Jest CLI Options](https://jestjs.io/docs/en/cli) can be used. Some examples: |
| 58 | + |
| 59 | +```bash |
| 60 | +# run all tests |
| 61 | +$ npm run test |
| 62 | + |
| 63 | +# run all tests under the runtime-core package |
| 64 | +$ npm run test -- runtime-core |
| 65 | + |
| 66 | +# run tests in a specific file |
| 67 | +$ npm run test -- fileName |
| 68 | + |
| 69 | +# run a specific test in a specific file |
| 70 | +$ npm run test -- fileName -t 'test name' |
| 71 | +``` |
| 72 | + |
| 73 | +## Project Structure |
| 74 | + |
| 75 | +- **`src`**: contains the source code |
| 76 | + |
| 77 | + - **`api`**: contains group of methods and methods for the API. |
| 78 | + |
| 79 | + - **`helpers`**: contains utilities shared across the entire codebase. |
| 80 | + |
| 81 | + - **`tests`**: contains tests for the helpers directory. |
| 82 | + |
| 83 | + - **`tests`**: contains tests for the src directory. |
| 84 | + |
| 85 | +## Contributing Tests |
| 86 | + |
| 87 | +Unit tests are collocated with the code being tested inside directories named `tests`. Consult the [Jest docs](https://jestjs.io/docs/en/using-matchers) and existing test cases for how to write new test specs. Here are some additional guidelines: |
| 88 | + |
| 89 | +- Use the minimal API needed for a test case. For example, if a test can be written without involving the reactivity system or a component, it should be written so. This limits the test's exposure to changes in unrelated parts and makes it more stable. |
| 90 | + |
| 91 | +- Only use platform-specific runtimes if the test is asserting platform-specific behavior. |
0 commit comments