|
| 1 | +# Testing Guidelines |
| 2 | + |
| 3 | +These notes define conventions and coverage expectations for the test suite. |
| 4 | + |
| 5 | +## Framework |
| 6 | + |
| 7 | +- Use Jest (already configured). |
| 8 | +- JavaScript test sources run directly with Jest. |
| 9 | + |
| 10 | +## File / Naming |
| 11 | + |
| 12 | +- Name pattern: `*.test.js`. |
| 13 | +- One logical unit per file (e.g. `polyslice.test.js`). |
| 14 | +- All helpers from the main class share a single consolidated test file (append new helper tests at bottom, do not create a separate file). |
| 15 | + |
| 16 | +## Structure |
| 17 | + |
| 18 | +- Use a small helper factory for repetitive data construction (e.g. `slicer()`). |
| 19 | +- Keep assertion helpers local (no global shared unless reused across 3+ files). |
| 20 | +- Avoid hidden magic numbers; define `EPS`, `TOL`, etc. at top of file. |
| 21 | +- Place any new shared helper functions (e.g. geometry builders, orientation wrappers) near the TOP of the consolidated test file so subsequent describe blocks can reuse them. |
| 22 | +- Formatting / Whitespace: Insert a blank line immediately after each `describe` declaration line and after each `it` line (before the body) to maintain generous vertical whitespace consistent with JavaScript style. |
| 23 | + |
| 24 | +## Assertions |
| 25 | + |
| 26 | +- Prefer strict equality expectations for G-code output validation. |
| 27 | +- When testing floating-point calculations (e.g., fan speeds), use appropriate precision handling. |
| 28 | +- Test both Node.js and browser environments when applicable. |
| 29 | + |
| 30 | +## Coverage Expectations (G-code Generation) |
| 31 | + |
| 32 | +Polyslice tests must include: |
| 33 | + |
| 34 | +1. **Constructor and Options** |
| 35 | + - Default values initialization |
| 36 | + - Custom options handling |
| 37 | + - Invalid parameter rejection |
| 38 | + |
| 39 | +2. **Parameter Setters/Getters** |
| 40 | + - Valid range checking |
| 41 | + - Type validation |
| 42 | + - Chaining behavior |
| 43 | + |
| 44 | +3. **G-code Command Generation** |
| 45 | + - Basic movement commands (G0, G1) |
| 46 | + - Temperature control (M104, M109, M140, M190) |
| 47 | + - Fan control (M106, M107) |
| 48 | + - Home commands (G28) |
| 49 | + - Workspace plane setting (G17, G18, G19) |
| 50 | + - Unit setting (G20, G21) |
| 51 | + - Arc movements (G2, G3) |
| 52 | + - Bézier curves (G5) |
| 53 | + - Special commands (M117, M112, etc.) |
| 54 | + |
| 55 | +4. **Environment Compatibility** |
| 56 | + - Node.js environment tests |
| 57 | + - Browser environment compatibility (when applicable) |
| 58 | + - Three.js integration tests |
| 59 | + |
| 60 | +5. **Edge Cases** |
| 61 | + - Zero values handling |
| 62 | + - Maximum/minimum parameter values |
| 63 | + - Invalid parameter handling |
| 64 | + - Floating-point precision |
| 65 | + |
| 66 | +Future (add later): |
| 67 | + |
| 68 | +- Random fuzz testing for parameter validation |
| 69 | +- Stress test with large coordinate values |
| 70 | +- Performance benchmarks for G-code generation |
| 71 | +- Integration tests with actual three.js meshes |
| 72 | +- Browser environment automated testing |
| 73 | + |
| 74 | +## Floating Point |
| 75 | + |
| 76 | +- Use tolerance constant (default `1e-6`) for floating-point comparisons. |
| 77 | +- Do not equality-compare raw floats except against `0` with documented intent. |
| 78 | +- For fan speed calculations, test the actual rounded output values. |
| 79 | + |
| 80 | +## Environment Testing |
| 81 | + |
| 82 | +- Test CommonJS imports (`require`) |
| 83 | +- Test ES module imports (`import`) when applicable |
| 84 | +- Verify browser global availability |
| 85 | +- Test three.js integration in both environments |
| 86 | + |
| 87 | +## DRY Principles |
| 88 | + |
| 89 | +- Shared helper naming: `slicer()`, `assertGCode()`. |
| 90 | +- Keep helpers minimal; do not abstract prematurely. |
| 91 | +- If helper exceeds ~30 LOC or becomes multi-purpose, split. |
| 92 | + |
| 93 | +## Test Output Clarity |
| 94 | + |
| 95 | +- Include descriptive test names that explain what is being tested. |
| 96 | +- Use meaningful variable names in test setup. |
| 97 | +- Include comments for non-obvious expectations (especially G-code format specifics). |
| 98 | + |
| 99 | +## Adding New G-code Tests |
| 100 | + |
| 101 | +When adding a new G-code command or feature: |
| 102 | + |
| 103 | +1. List expected G-code output format in comment header. |
| 104 | +2. Implement parameter validation tests first. |
| 105 | +3. Write "happy path" test with expected output. |
| 106 | +4. Test edge cases and invalid parameters. |
| 107 | +5. Add regression tests for any bugs fixed. |
| 108 | + |
| 109 | +## Performance / Stability |
| 110 | + |
| 111 | +- Long-running test suites should be opt-in via `process.env.LONG_TESTS`. |
| 112 | +- Default `npm test` must remain fast (< 5s typical). |
| 113 | +- Browser compatibility tests should be separate from core functionality tests. |
| 114 | + |
| 115 | +## Lint / Style |
| 116 | + |
| 117 | +- Follow JavaScript/ESLint formatting guidelines. |
| 118 | +- Keep tests readable over condensed. |
| 119 | +- Use descriptive assertion messages. |
| 120 | + |
| 121 | +## TODO Tags |
| 122 | + |
| 123 | +- Allowed only with issue reference: `# TODO(#123): add browser integration tests`. |
0 commit comments