Skip to content

Commit 8563362

Browse files
test: support server-side unit testing (#2485)
1 parent 40edaea commit 8563362

17 files changed

Lines changed: 2379 additions & 92 deletions

.github/workflows/ci.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,51 @@ jobs:
127127
- name: Build
128128
run: pnpm build
129129

130+
unit-test:
131+
name: Unit Tests
132+
if: github.event_name == 'pull_request'
133+
runs-on: ubuntu-24.04
134+
container: node:22.22.0-alpine3.22@sha256:0c49915657c1c77c64c8af4d91d2f13fe96853bbd957993ed00dd592cbecc284
135+
permissions:
136+
checks: write
137+
steps:
138+
- name: Checkout
139+
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
140+
with:
141+
persist-credentials: false
142+
143+
- name: Pnpm Setup
144+
uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4.2.0
145+
146+
- name: Get pnpm store directory
147+
shell: sh
148+
run: |
149+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
150+
151+
- name: Setup pnpm cache
152+
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
153+
with:
154+
path: ${{ env.STORE_PATH }}
155+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
156+
restore-keys: |
157+
${{ runner.os }}-pnpm-store-
158+
159+
- name: Install dependencies
160+
env:
161+
CI: true
162+
run: pnpm install
163+
164+
- name: Run tests
165+
env:
166+
CI: true
167+
run: pnpm test
168+
169+
- name: Publish test report
170+
uses: mikepenz/action-junit-report@74626db7353a25a20a72816467ebf035f674c5f8 # v6.2.0
171+
if: success() || failure() # always run even if the previous step fails
172+
with:
173+
report_paths: 'report.xml'
174+
130175
build:
131176
name: Build (per-arch, native runners)
132177
if: github.ref == 'refs/heads/develop'

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
# testing
77
/coverage
8+
lcov.info
89

910
# next.js
1011
/.next/

.vscode/extensions.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
"stylelint.vscode-stylelint",
1818

19-
"bradlc.vscode-tailwindcss"
19+
"bradlc.vscode-tailwindcss",
20+
"firsttris.vscode-jest-runner"
2021
]
2122
}

.vscode/settings.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,12 @@
2323
"i18n-ally.localesPaths": [
2424
"src/i18n/locale"
2525
],
26-
"yaml.format.singleQuote": true
26+
"yaml.format.singleQuote": true,
27+
"jestrunner.enableTestExplorer": true,
28+
"jestrunner.defaultTestPatterns": [
29+
"server/**/*.{test,spec}.?(c|m)[jt]s?(x)",
30+
],
31+
"jestrunner.nodeTestCommand": "pnpm test",
32+
"jestrunner.changeDirectoryToWorkspaceRoot": true,
33+
"jestrunner.projectPath": "."
2734
}

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"build": "pnpm build:next && pnpm build:server",
1313
"lint": "eslint \"./server/**/*.{ts,tsx}\" \"./src/**/*.{ts,tsx}\" --cache",
1414
"lintfix": "eslint \"./server/**/*.{ts,tsx}\" \"./src/**/*.{ts,tsx}\" --fix",
15+
"test": "node server/test/index.mts",
1516
"start": "NODE_ENV=production node dist/index.js",
1617
"i18n:extract": "ts-node --project server/tsconfig.json src/i18n/extractMessages.ts",
1718
"migration:generate": "ts-node -r tsconfig-paths/register --project server/tsconfig.json ./node_modules/typeorm/cli.js migration:generate -d server/datasource.ts",
@@ -137,6 +138,7 @@
137138
"@types/react-transition-group": "4.4.12",
138139
"@types/secure-random-password": "0.2.1",
139140
"@types/semver": "7.7.1",
141+
"@types/supertest": "^6.0.3",
140142
"@types/swagger-ui-express": "4.1.8",
141143
"@types/validator": "^13.15.10",
142144
"@types/web-push": "3.6.4",
@@ -147,6 +149,7 @@
147149
"@typescript-eslint/parser": "7.18.0",
148150
"autoprefixer": "^10.4.23",
149151
"baseline-browser-mapping": "^2.8.32",
152+
"commander": "^14.0.3",
150153
"commitizen": "4.3.1",
151154
"copyfiles": "2.4.1",
152155
"cy-mobile-commands": "0.3.0",
@@ -168,6 +171,7 @@
168171
"prettier": "3.8.1",
169172
"prettier-plugin-organize-imports": "4.3.0",
170173
"prettier-plugin-tailwindcss": "0.6.14",
174+
"supertest": "^7.2.2",
171175
"tailwindcss": "3.4.19",
172176
"ts-node": "10.9.2",
173177
"tsc-alias": "1.8.16",

0 commit comments

Comments
 (0)