Skip to content

Commit c339688

Browse files
authored
Add comprehensive test suite and CI integration for v3.4.1 (#146)
## Plan: Add Tests and CI Integration - [x] Explore repository structure and understand the codebase - [x] Verify builds work for both client and server - [x] Add testing framework dependencies for client (Vitest for unit tests) - [x] Add testing framework dependencies for server (Vitest for unit tests) - [x] Write unit tests for server (socket.io signaling logic, generateId function) - [x] Write unit tests for client utilities (FileChunkManager, msgType functions) - [x] Update GitHub Actions workflow to run tests - [x] Update package.json versions to bug fix versions (3.4.0 -> 3.4.1) - [x] Update CHANGELOG.md with new version entry - [x] Run all tests and verify CI integration - [x] Fix build and linting configuration issues - [x] Fix package-lock.json version mismatch - [x] Address code review feedback (remove hardcoded values, improve ID generation) - [x] **Expand test coverage to include more functions** - [x] Add FileProtocol tests (24 tests) - [x] Add RetryManager tests (28 tests) - [x] Add ThemeManager tests (17 tests) - [x] Add WebRTC Connection Workflow tests (27 tests) - [x] Update CHANGELOG with comprehensive test details - [x] **Update all project documentation** - [x] Make CHANGELOG more concise - [x] Add development commands to README - [x] Add semantic commit guidelines to copilot-instructions.md and AGENTS.md - [x] Comprehensively update CONTRIBUTING.md - [x] Enhance SECURITY.md with detailed processes - [x] Fix CI workflow Node.js version to prevent engine warnings ## Summary Successfully expanded test coverage from 74 to **170 tests total** (13 server + 157 client), achieving comprehensive coverage of core utilities, protocol handling, retry mechanisms, UI theming, and WebRTC connection workflows. All documentation updated to reflect testing infrastructure and semantic commit practices. ### Test Coverage Includes: **Server (13 tests)** - ID generation and validation - Character exclusion logic **Client (157 tests)** - FileChunkManager (28 tests): file slicing, chunk management, merging, validation - msgType utilities (33 tests): link detection, file type identification - FileProtocol (24 tests): message parsing, encoding/decoding, round-trip validation - RetryManager (28 tests): timeout handling, retry logic, state management - ThemeManager (17 tests): theme application, color validation, accessibility - WebRTC Connection Workflow (27 tests): connection initialization, offer/answer exchange, ICE candidate handling, data channel management, connection lifecycle All tests passing ✅ Builds successful ✅ Documentation updated ✅ CI workflow optimized ✅ <!-- START COPILOT CODING AGENT SUFFIX --> <details> <summary>Original prompt</summary> > Write tests for the project. > > Then integrate them into GitHub Actions for automated checks. > > Finally, upgrade to a bug fix version. </details> <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/WCY-dt/EasyTransfer/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo.
2 parents ec2b4dc + 48721b9 commit c339688

25 files changed

+5218
-96
lines changed

.github/copilot-instructions.md

Lines changed: 90 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,76 @@ EasyTransfer is a free, anonymous, encrypted, and easy-to-use E2EE file transfer
3838
### Client (in `/client` directory)
3939

4040
```bash
41-
npm run dev # Start development server
42-
npm run build # Build for production
43-
npm run preview # Preview production build
44-
npm run lint # Run ESLint with auto-fix
45-
npm run format # Format code with Prettier
41+
npm run dev # Start development server
42+
npm run build # Build for production
43+
npm run preview # Preview production build
44+
npm run lint # Run ESLint with auto-fix
45+
npm run format # Format code with Prettier
46+
npm test # Run tests
47+
npm run test:watch # Run tests in watch mode
48+
npm run test:ui # Run tests with UI
4649
```
4750

4851
### Server (in `/server` directory)
4952

5053
```bash
51-
npm run dev # Build and start with nodemon
52-
npm run build # Compile TypeScript
53-
npm run start # Start production server
54-
npm run lint # Run ESLint with auto-fix
55-
npm run format # Format code with Prettier
54+
npm run dev # Build and start with nodemon
55+
npm run build # Compile TypeScript
56+
npm run start # Start production server
57+
npm run lint # Run ESLint with auto-fix
58+
npm run format # Format code with Prettier
59+
npm test # Run tests
60+
npm run test:watch # Run tests in watch mode
61+
npm run test:ui # Run tests with UI
5662
```
5763

64+
## Commit Message Guidelines
65+
66+
Follow the [Conventional Commits](https://www.conventionalcommits.org/) specification for semantic commit messages:
67+
68+
### Format
69+
70+
```plaintext
71+
<type>(<scope>): <description>
72+
73+
[optional body]
74+
75+
[optional footer(s)]
76+
```
77+
78+
### Types
79+
80+
- **feat**: A new feature
81+
- **fix**: A bug fix
82+
- **docs**: Documentation only changes
83+
- **style**: Changes that don't affect code meaning (formatting, whitespace)
84+
- **refactor**: Code change that neither fixes a bug nor adds a feature
85+
- **perf**: Performance improvement
86+
- **test**: Adding or updating tests
87+
- **build**: Changes to build system or dependencies
88+
- **ci**: Changes to CI configuration files and scripts
89+
- **chore**: Other changes that don't modify src or test files
90+
91+
### Examples
92+
93+
```
94+
feat(client): add dark mode theme support
95+
fix(server): resolve connection timeout issue
96+
docs(readme): update installation instructions
97+
test(client): add FileChunkManager unit tests
98+
refactor(utils): extract ID generation to utils
99+
ci: add automated testing to GitHub Actions
100+
chore(dependencies): update dependencies to latest versions
101+
```
102+
103+
### Best Practices
104+
105+
- Use present tense (`add` not `added`)
106+
- Use imperative mood (`move` not `moves`)
107+
- Keep first line under 72 characters
108+
- Reference issues/PRs in footer: `Fixes #123`
109+
- Break long descriptions into body paragraphs
110+
58111
## Code Style Guidelines
59112

60113
### General
@@ -123,11 +176,33 @@ npm run format # Format code with Prettier
123176

124177
## Testing Considerations
125178

126-
- Test WebRTC connection establishment
127-
- Verify file transfer integrity
128-
- Test connection across different networks
129-
- Validate encryption implementation
130-
- Test edge cases (large files, network interruptions)
179+
The project uses Vitest for unit testing:
180+
181+
- **Client**: 157 tests covering utilities, protocol handling, retry logic, theming, and WebRTC
182+
- **Server**: 13 tests covering ID generation and validation
183+
184+
### Running Tests
185+
186+
```bash
187+
# Run all tests
188+
npm test
189+
190+
# Run tests in watch mode
191+
npm run test:watch
192+
193+
# Run tests with UI
194+
npm run test:ui
195+
```
196+
197+
### Test Coverage Areas
198+
199+
- WebRTC connection establishment
200+
- File transfer integrity and chunking
201+
- Protocol message encoding/decoding
202+
- Retry mechanisms and timeout handling
203+
- Theme management
204+
- ID generation and validation
205+
- Edge cases (large files, network interruptions)
131206

132207
## Security Considerations
133208

.github/workflows/check.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Check Lint and Format
1+
name: Check Lint, Format, and Tests
22

33
permissions:
44
contents: read
@@ -13,7 +13,7 @@ on:
1313
workflow_dispatch:
1414

1515
jobs:
16-
lint-and-format:
16+
lint-format-and-test:
1717
runs-on: ubuntu-latest
1818

1919
steps:
@@ -25,21 +25,25 @@ jobs:
2525
- name: Set up Node.js
2626
uses: actions/setup-node@v6
2727
with:
28-
node-version: latest
28+
node-version: '22'
2929

3030
- name: Check server
3131
run: |
3232
cd server
3333
npm install
3434
npm run lint
3535
npm run format -- --check
36+
npm run build
37+
npm test
3638
3739
- name: Check client
3840
run: |
3941
cd client
4042
npm install
4143
npm run lint
4244
npm run format -- --check
45+
npm run build
46+
npm test
4347
4448
- name: Check if the code is formatted and linted
4549
run: |

AGENTS.md

Lines changed: 87 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,60 @@ npm run format
7979
# Lint and format server (in /server)
8080
npm run lint
8181
npm run format
82+
83+
# Run tests (in /client or /server)
84+
npm test # Run all tests
85+
npm run test:watch # Run tests in watch mode
86+
npm run test:ui # Run tests with UI
87+
```
88+
89+
## Commit Message Guidelines
90+
91+
Follow the [Conventional Commits](https://www.conventionalcommits.org/) specification for semantic commit messages:
92+
93+
### Format
94+
95+
```plaintext
96+
<type>(<scope>): <description>
97+
98+
[optional body]
99+
100+
[optional footer(s)]
101+
```
102+
103+
### Types
104+
105+
- **feat**: A new feature
106+
- **fix**: A bug fix
107+
- **docs**: Documentation only changes
108+
- **style**: Changes that don't affect code meaning (formatting, whitespace)
109+
- **refactor**: Code change that neither fixes a bug nor adds a feature
110+
- **perf**: Performance improvement
111+
- **test**: Adding or updating tests
112+
- **build**: Changes to build system or dependencies
113+
- **ci**: Changes to CI configuration files and scripts
114+
- **chore**: Other changes that don't modify src or test files
115+
116+
### Examples
117+
118+
```bash
119+
feature(client): add dark mode theme support
120+
fix(server): resolve connection timeout issue
121+
docs(readme): update installation instructions
122+
test(client): add FileChunkManager unit tests
123+
refactor(utils): extract ID generation to utils
124+
ci: add automated testing to GitHub Actions
125+
chore(dependencies): update dependencies to latest versions
82126
```
83127

128+
### Best Practices
129+
130+
- Use present tense (`add` not `added`)
131+
- Use imperative mood (`move` not `moves`)
132+
- Keep first line under 72 characters
133+
- Reference issues/PRs in footer when applicable
134+
- Break long descriptions into body paragraphs
135+
84136
## Key Concepts for AI Agents
85137

86138
### Architecture Understanding
@@ -252,27 +304,45 @@ export const useMyStore = defineStore('myStore', () => {
252304

253305
## Testing Strategy
254306

255-
### What to Test
307+
### Test Infrastructure
256308

257-
1. **WebRTC Connection**: Verify peers can connect
258-
2. **File Transfer**: Test various file sizes and types
259-
3. **Network Conditions**: Test on LAN and WAN
260-
4. **Error Handling**: Test disconnections and failures
261-
5. **UI Responsiveness**: Verify UI updates correctly
309+
The project uses **Vitest** for comprehensive unit testing:
310+
311+
- **Client Tests (157 tests)**:
312+
- FileChunkManager (28 tests): file slicing, chunk management, merging, validation
313+
- msgType utilities (33 tests): link detection, file type identification
314+
- FileProtocol (24 tests): message parsing, encoding/decoding, round-trip validation
315+
- RetryManager (28 tests): timeout handling, retry logic, state management
316+
- ThemeManager (17 tests): theme application, color validation, accessibility
317+
- WebRTC Connection Workflow (27 tests): connection lifecycle, signaling, data channels
318+
319+
- **Server Tests (13 tests)**: ID generation, character validation, collision prevention
262320

263321
### Running Tests
264322

265-
Currently, the project uses:
323+
```bash
324+
# In /client or /server directory
325+
npm test # Run all tests once
326+
npm run test:watch # Run tests in watch mode (auto-rerun on changes)
327+
npm run test:ui # Run tests with interactive UI
328+
```
329+
330+
### What to Test
266331

267-
- ESLint for code quality
268-
- Prettier for formatting
269-
- Manual testing for functionality
332+
1. **WebRTC Connection**: Verify peers can connect through signaling
333+
2. **File Transfer**: Test various file sizes and types
334+
3. **Protocol Handling**: Validate message encoding/decoding
335+
4. **Retry Logic**: Test timeout handling and retry mechanisms
336+
5. **Error Handling**: Test disconnections and failures
337+
6. **UI Components**: Verify theming and state management
270338

271-
**Note**: No automated test suite exists yet. When making changes:
339+
### Testing Best Practices
272340

273-
- Test manually with the running application
274-
- Verify WebRTC connections work
275-
- Test file transfers complete successfully
341+
- Write tests for new utilities and functions
342+
- Mock external dependencies (WebRTC, Socket.io)
343+
- Test edge cases and error conditions
344+
- Keep tests focused and isolated
345+
- Run tests before committing changes
276346

277347
## Common Pitfalls and How to Avoid Them
278348

@@ -340,12 +410,14 @@ Before committing changes:
340410

341411
- [ ] Run `npm run lint` in both client and server
342412
- [ ] Run `npm run format` in both client and server
413+
- [ ] Run `npm test` in both client and server (all tests pass)
343414
- [ ] Build succeeds: `npm run build` in both directories
344-
- [ ] Manual testing completed
415+
- [ ] Manual testing completed (if applicable)
345416
- [ ] No console.log statements left in code
346417
- [ ] TypeScript types are correct
347418
- [ ] No new ESLint warnings
348419
- [ ] Changes follow existing code style
420+
- [ ] Commit message follows semantic commit format
349421

350422
## Dependencies Management
351423

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [3.4.1] - 2025-11-04
6+
7+
### Added
8+
9+
- Comprehensive unit tests
10+
- Automated testing in GitHub Actions CI/CD pipeline
11+
12+
### Changed
13+
14+
- Improved ID generation algorithm for better reliability
15+
- Refactored server code to extract testable utility functions
16+
517
## [3.4.0] - 2025-11-04
618

719
**New Features:** The new version introduces settings for language preference and theme preference.

0 commit comments

Comments
 (0)