|
| 1 | +# Testing Guide |
| 2 | + |
| 3 | +## PlutoManager Tests |
| 4 | + |
| 5 | +The PlutoManager tests use **comprehensive integration testing** with a real Pluto server. |
| 6 | + |
| 7 | +### Test Approach |
| 8 | + |
| 9 | +**Single Workflow Test** - One comprehensive test that: |
| 10 | + |
| 11 | +- Opens a notebook |
| 12 | +- Performs all operations sequentially |
| 13 | +- Verifies each step works correctly |
| 14 | +- Tests the complete lifecycle end-to-end |
| 15 | + |
| 16 | +This approach provides: |
| 17 | + |
| 18 | +- ✅ Realistic usage patterns |
| 19 | +- ✅ Fast execution (no repeated setup/teardown) |
| 20 | +- ✅ Clear verification of functionality |
| 21 | +- ✅ Easy to understand workflow |
| 22 | +- ✅ Real Pluto server interaction |
| 23 | + |
| 24 | +### Test Setup |
| 25 | + |
| 26 | +- **beforeAll**: |
| 27 | + - Starts Julia Pluto server on port 1234 |
| 28 | + - Creates test notebook file |
| 29 | + - Creates PlutoManager instance |
| 30 | + |
| 31 | +- **afterAll**: |
| 32 | + - Disposes PlutoManager |
| 33 | + - Cleans up test files |
| 34 | + - Kills Pluto server |
| 35 | + |
| 36 | +### Test Coverage |
| 37 | + |
| 38 | +**One comprehensive integration test** that verifies all functionality: |
| 39 | + |
| 40 | +1. **Initial State** (Steps 1) |
| 41 | + - Manager not connected |
| 42 | + - No open notebooks |
| 43 | + - Server URL correct |
| 44 | + |
| 45 | +2. **Connection** (Steps 2-3) |
| 46 | + - Connect to server |
| 47 | + - Verify duplicate connection handling |
| 48 | + |
| 49 | +3. **Event System Setup** (Step 4) |
| 50 | + - Register event listeners |
| 51 | + - Prepare to track events |
| 52 | + |
| 53 | +4. **Open Notebook** (Steps 5-7) |
| 54 | + - Get worker for notebook |
| 55 | + - Verify worker caching |
| 56 | + - Check open notebooks list |
| 57 | + - Verify notebookOpened event |
| 58 | + |
| 59 | +5. **Cell Operations** (Steps 8-12) |
| 60 | + - Execute existing cell |
| 61 | + - Add new cell |
| 62 | + - Execute new cell |
| 63 | + - Delete cell |
| 64 | + - Execute ephemeral code |
| 65 | + |
| 66 | +6. **Event Testing** (Step 13) |
| 67 | + - Emit cellUpdated event |
| 68 | + - Verify event received |
| 69 | + |
| 70 | +7. **Multiple Notebooks** (Step 14) |
| 71 | + - Open second notebook with custom content |
| 72 | + - Verify different worker |
| 73 | + - Close second notebook |
| 74 | + - Verify notebookClosed event |
| 75 | + |
| 76 | +8. **Event Listener Removal** (Step 15) |
| 77 | + - Add and remove listener |
| 78 | + - Verify listener not called |
| 79 | + |
| 80 | +9. **Close Operations** (Steps 16-18) |
| 81 | + - Close main notebook |
| 82 | + - Verify removed from list |
| 83 | + - Test graceful error handling |
| 84 | + |
| 85 | +10. **Error Handling** (Step 19) |
| 86 | + - Test missing file error |
| 87 | + |
| 88 | +11. **Final State** (Step 20) |
| 89 | + - Verify still connected |
| 90 | + - No notebooks open |
| 91 | + |
| 92 | +**Plus 2 constructor tests**: |
| 93 | + |
| 94 | +- Default port initialization |
| 95 | +- Custom server URL |
| 96 | + |
| 97 | +### Running Tests |
| 98 | + |
| 99 | +```bash |
| 100 | +# Run all tests (in parallel by default) |
| 101 | +npm test |
| 102 | + |
| 103 | +# Run only PlutoManager tests |
| 104 | +npm run test:unit -- plutoManager.test.ts |
| 105 | + |
| 106 | +# Run with coverage |
| 107 | +npm run test:coverage |
| 108 | + |
| 109 | +# Run serially (for debugging) |
| 110 | +npm run test:unit -- --runInBand plutoManager.test.ts |
| 111 | +``` |
| 112 | + |
| 113 | +### Test Timeouts |
| 114 | + |
| 115 | +- Main integration test: **2 minutes** (complete workflow) |
| 116 | +- `beforeAll`: **2 minutes** (for Pluto server startup) |
| 117 | +- `afterAll`: **30 seconds** (for cleanup) |
| 118 | +- Constructor tests: **5 seconds** (default) |
| 119 | + |
| 120 | +### Mocking Strategy |
| 121 | + |
| 122 | +**What we mock:** |
| 123 | + |
| 124 | +- `vscode` module - Only what's needed by PlutoServerTaskManager: |
| 125 | + - `workspace.getConfiguration` (for Julia settings) |
| 126 | + - Task-related types (TaskExecution, ShellExecution, etc.) |
| 127 | + - Notebook types (for serializer tests) |
| 128 | + |
| 129 | +**What we DON'T mock:** |
| 130 | + |
| 131 | +- ❌ Pluto server - use real Julia Pluto server |
| 132 | +- ❌ File system - use real file operations |
| 133 | +- ❌ @plutojl/rainbow - use real library |
| 134 | +- ❌ PlutoServerTaskManager - use real implementation |
| 135 | + |
| 136 | +This integration testing approach provides: |
| 137 | + |
| 138 | +- ✅ More realistic test scenarios |
| 139 | +- ✅ Better confidence in functionality |
| 140 | +- ✅ Easier test maintenance |
| 141 | +- ✅ Real interaction testing with Pluto |
| 142 | +- ✅ Parallel test execution |
| 143 | + |
| 144 | +### Prerequisites |
| 145 | + |
| 146 | +**Local Development:** |
| 147 | + |
| 148 | +- Julia 1.11+ must be installed and available in PATH |
| 149 | +- Pluto.jl package must be installed: `julia -e 'using Pkg; Pkg.add("Pluto")'` |
| 150 | + |
| 151 | +**CI/CD:** |
| 152 | + |
| 153 | +- GitHub Actions CI automatically installs Julia 1.11 and Pluto.jl |
| 154 | +- The test job uses `julia-actions/setup-julia@v2` to set up Julia |
| 155 | +- Pluto.jl is installed before running tests |
| 156 | + |
| 157 | +### Test Structure |
| 158 | + |
| 159 | +**Sequential Workflow Test**: |
| 160 | + |
| 161 | +```typescript |
| 162 | +it("should perform complete notebook lifecycle workflow", async () => { |
| 163 | + // Step 1: Test initial state |
| 164 | + expect(manager.isConnected()).toBe(false); |
| 165 | + |
| 166 | + // Step 2: Connect to server |
| 167 | + await manager.connect(); |
| 168 | + expect(manager.isConnected()).toBe(true); |
| 169 | + |
| 170 | + // Step 3-20: Sequential operations |
| 171 | + // - Open notebook |
| 172 | + // - Execute cells |
| 173 | + // - Add/delete cells |
| 174 | + // - Test events |
| 175 | + // - Close notebook |
| 176 | + // - Verify cleanup |
| 177 | +}, 120000); |
| 178 | +``` |
| 179 | + |
| 180 | +**Benefits of Sequential Testing**: |
| 181 | + |
| 182 | +- ✅ Tests realistic usage patterns |
| 183 | +- ✅ Verifies operations work together |
| 184 | +- ✅ Faster than isolated tests (no repeated setup) |
| 185 | +- ✅ Easy to follow workflow |
| 186 | +- ✅ Clear failure points (which step failed) |
0 commit comments