Add automated tests, CI pipeline, and documentation improvements#30
Add automated tests, CI pipeline, and documentation improvements#30JaivPatel07 wants to merge 10 commits intoDhanushNehru:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces an automated testing setup for the Node.js signaling server, adds a CI workflow to run those tests on pushes/PRs, and updates documentation with test-running instructions.
Changes:
- Added Vitest + Supertest integration tests covering health, upload/download, and WebSocket signaling flows.
- Added a GitHub Actions workflow to install server deps and run the test suite.
- Updated server startup behavior and README to support/describe running tests.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
server/test/index.test.js |
New integration test suite for HTTP endpoints and WebSocket signaling. |
server/index.js |
Avoids auto-listening in tests and attempts to export app/server for test harness usage. |
server/package.json |
Adds Vitest/Supertest, test script, and switches module type. |
server/package-lock.json |
Locks newly added dev dependencies. |
README.md |
Adds “Running Tests” section and instructions. |
.github/workflows/test.yml |
New CI job to run server tests on push/PR. |
Files not reviewed (1)
- server/package-lock.json: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const timeout = setTimeout(() => { | ||
| client.off('error', onError); | ||
| client.off('message', onMessage); | ||
| reject(new Error('Timed out waiting for init message')); | ||
| }, 3000); | ||
|
|
||
| const onError = (err) => { | ||
| clearTimeout(timeout); | ||
| client.off('message', onMessage); | ||
| reject(err); | ||
| }; |
There was a problem hiding this comment.
On timeout, connectAndInitClient rejects but leaves the WebSocket open (no terminate/close), which can leak sockets and keep the test process alive on failures. Ensure the timeout/error paths terminate the client and remove listeners before rejecting.
| ### Prerequisites | ||
|
|
||
| - Node.js 16+ and npm installed | ||
| - Server dependencies installed in the `server` folder (`npm install`) | ||
|
|
||
| ### Commands | ||
|
|
||
| From the project root: | ||
|
|
||
| ```bash | ||
| cd server | ||
| npx vitest run | ||
| ``` | ||
|
|
||
| Or run the npm test script (watch mode): | ||
|
|
||
| ```bash | ||
| cd server | ||
| npm test | ||
| ``` |
There was a problem hiding this comment.
README says Node.js 16+ and describes npm test as "watch mode", but server/package.json runs vitest run and the added devDependencies (vitest/vite) require a newer Node version. Please update the Node version requirement and adjust the command descriptions to match the actual scripts (or update scripts to match the docs).
| it('should upload file and return file id', async () => { | ||
| const res = await request(baseURL) | ||
| .post('/upload') | ||
| .attach('file', Buffer.from('hello world'), 'test.txt'); | ||
|
|
||
| expect(res.status).toBe(200); | ||
| expect(res.body.id).toBeDefined(); | ||
|
|
||
| // Save this id so the download test can fetch the same file. | ||
| uploadedFileId = res.body.id; | ||
| }); |
There was a problem hiding this comment.
These integration tests upload files to the server’s real uploads/ directory but never clean them up, so repeated local test runs will accumulate artifacts on disk. Consider using a temp uploads directory for NODE_ENV=test and/or deleting uploaded files in afterAll.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
I have updated all the required changes |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 6 changed files in this pull request and generated 4 comments.
Files not reviewed (1)
- server/package-lock.json: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Save this id so the download test can fetch the same file. | ||
| uploadedFileId = res.body.id; | ||
| }); | ||
|
|
||
| // Sending no file should return a validation error. | ||
| it('should fail if no file is sent', async () => { | ||
| const res = await request(baseURL).post('/upload'); | ||
|
|
||
| expect(res.status).toBe(400); | ||
| }); | ||
| }); | ||
|
|
||
| // File download tests | ||
| describe('Download File', () => { | ||
| // Downloads the file uploaded in the previous test block. | ||
| it('should download file using valid id', async () => { | ||
| const res = await request(baseURL).get(`/download/${uploadedFileId}`); | ||
|
|
There was a problem hiding this comment.
uploadedFileId is populated in one test and then consumed by a different describe block. This makes the suite order-dependent and can fail if tests are retried/shuffled or if the upload test fails (download becomes /download/undefined). Prefer creating the upload in a beforeAll within the download suite, or uploading within the download test itself.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
Done |
Add tests, CI workflow, and improve README
What’s included
This PR adds proper test coverage, sets up CI, and improves the project documentation.
Testing
Added tests for the main functionality using Vitest and Supertest.
Covered:
Also handled async cases and made sure WebSocket connections are cleaned up properly.
CI setup
Added a GitHub Actions workflow that:
This helps catch issues early before merging.
README updates
Notes
4000index.jsto support testing. The server start is now controlled so it does not run immediately during tests.