peerpigeon 0.0.5 โ†’ 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,6 +4,8 @@
4
4
 
5
5
  [![npm version](https://badge.fury.io/js/peerpigeon.svg)](https://badge.fury.io/js/peerpigeon)
6
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+ [![Tests](https://img.shields.io/badge/Tests-23%2F23%20passing-brightgreen.svg)](https://github.com/draeder/peerpigeon)
8
+ [![ESLint](https://img.shields.io/badge/ESLint-0%20errors-brightgreen.svg)](https://github.com/draeder/peerpigeon)
7
9
 
8
10
  > **๐Ÿ“Š Viewing Diagrams**: This README contains Mermaid diagrams. For proper visualization in VS Code, install the [Markdown Preview Mermaid Support](https://marketplace.visualstudio.com/items?itemName=bierner.markdown-mermaid) extension.
9
11
 
@@ -1093,11 +1095,136 @@ mesh.addEventListener('messageReceived', (event) => {
1093
1095
  });
1094
1096
  ```
1095
1097
 
1096
- ### Testing Scenarios
1098
+ ## ๐Ÿงช Testing & Development
1099
+
1100
+ PeerPigeon includes a comprehensive testing framework with unit tests, integration tests, performance benchmarks, and automated CI/CD pipeline.
1101
+
1102
+ ### Quick Start
1103
+
1104
+ ```bash
1105
+ # Install dependencies
1106
+ npm install
1107
+
1108
+ # Run all tests
1109
+ npm test
1110
+
1111
+ # Run specific test suites
1112
+ npm run test:unit # Unit tests only
1113
+ npm run test:integration # Integration tests only
1114
+ npm run test:custom # Custom test runners
1115
+
1116
+ # Run with coverage
1117
+ npm run test:coverage
1118
+
1119
+ # Performance benchmarks
1120
+ npm run benchmark
1121
+
1122
+ # Linting
1123
+ npm run lint
1124
+ npm run lint:fix # Auto-fix issues
1125
+
1126
+ # Full CI pipeline
1127
+ npm run ci
1128
+ ```
1129
+
1130
+ ### Test Structure
1131
+
1132
+ ```
1133
+ test/
1134
+ โ”œโ”€โ”€ unit/ # Unit tests (16 tests)
1135
+ โ”‚ โ”œโ”€โ”€ crypto.test.js # CryptoManager tests (7 tests)
1136
+ โ”‚ โ””โ”€โ”€ mesh.test.js # PeerPigeonMesh tests (9 tests)
1137
+ โ”œโ”€โ”€ integration/ # Integration tests (7 tests)
1138
+ โ”‚ โ”œโ”€โ”€ simple.test.js # Integration scenarios
1139
+ โ”‚ โ””โ”€โ”€ integration-runner.js # Custom test runner
1140
+ โ”œโ”€โ”€ setup.js # Jest configuration
1141
+ โ”œโ”€โ”€ runner.js # Comprehensive test runner
1142
+ โ””โ”€โ”€ benchmark.js # Performance benchmarks
1143
+ ```
1144
+
1145
+ ### Testing Framework Features
1146
+
1147
+ - **๐Ÿ”ง Custom Test Runners**: Built-in Node.js test runners for comprehensive testing
1148
+ - **๐Ÿƒ Jest Integration**: Modern testing framework with ES modules support and coverage reporting
1149
+ - **๐Ÿ“Š Coverage Reports**: Detailed HTML and LCOV coverage reports
1150
+ - **โšก Performance Benchmarks**: Crypto operations, mesh performance, and memory usage
1151
+ - **๐Ÿ” Linting**: ESLint with standard configuration (0 errors, 0 warnings)
1152
+ - **๐Ÿค– CI/CD Pipeline**: Automated testing with proper resource cleanup
1153
+ - **๐Ÿ› ๏ธ Clean Test Termination**: All tests complete without hanging processes
1154
+ - **โšก Fast Execution**: Unit tests ~0.26s, full suite ~1.2s
1155
+
1156
+ ### Available Commands
1157
+
1158
+ ```bash
1159
+ # Using npm scripts
1160
+ npm test # Jest tests (23/23 passing)
1161
+ npm run test:unit # Unit tests (16/16 passing)
1162
+ npm run test:integration # Integration tests (7/7 passing)
1163
+ npm run test:custom # Custom test runners
1164
+ npm run test:all # Comprehensive test suite
1165
+ npm run test:coverage # Coverage analysis
1166
+ npm run test:watch # Watch mode
1167
+ npm run lint # ESLint (0 errors, 0 warnings)
1168
+ npm run lint:fix # Auto-fix linting issues
1169
+ npm run benchmark # Performance benchmarks
1170
+ npm run ci # Full CI pipeline
1171
+
1172
+ # Using Makefile (shorter commands)
1173
+ make test # Run tests
1174
+ make lint # Run linting
1175
+ make benchmark # Run benchmarks
1176
+ make coverage # Generate coverage
1177
+ make ci # Full CI check
1178
+ make help # Show all commands
1179
+ ```
1180
+
1181
+ ### Test Categories
1182
+
1183
+ #### Unit Tests (16 tests passing)
1184
+ - **CryptoManager (7 tests)**: Encryption, decryption, key generation, signing
1185
+ - **PeerPigeonMesh (9 tests)**: Core mesh functionality, message routing
1186
+ - **Resource Management**: Timer cleanup, proper disconnection
1187
+ - **Memory Safety**: No memory leaks or hanging processes
1188
+
1189
+ #### Integration Tests (7 tests passing)
1190
+ - **Peer Discovery**: Network join/leave scenarios
1191
+ - **Message Propagation**: End-to-end gossip protocol testing
1192
+ - **Network Resilience**: Connection management and cleanup
1193
+ - **Multi-Peer Scenarios**: Real-world mesh networking tests
1194
+
1195
+ #### Performance Benchmarks
1196
+ - **Crypto Performance**: Key generation, encryption/decryption speed
1197
+ - **Mesh Operations**: Peer connection, message routing efficiency
1198
+ - **Memory Usage**: Memory leak detection, resource management
1199
+ - **Network Performance**: Message throughput, latency analysis
1200
+
1201
+ ### Coverage Reports
1202
+
1203
+ After running `npm run test:coverage`, open `coverage/index.html` to view detailed coverage reports including:
1204
+
1205
+ - Line coverage
1206
+ - Function coverage
1207
+ - Branch coverage
1208
+ - Statement coverage
1209
+
1210
+ ### Continuous Integration
1211
+
1212
+ The project includes GitHub Actions workflows for:
1213
+
1214
+ - **Multiple Node.js versions** (18.x, 20.x, 22.x)
1215
+ - **Automated testing** on push/PR
1216
+ - **Security audits**
1217
+ - **Performance benchmarking**
1218
+ - **Coverage reporting**
1219
+
1220
+ ### Browser Testing Scenarios
1097
1221
 
1098
1222
  #### Multi-Tab Testing
1099
1223
  ```bash
1100
- # Open 3-5 browser tabs
1224
+ # Open multiple browser tabs for mesh testing
1225
+ npm run dev
1226
+
1227
+ # In separate terminal, open tabs
1101
1228
  for i in {1..5}; do
1102
1229
  open "http://localhost:8080/examples/browser/?debug=true&tab=$i"
1103
1230
  done
@@ -1105,10 +1232,23 @@ done
1105
1232
 
1106
1233
  #### Network Partition Testing
1107
1234
  ```javascript
1108
- // Simulate network partition
1235
+ // Simulate network partition in browser console
1109
1236
  mesh.disconnectPeer(specificPeerId, 'testing partition');
1110
1237
 
1111
- // Wait and observe reconnection behavior
1238
+ // Monitor reconnection behavior
1239
+ mesh.on('peerReconnected', (peerId) => {
1240
+ console.log('Peer reconnected after partition:', peerId);
1241
+ });
1242
+ ```
1243
+
1244
+ #### Encryption Testing
1245
+ ```javascript
1246
+ // Test encryption in browser
1247
+ await mesh.crypto.generateKeyPair();
1248
+ const encrypted = await mesh.encryptMessage('test message', targetPeerId);
1249
+ const decrypted = await mesh.decryptMessage(encrypted, senderPeerId);
1250
+ console.log('Encryption test:', decrypted === 'test message');
1251
+ ```
1112
1252
  setTimeout(() => {
1113
1253
  console.log('Network recovered, connections:', mesh.getConnectedPeerCount());
1114
1254
  }, 10000);
@@ -2,51 +2,51 @@ import { PeerPigeonMesh } from '../../src/PeerPigeonMesh.js';
2
2
  import { PeerPigeonUI } from './ui.js';
3
3
 
4
4
  class PeerPigeonApp {
5
- constructor() {
6
- // Initialize mesh with default options (WebDHT enabled)
7
- this.mesh = new PeerPigeonMesh();
8
-
9
- // To disable WebDHT, use:
10
- // this.mesh = new PeerPigeonMesh({ enableWebDHT: false });
11
-
12
- this.ui = new PeerPigeonUI(this.mesh);
13
- this.init();
14
- }
5
+ constructor() {
6
+ // Initialize mesh with crypto and WebDHT enabled
7
+ this.mesh = new PeerPigeonMesh({
8
+ enableWebDHT: true,
9
+ enableCrypto: true
10
+ });
11
+
12
+ this.ui = new PeerPigeonUI(this.mesh);
13
+ this.init();
14
+ }
15
15
 
16
- async init() {
17
- try {
18
- await this.mesh.init();
19
- this.ui.updateUI();
20
- this.setupUnloadHandler();
21
- } catch (error) {
22
- console.error('Failed to initialize app:', error);
23
- }
16
+ async init() {
17
+ try {
18
+ await this.mesh.init();
19
+ this.ui.updateUI();
20
+ this.setupUnloadHandler();
21
+ } catch (error) {
22
+ console.error('Failed to initialize app:', error);
24
23
  }
24
+ }
25
25
 
26
- setupUnloadHandler() {
27
- const handleUnload = () => {
28
- if (this.mesh.connected) {
29
- this.mesh.sendGoodbyeMessage();
30
- }
31
- };
26
+ setupUnloadHandler() {
27
+ const handleUnload = () => {
28
+ if (this.mesh.connected) {
29
+ this.mesh.sendGoodbyeMessage();
30
+ }
31
+ };
32
32
 
33
- window.addEventListener('beforeunload', handleUnload);
34
- window.addEventListener('unload', handleUnload);
35
- }
33
+ window.addEventListener('beforeunload', handleUnload);
34
+ window.addEventListener('unload', handleUnload);
35
+ }
36
36
  }
37
37
 
38
38
  // Initialize the application
39
39
  document.addEventListener('DOMContentLoaded', () => {
40
- const peerPigeonApp = new PeerPigeonApp();
41
-
42
- // Expose for debugging and global access
43
- window.peerPigeonApp = peerPigeonApp;
44
- window.peerPigeonMesh = peerPigeonApp.mesh;
45
- window.peerPigeonUI = peerPigeonApp.ui;
46
- window.ui = peerPigeonApp.ui; // Also expose as 'ui' for compatibility with discovered peers buttons
47
- window.peerPigeonSignaling = peerPigeonApp.mesh.signalingClient;
48
- window.getPeerPigeonState = () => peerPigeonApp.mesh.getStatus();
49
-
50
- // Expose PeerPigeonMesh class for static validation in UI
51
- window.PeerPigeonMesh = PeerPigeonMesh;
52
- });
40
+ const peerPigeonApp = new PeerPigeonApp();
41
+
42
+ // Expose for debugging and global access
43
+ window.peerPigeonApp = peerPigeonApp;
44
+ window.peerPigeonMesh = peerPigeonApp.mesh;
45
+ window.peerPigeonUI = peerPigeonApp.ui;
46
+ window.ui = peerPigeonApp.ui; // Also expose as 'ui' for compatibility with discovered peers buttons
47
+ window.peerPigeonSignaling = peerPigeonApp.mesh.signalingClient;
48
+ window.getPeerPigeonState = () => peerPigeonApp.mesh.getStatus();
49
+
50
+ // Expose PeerPigeonMesh class for static validation in UI
51
+ window.PeerPigeonMesh = PeerPigeonMesh;
52
+ });