Skip to content

Commit 6d86c0c

Browse files
authored
chore(docs): update CONTRIBUTING.md with additional information (#310)
1 parent 276687e commit 6d86c0c

File tree

1 file changed

+203
-37
lines changed

1 file changed

+203
-37
lines changed

CONTRIBUTING.md

Lines changed: 203 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,264 @@
1-
# # Node.js `api-docs-tooling` Contributing Guide
1+
# Node.js `api-docs-tooling` Contributing Guide
22

33
Thank you for your interest in contributing to the Node.js `api-docs-tooling` project! We welcome contributions from everyone, and we appreciate your help in making this project better.
44

5-
## Getting started
5+
## Table of Contents
66

7-
The steps below will give you a general idea of how to prepare your local environment for the Node.js Website and general steps
8-
for getting things done and landing your contribution.
7+
- [Getting Started](#getting-started)
8+
- [Prerequisites](#prerequisites)
9+
- [Setting Up Your Development Environment](#setting-up-your-development-environment)
10+
- [Development Workflow](#development-workflow)
11+
- [Making Changes](#making-changes)
12+
- [Submitting Your Changes](#submitting-your-changes)
13+
- [Writing Tests](#writing-tests)
14+
- [Test File Organization](#test-file-organization)
15+
- [Writing Test Code](#writing-test-code)
16+
- [Use Node.js Built-in Test Runner](#use-nodejs-built-in-test-runner)
17+
- [Test Structure](#test-structure)
18+
- [Best Practices](#best-practices)
19+
- [Example Test File](#example-test-file)
20+
- [Running Tests](#running-tests)
21+
- [Code Quality](#code-quality)
22+
- [Linting and Formatting](#linting-and-formatting)
23+
- [Pre-commit Hooks](#pre-commit-hooks)
24+
- [Commit Guidelines](#commit-guidelines)
25+
- [Developer's Certificate of Origin 1.1](#developers-certificate-of-origin-11)
926

10-
1. Click the fork button in the top right to clone the [Node.js `api-docs-tooling` Repository](https://github.com/nodejs/api-docs-tooling/fork)
27+
## Getting Started
1128

12-
2. Clone your fork using SSH, GitHub CLI, or HTTPS.
29+
The steps below will give you a general idea of how to prepare your local environment for the Node.js `api-docs-tooling` project and general steps for getting things done and landing your contribution.
30+
31+
### Prerequisites
32+
33+
- Node.js (latest LTS version, check the [`.nvmrc` file](/.nvmrc))
34+
- [Git][]
35+
- A GitHub account
36+
37+
### Setting Up Your Development Environment
38+
39+
1. **Fork the repository**
40+
41+
Click the fork button in the top right, or the link in this paragraph, to clone the [Node.js `api-docs-tooling` Repository](https://github.com/nodejs/api-docs-tooling/fork)
42+
43+
2. **Clone your fork**
1344

1445
```bash
1546
git clone [email protected]:<YOUR_GITHUB_USERNAME>/api-docs-tooling.git # SSH
1647
git clone https://github.com/<YOUR_GITHUB_USERNAME>/api-docs-tooling.git # HTTPS
1748
gh repo clone <YOUR_GITHUB_USERNAME>/api-docs-tooling # GitHub CLI
1849
```
1950

20-
3. Change into the `api-docs-tooling` directory.
51+
3. **Navigate to the project directory**
2152

2253
```bash
2354
cd api-docs-tooling
2455
```
2556

26-
4. Create a remote to keep your fork and local clone up-to-date.
57+
4. **Set up upstream remote**
2758

2859
```bash
2960
git remote add upstream [email protected]:nodejs/api-docs-tooling # SSH
3061
git remote add upstream https://github.com/nodejs/api-docs-tooling # HTTPS
3162
gh repo sync nodejs/api-docs-tooling # GitHub CLI
3263
```
3364

34-
5. Create a new branch for your work.
65+
5. **Install dependencies**
3566

3667
```bash
37-
git checkout -b <name-of-your-branch>
68+
npm install
3869
```
3970

40-
6. Run the following to install the dependencies.
71+
## Development Workflow
72+
73+
### Making Changes
74+
75+
1. **Create a new branch for your work**
4176

4277
```bash
43-
npm install
78+
git checkout -b <name-of-your-branch>
4479
```
4580

46-
7. Perform your changes.
81+
2. **Perform your changes**
4782

48-
8. Perform a merge to sync your current branch with the upstream branch.
83+
Make your code changes, add features, fix bugs, or improve documentation.
84+
85+
3. **Keep your branch up-to-date**
4986

5087
```bash
5188
git fetch upstream
5289
git merge upstream/main
5390
```
5491

55-
9. Run `node --run format` and `node --run lint` to confirm that linting and formatting are passing.
92+
4. **Test your changes**
5693

5794
```bash
58-
node --run format
59-
node --run lint
95+
node --run test
96+
node --run test:coverage # To check code coverage
6097
```
6198

62-
10. Once you're happy with your changes, add and commit them to your branch, then push the branch to your fork.
99+
5. **Check code quality**
63100

64-
```bash
65-
cd ~/api-docs-tooling
66-
git add .
67-
git commit -m "describe your changes"
68-
git push -u origin name-of-your-branch
69-
```
101+
```bash
102+
node --run format
103+
node --run lint
104+
```
70105

71-
> [!IMPORTANT]\
72-
> Before committing and opening a Pull Request, please go first through our [Commit](#commit-guidelines);
106+
### Submitting Your Changes
73107

74-
11. Create a Pull Request.
108+
1. **Add and commit your changes**
75109

76-
## Commit Guidelines
110+
```bash
111+
git add .
112+
git commit -m "describe your changes"
113+
```
77114

78-
This project follows the [Conventional Commits][] specification.
115+
2. **Push to your fork**
116+
117+
```bash
118+
git push -u origin <name-of-your-branch>
119+
```
120+
121+
3. **Create a Pull Request**
122+
123+
Go to your fork on GitHub and create a Pull Request to the main repository.
124+
125+
> [!IMPORTANT]
126+
> Before committing and opening a Pull Request, please go through our [Commit Guidelines](#commit-guidelines) and ensure your code passes all tests and quality checks.
127+
128+
## Writing Tests
129+
130+
Testing is a crucial part of maintaining code quality and ensuring reliability. All contributions should include appropriate tests.
131+
132+
### Test Coverage
133+
134+
- **Patches (PRs) are required to maintain 80% coverage minimum**
135+
- **Contributors are encouraged to strive for 95-100% coverage**
136+
- New features and bug fixes should include corresponding tests
137+
- Tests should cover both happy path and edge cases
79138

80-
### Commit Message Guidelines
139+
### Test File Organization
81140

82-
- Commit messages must include a "type" as described on Conventional Commits
83-
- Commit messages **must** start with a capital letter
84-
- Commit messages **must not** end with a period `.`
141+
Tests should be organized to mirror the source code structure:
142+
143+
- For a source file at `/src/index.mjs`, create a test file at `/src/__tests__/index.test.mjs`
144+
- For a source file at `/src/utils/parser.mjs`, create a test file at `/src/utils/__tests__/parser.test.mjs`
145+
- Test files should use the `.test.mjs` extension
146+
147+
- For a fixture used in `/src/__tests__/some.test.mjs`, place the fixture at `/src/__tests__/fixtures/some-fixture.mjs`.
148+
- When fixtures are used in multiple tests, place them in the test directory of the closest shared ancestor. For instance, if a fixture is used by both `/src/__tests__/some.test.mjs`, and `/src/utils/__tests__/parser.test.mjs`, the fixture belongs in `/src/__tests__/fixtures/`.
149+
150+
### Writing Test Code
151+
152+
Tests should follow these guidelines:
153+
154+
#### Use Node.js Built-in Test Runner
155+
156+
```javascript
157+
import assert from 'node:assert/strict';
158+
import { describe, it } from 'node:test';
159+
```
160+
161+
#### Test Structure
162+
163+
Use `describe` and `it` syntax for organizing tests:
164+
165+
```javascript
166+
describe('MyModule', () => {
167+
describe('myFunction', () => {
168+
it('should return expected result for valid input', () => {
169+
// Test implementation
170+
assert.strictEqual(actual, expected);
171+
});
172+
173+
it('should throw error for invalid input', () => {
174+
assert.throws(() => {
175+
// Code that should throw
176+
});
177+
});
178+
});
179+
});
180+
```
181+
182+
#### Best Practices
183+
184+
- **Use strict assertions**: Always use `node:assert/strict` over `node:assert`.
185+
- **Focused testing**: Tests should ideally only test the specific file they are intended for
186+
- **Use mocking**: Mock external dependencies to isolate the code under test
187+
- **Code splitting**: Encourage breaking down complex functionality for easier testing
188+
189+
#### Example Test File
190+
191+
```javascript
192+
// tests/index.test.mjs
193+
import assert from 'node:assert/strict';
194+
import { describe, it } from 'node:test';
195+
196+
import { myFunction } from '../index.mjs';
197+
198+
describe('index.mjs', () => {
199+
describe('myFunction', () => {
200+
it('should process valid input correctly', () => {
201+
const input = 'test input';
202+
const result = myFunction(input);
203+
assert.strictEqual(result, 'expected output');
204+
});
205+
206+
it('should handle edge cases', () => {
207+
assert.strictEqual(myFunction(''), '');
208+
assert.strictEqual(myFunction(null), null);
209+
});
210+
211+
it('should throw for invalid input', () => {
212+
assert.throws(() => myFunction(undefined), {
213+
name: 'TypeError',
214+
message: 'Input cannot be undefined',
215+
});
216+
});
217+
});
218+
});
219+
```
220+
221+
### Running Tests
222+
223+
```bash
224+
# Run all tests
225+
node --run test
226+
227+
# Run tests with coverage
228+
node --run test:coverage
229+
230+
# Run specific test file
231+
node --test src/test/index.test.mjs
232+
```
233+
234+
## Code Quality
235+
236+
### Linting and Formatting
237+
238+
This project uses automated code quality tools:
239+
240+
```bash
241+
# Format code
242+
node --run format # To apply changes, use `format:write`
243+
244+
# Lint code
245+
node --run lint # To apply changes, use `lint:fix`
246+
```
85247

86248
### Pre-commit Hooks
87249

88-
This project uses [Husky][] for Git pre-commit hooks.
89-
It's lint and format stages your code before committing.
90-
You can disable the pre-commit hooks by using the `--no-verify` flag.
250+
This project uses [Husky][] for Git pre-commit hooks that automatically lint and format your code before committing.
251+
252+
You can bypass pre-commit hooks if necessary (not recommended):
91253

92254
```bash
93255
git commit -m "describe your changes" --no-verify
94256
```
95257

258+
## Commit Guidelines
259+
260+
This project follows the [Conventional Commits][] specification.
261+
96262
## Developer's Certificate of Origin 1.1
97263

98264
```
@@ -114,5 +280,5 @@ By contributing to this project, I certify that:
114280
```
115281

116282
[Conventional Commits]: https://www.conventionalcommits.org/
117-
[Commit Signing]: https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits
283+
[Git]: https://git-scm.com/downloads
118284
[Husky]: https://typicode.github.io/husky/

0 commit comments

Comments
 (0)