Skip to content

Commit e113bb2

Browse files
authored
Docs/improve contributor onboarding (#4976)
* docs: add pre-push checklist to CONTRIBUTING.md * docs: add CI badge and Developer Quick Start to README * docs: create TESTING.md with block testing guide * chore: add .nvmrc and fix .editorconfig indent * chore: add lint checkbox to PR template and test issue template * docs: address Walter's review feedback - Add checkbox for duplicate PR check in test issue template - Add license header example to TESTING.md template
1 parent b7825f8 commit e113bb2

File tree

8 files changed

+205
-1
lines changed

8 files changed

+205
-1
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ root = true
33
[*]
44
charset = utf-8
55
indent_style = space
6-
indent_size = 2
6+
indent_size = 4
77
end_of_line = lf
88
insert_final_newline = true
99
trim_trailing_whitespace = true
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
name: 🧪 Test Contribution
3+
about: Add or improve unit tests
4+
title: ""
5+
labels: "testing"
6+
assignees: ""
7+
---
8+
9+
### What needs testing
10+
11+
<!-- Which file, block, or feature needs test coverage? -->
12+
13+
### Current coverage
14+
15+
<!-- If known, what's the current test coverage for this area? -->
16+
17+
### Proposed approach
18+
19+
<!-- How would you approach testing this? -->
20+
21+
### Checklist
22+
23+
- [ ] I have read and followed the project's code of conduct.
24+
- [ ] I have checked that no existing tests cover this area.
25+
- [ ] I have checked that there is no open PR for the tests I am submitting.
26+
- [ ] I have reviewed [docs/TESTING.md](docs/TESTING.md) for testing patterns.
27+
28+
---
29+
30+
📚 See [Testing Guide](docs/TESTING.md) for how to write block tests.
31+
32+
🙋🏾🙋🏼 Questions: [Community Matrix Server](https://matrix.to/#/#sugar:matrix.org).

.github/PULL_REQUEST_TEMPLATE/generic.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ This PR fixes #
4343
- [ ] I have added/updated tests that prove the effectiveness of these changes.
4444
- [ ] I have updated the documentation to reflect these changes, if applicable.
4545
- [ ] I have followed the project's coding style guidelines.
46+
- [ ] I have run `npm run lint` and `npx prettier --check .` with no errors.
4647
- [ ] I have addressed the code review feedback from the previous submission, if applicable.
4748

4849
## Additional Notes for Reviewers

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
20

CONTRIBUTING.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,19 @@ following resources:
5353
Programmers, please follow these general [guidelines for
5454
contributions](https://github.com/sugarlabs/sugar-docs/blob/master/src/contributing.md).
5555

56+
57+
### Before You Push
58+
59+
Run these commands locally before submitting a PR:
60+
61+
```bash
62+
npm run lint # ESLint
63+
npx prettier --check . # Formatting
64+
npm test # Jest
65+
```
66+
67+
If formatting fails, run `npx prettier --write .` to fix it.
68+
5669
### License Header
5770

5871
Music Blocks is licensed under the [AGPL](https://www.gnu.org/licenses/agpl-3.0.en.html).

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
<img src="https://img.shields.io/github/license/sugarlabs/musicblocks" />
77
</a>
88

9+
<a href="https://github.com/sugarlabs/musicblocks/actions/workflows/node.js.yml" alt="CI">
10+
<img src="https://github.com/sugarlabs/musicblocks/actions/workflows/node.js.yml/badge.svg" />
11+
</a>
12+
913
# Music Blocks
1014

1115
_All musicians are subconsciously mathematicians._” — Monk
@@ -217,6 +221,14 @@ provides a general overview of Sugar Lab's guidelines. See
217221
[Contributing](#CONTRIBUTING) section for specific details about this
218222
repository.
219223

224+
### Developer Quick Start
225+
226+
1. Clone and install: `git clone https://github.com/sugarlabs/musicblocks.git && npm install`
227+
2. Run locally: `npm run dev`
228+
3. Before pushing: `npm run lint && npx prettier --check . && npm test`
229+
230+
For writing tests, see [docs/TESTING.md](./docs/TESTING.md).
231+
220232
## <a name="REPORTING_BUGS"></a>Reporting Bugs
221233

222234
Bugs can be reported in the [issues

docs/TESTING.md

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# Testing Guide
2+
3+
How to write unit tests for block files.
4+
5+
## Running Tests
6+
7+
```bash
8+
npm test # Run all tests
9+
npm test -- path/to/file.test.js # Run specific test file
10+
npm test -- --coverage # Run with coverage report
11+
```
12+
13+
## Testing Blocks
14+
15+
Block files (in `js/blocks/`) need specific mocks. Copy this template and modify for your block:
16+
17+
### Basic Template
18+
19+
Add a license header at the top of your test file:
20+
21+
```javascript
22+
/**
23+
* MusicBlocks v3.6.2
24+
*
25+
* @author Your Name
26+
*
27+
* @copyright 2026 Your Name
28+
*
29+
* @license
30+
* This program is free software: you can redistribute it and/or modify
31+
* it under the terms of the GNU Affero General Public License as published by
32+
* the Free Software Foundation, either version 3 of the License, or
33+
* (at your option) any later version.
34+
*/
35+
```
36+
37+
Then add the test code:
38+
39+
```javascript
40+
const { setupYourBlocks } = jest.requireActual("../YourBlocks");
41+
42+
global._ = s => s;
43+
global.NOINPUTERRORMSG = "NO_INPUT";
44+
45+
class BaseBlock {
46+
constructor(name) {
47+
this.name = name;
48+
}
49+
setPalette(palette) {
50+
this.palette = palette;
51+
}
52+
setHelpString(help) {
53+
this.help = help;
54+
}
55+
formBlock(defn) {
56+
this.formDefn = defn;
57+
}
58+
setup(activity) {
59+
activity.registeredBlocks = activity.registeredBlocks || {};
60+
activity.registeredBlocks[this.name] = this;
61+
return this;
62+
}
63+
}
64+
65+
class FlowBlock extends BaseBlock {
66+
constructor(name) {
67+
super(name);
68+
}
69+
flow() {}
70+
}
71+
72+
class ValueBlock extends BaseBlock {
73+
constructor(name) {
74+
super(name);
75+
}
76+
arg() {}
77+
}
78+
79+
global.BaseBlock = BaseBlock;
80+
global.FlowBlock = FlowBlock;
81+
global.ValueBlock = ValueBlock;
82+
83+
describe("YourBlocks", () => {
84+
let activity;
85+
let logo;
86+
87+
beforeEach(() => {
88+
jest.clearAllMocks();
89+
90+
activity = {
91+
registeredBlocks: {},
92+
blocks: {
93+
blockList: [],
94+
palettes: { dict: {} }
95+
},
96+
turtles: {
97+
ithTurtle: jest.fn(() => ({
98+
singer: { justCounting: [] }
99+
}))
100+
},
101+
errorMsg: jest.fn()
102+
};
103+
104+
logo = {
105+
parseArg: jest.fn(),
106+
runFromBlock: jest.fn()
107+
};
108+
109+
setupYourBlocks(activity);
110+
});
111+
112+
const getBlock = name => activity.registeredBlocks[name];
113+
114+
test("registers blocks", () => {
115+
expect(activity.registeredBlocks).toHaveProperty("yourblock");
116+
});
117+
118+
test("block flow works", () => {
119+
const block = getBlock("yourblock");
120+
// Replace with actual args for your block
121+
const result = block.flow([1 / 4, "sol"], logo, 0, 5);
122+
expect(result).toEqual(["sol", 1]);
123+
});
124+
});
125+
```
126+
127+
### Common Mocks
128+
129+
| Global | Purpose |
130+
| ------------------------------ | ---------------------------------- |
131+
| `activity.errorMsg` | Captures error messages |
132+
| `activity.blocks.blockList` | Simulates block connections |
133+
| `logo.parseArg` | Returns values for block arguments |
134+
| `activity.turtles.ithTurtle()` | Returns turtle state |
135+
136+
### Tips
137+
138+
1. Check the source file's `flow()` or `arg()` method to understand what it expects
139+
2. Mock only what's needed for the specific test
140+
3. Use `jest.fn()` for methods you want to verify were called
141+
4. Run `npx prettier --write` on your test file before committing

js/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ MusicBlocks/js
44
The core code for Music Blocks resides in this directory, the blocks and the turtleactions
55
subdirectory.
66

7+
## Testing
8+
9+
For writing unit tests for block files, see [docs/TESTING.md](../docs/TESTING.md).
10+
711
* `activity.js` -- where the menus are defined
812

913
Logo code

0 commit comments

Comments
 (0)