-
Notifications
You must be signed in to change notification settings - Fork 0
Unit Tests for Server App #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d149399
acf90e1
95e67fd
be4ab3e
d2afcd8
bff9fd1
3068b24
c417a8e
8f4c0c6
650aca3
922d707
2f2157d
4e89be1
c675d34
8243e82
ccd16be
135c3ca
ddb7d50
463cbec
9c8d5b6
9c30be7
4258006
135d928
0f683c3
adf5889
23f27d0
c91be35
86956f0
ba6ebe1
67a9e99
592d753
036d533
6632ec3
183fc71
c328824
d594ee2
ee3914e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,7 +1,9 @@ | ||||||||||
| name: Build and push images to GHCR | ||||||||||
|
|
||||||||||
| on: | ||||||||||
| workflow_dispatch: | ||||||||||
| push: | ||||||||||
| branches: | ||||||||||
| - main | ||||||||||
|
|
||||||||||
|
Comment on lines
+4
to
7
|
||||||||||
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: |
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,66 @@ | ||||||
| name: Unit Tests for Server | ||||||
|
|
||||||
| on: | ||||||
| pull_request: | ||||||
| branches: | ||||||
| - staging | ||||||
| paths: | ||||||
| - 'server/**' | ||||||
| push: | ||||||
| branches: | ||||||
| - staging | ||||||
|
|
||||||
| jobs: | ||||||
| test: | ||||||
| runs-on: ubuntu-latest | ||||||
|
|
||||||
| steps: | ||||||
| - name: Checkout code | ||||||
| uses: actions/checkout@v4 | ||||||
|
|
||||||
| - name: Setup Node.js | ||||||
| uses: actions/setup-node@v4 | ||||||
| with: | ||||||
| node-version: '20' | ||||||
| cache: 'npm' | ||||||
|
|
||||||
| - name: Install server dependencies | ||||||
| run: npm install --ignore-scripts | ||||||
| working-directory: server | ||||||
|
|
||||||
| - name: Run Unit Tests & Generate Coverage | ||||||
| run: npm run test:unit -- --coverage | ||||||
| working-directory: server | ||||||
| env: | ||||||
| NODE_ENV: test | ||||||
| REDIS_PWD: ${{ secrets.REDIS_PWD }} | ||||||
| REDIS_HOST: ${{ secrets.REDIS_HOST }} | ||||||
| REDIS_PORT: ${{ secrets.REDIS_PORT }} | ||||||
| SUPABASE_DB_URL: ${{ secrets.SUPABASE_DB_URL }} | ||||||
|
|
||||||
| - name: Upload coverage reports | ||||||
| uses: codecov/codecov-action@ab904c41d6ece82784817410c45d8b8c02684457 | ||||||
|
||||||
| uses: codecov/codecov-action@ab904c41d6ece82784817410c45d8b8c02684457 | |
| uses: codecov/codecov-action@ab904c41d6ece82784817410c45d8b8c02684457 # codecov-action v4.4.1 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| name: SonarQube Scan | ||
|
|
||
| on: | ||
| workflow_run: | ||
| workflows: ["Unit Tests for Server"] | ||
| types: | ||
| - completed | ||
|
|
||
| jobs: | ||
| scan: | ||
| runs-on: ubuntu-latest | ||
| environment: analysis | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v3 | ||
|
|
||
| - name: Install Node.js | ||
| uses: actions/setup-node@v3 | ||
| with: | ||
| node-version: 18 | ||
|
|
||
| - name: Install dependencies | ||
| run: npm install --ignore-scripts | ||
|
|
||
| # Optional: run tests to generate coverage file | ||
| #- name: Run tests | ||
| # run: npm test -- --coverage | ||
|
|
||
| - name: SonarQube Scan | ||
| uses: sonarsource/sonarqube-scan-action@v2 | ||
| with: | ||
| projectBaseDir: server | ||
| args: > | ||
| -Dsonar.organization=${{ secrets.SONAR_ORGANIZATION }} | ||
| -Dsonar.projectKey=${{ secrets.SONAR_PROJECT_KEY }} | ||
| -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info | ||
| env: | ||
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | ||
| SONAR_HOST_URL: https://sonarcloud.io |
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,58 @@ | ||
| # prototype-rtc-js | ||
| Real -time scalable group chat app with uWebSockets, Redis, and Postgres | ||
|
|
||
| ### How to run (Local) >> | ||
|
|
||
| Using code? | ||
| ```bash | ||
| node server.js | ||
|
|
||
| node consumer.js | ||
| ``` | ||
| Also run local redis instance. | ||
| ```bash | ||
| docker start redis-local | ||
| ``` | ||
| Also run local Postgres instance. | ||
| ```bash | ||
| docker start local-pg | ||
| ``` | ||
| Don't forget to change env variables to local redis and pg | ||
| ```bash | ||
| SUPABASE_DB_URL=postgres://postgres:postgres@localhost:5432/messages | ||
| ``` | ||
|
|
||
| Using containers to run server? | ||
| ```bash | ||
| docker build -t server-local -f Dockerfile.server . | ||
|
|
||
| docker run --env-file .env-local -p 9001:9001 server-local | ||
| ``` | ||
| Run local redis instance too. | ||
|
|
||
| ### How to run (PM2 Multiple Instances) >> | ||
|
|
||
| ```bash | ||
| pm2 start server.js -i <instance-num> | ||
| ``` | ||
|
|
||
| Also run local redis instance. | ||
| Change local vars to local redis host and port. | ||
|
|
||
| Check logs | ||
| ```bash | ||
| pm2 logs | ||
| ``` | ||
|
|
||
| Stop all instances | ||
| ```bash | ||
| pm2 stop all | ||
| ``` | ||
|
|
||
| ### Testing >> | ||
|
|
||
| Server Unit Tests | ||
| ```bash | ||
| cd server | ||
| npm run test:unit | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,3 +2,8 @@ SUPABASE_DB_URL= | |
| REDIS_PWD= | ||
| REDIS_HOST= | ||
| REDIS_PORT= | ||
|
|
||
| # TESTS | ||
| TOTAL_MESSAGES= | ||
| BATCH_SIZE= | ||
| CONCURRENCY= | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # Dockerfile.consumer | ||
| FROM node:20-alpine | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| # Install only production dependencies | ||
| COPY package*.json ./ | ||
| RUN npm ci --only=production | ||
|
|
||
| # Copy consumer modular codebase structure | ||
| COPY consumer/ ./consumer/ | ||
|
|
||
| # Copy config directory (for .env file structure) | ||
| # Note: .env file should be provided via environment variables in production | ||
| # The config directory should exist in the repo (even if empty) | ||
| COPY config/ ./config/ | ||
|
|
||
| # Small health-check-friendly default command | ||
| CMD ["node", "consumer/consumer.js"] |
Uh oh!
There was an error while loading. Please reload this page.