Skip to content

Commit b151a42

Browse files
committed
Add test instructions to README, implement test scripts, and create test suite
1 parent 48a80b3 commit b151a42

5 files changed

Lines changed: 397 additions & 4 deletions

File tree

.github/workflows/test.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Run Tests
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
push:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout Code
15+
uses: actions/checkout@v3
16+
17+
- name: Setup Node.js
18+
uses: actions/setup-node@v4
19+
with:
20+
node-version: 18
21+
22+
- name: Install Dependencies
23+
run: npm install
24+
25+
- name: Run Tests
26+
run: npm test

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Transfer files across your local network directly from device to device using We
2727
- [2. Install Dependencies](#2-install-dependencies)
2828
- [3. Run the Signaling Server](#3-run-the-signaling-server)
2929
- [4. Serve the Frontend](#4-serve-the-frontend)
30+
- [Running Tests](#running-tests)
3031
- [Self-Hosting](#self-hosting)
3132
- [Frontend — GitHub Pages](#frontend--github-pages)
3233
- [Backend — Signaling Server](#backend--signaling-server)
@@ -182,6 +183,31 @@ Then open `http://localhost:8080` in your browser.
182183

183184
---
184185

186+
## Running Tests
187+
188+
### Prerequisites
189+
190+
- Node.js 16+ and npm installed
191+
- Server dependencies installed in the `server` folder (`npm install`)
192+
193+
### Commands
194+
195+
From the project root:
196+
197+
```bash
198+
cd server
199+
npx vitest run
200+
```
201+
202+
Or run the npm test script (watch mode):
203+
204+
```bash
205+
cd server
206+
npm test
207+
```
208+
209+
---
210+
185211
## Self-Hosting
186212

187213
### Frontend — GitHub Pages

server/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,10 @@ wss.on('connection', (ws, req) => {
366366
});
367367

368368
const PORT = process.env.PORT || 3000;
369-
server.listen(PORT, () => {
370-
console.log(`Signaling server running on port ${PORT}`);
371-
});
369+
370+
if (process.env.NODE_ENV !== 'test') {
371+
server.listen(PORT, () => {
372+
console.log(`Signaling server running on port ${PORT}`);
373+
});
374+
}
375+
export { app, server };

server/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
"version": "1.0.0",
44
"main": "index.js",
55
"scripts": {
6-
"test": "echo \"Error: no test specified\" && exit 1"
6+
"test": "vitest run"
77
},
8+
"type": "module",
89
"keywords": [],
910
"author": "",
1011
"license": "ISC",

0 commit comments

Comments
 (0)