Skip to content

Add automated tests, CI pipeline, and documentation improvements#30

Open
JaivPatel07 wants to merge 10 commits intoDhanushNehru:mainfrom
JaivPatel07:main
Open

Add automated tests, CI pipeline, and documentation improvements#30
JaivPatel07 wants to merge 10 commits intoDhanushNehru:mainfrom
JaivPatel07:main

Conversation

@JaivPatel07
Copy link
Contributor

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:

  • Health check endpoint
  • File upload (single and batch)
  • File download
  • WebSocket behavior:
    • Connection init
    • Peer join / leave
    • Signaling (offer, answer, candidate)

Also handled async cases and made sure WebSocket connections are cleaned up properly.

CI setup

Added a GitHub Actions workflow that:

  • Runs on push and pull requests
  • Installs dependencies
  • Runs all tests

This helps catch issues early before merging.

README updates

  • Added a "Running tests" section

Notes

  • Tests use port 4000
  • Make sure the port is free when running locally
  • There is a small update in index.js to support testing. The server start is now controlled so it does not run immediately during tests.

@JaivPatel07 JaivPatel07 reopened this Mar 20, 2026
@JaivPatel07 JaivPatel07 reopened this Mar 20, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +59 to +69
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);
};
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +188 to +207
### 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
```
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Comment on lines +134 to +144
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;
});
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
JaivPatel07 and others added 3 commits March 21, 2026 23:15
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>
@JaivPatel07
Copy link
Contributor Author

I have updated all the required changes

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +142 to +159
// 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}`);

Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
JaivPatel07 and others added 3 commits March 22, 2026 08:58
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>
@JaivPatel07
Copy link
Contributor Author

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants