You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
4
4
5
-
## Getting started
5
+
## Table of Contents
6
6
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)
-[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)
9
26
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
11
28
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)
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**
49
86
50
87
```bash
51
88
git fetch upstream
52
89
git merge upstream/main
53
90
```
54
91
55
-
9. Run `node --run format` and `node --run lint` to confirm that linting and formatting are passing.
92
+
4.**Test your changes**
56
93
57
94
```bash
58
-
node --run format
59
-
node --run lint
95
+
node --run test
96
+
node --run test:coverage # To check code coverage
60
97
```
61
98
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**
63
100
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
+
```
70
105
71
-
> [!IMPORTANT]\
72
-
> Before committing and opening a Pull Request, please go first through our [Commit](#commit-guidelines);
106
+
### Submitting Your Changes
73
107
74
-
11. Create a Pull Request.
108
+
1.**Add and commit your changes**
75
109
76
-
## Commit Guidelines
110
+
```bash
111
+
git add .
112
+
git commit -m "describe your changes"
113
+
```
77
114
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
79
138
80
-
### Commit Message Guidelines
139
+
### Test File Organization
81
140
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
+
importassertfrom'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
+
importassertfrom'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
+
constinput='test input';
202
+
constresult=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
+
```
85
247
86
248
### Pre-commit Hooks
87
249
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):
91
253
92
254
```bash
93
255
git commit -m "describe your changes" --no-verify
94
256
```
95
257
258
+
## Commit Guidelines
259
+
260
+
This project follows the [Conventional Commits][] specification.
261
+
96
262
## Developer's Certificate of Origin 1.1
97
263
98
264
```
@@ -114,5 +280,5 @@ By contributing to this project, I certify that:
0 commit comments