Skip to content

Commit ca7f7d4

Browse files
committed
feat: add tests
1 parent 56c1dc5 commit ca7f7d4

30 files changed

+3418
-86
lines changed

.claude/settings.local.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"permissions": {
3-
"allow": ["Bash(pnpm run lint*)"],
3+
"allow": ["Bash(pnpm run test:*)", "Bash(pnpm run lint:*)"],
44
"deny": [],
55
"ask": []
66
}

.github/workflows/test.yml

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
name: Test Suite
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
workflow_dispatch:
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
timeout-minutes: 15
12+
13+
permissions:
14+
contents: read
15+
pull-requests: write
16+
17+
services:
18+
mysql:
19+
image: mysql:8
20+
env:
21+
MYSQL_ROOT_PASSWORD: password
22+
MYSQL_DATABASE: catalog_test
23+
ports:
24+
- 3307:3306
25+
options: >-
26+
--health-cmd="mysqladmin ping"
27+
--health-interval=10s
28+
--health-timeout=5s
29+
--health-retries=3
30+
31+
opensearch:
32+
image: opensearchproject/opensearch:3
33+
env:
34+
cluster.name: test-opensearch-cluster
35+
node.name: test-opensearch
36+
discovery.type: single-node
37+
bootstrap.memory_lock: true
38+
OPENSEARCH_JAVA_OPTS: -Xms256m -Xmx256m
39+
DISABLE_SECURITY_PLUGIN: true
40+
ports:
41+
- 9201:9200
42+
options: >-
43+
--health-cmd="curl -f http://localhost:9200/_cluster/health || exit 1"
44+
--health-interval=30s
45+
--health-timeout=10s
46+
--health-retries=3
47+
48+
steps:
49+
- name: Checkout code
50+
uses: actions/checkout@v4
51+
52+
- name: Setup pnpm
53+
uses: pnpm/action-setup@v4
54+
55+
- name: Setup Node.js
56+
uses: actions/setup-node@v4
57+
with:
58+
node-version: "lts/*"
59+
cache: pnpm
60+
61+
- name: Install dependencies
62+
run: pnpm install --frozen-lockfile
63+
64+
- name: Generate Prisma client
65+
run: pnpm run generate
66+
67+
- name: Wait for services to be ready
68+
run: |
69+
# Wait for MySQL
70+
for i in {1..30}; do
71+
if mysqladmin ping -h 127.0.0.1 -P 3307 -u root -ppassword &> /dev/null; then
72+
echo "MySQL is ready"
73+
break
74+
fi
75+
echo "Waiting for MySQL..."
76+
sleep 2
77+
done
78+
79+
# Wait for OpenSearch
80+
for i in {1..30}; do
81+
if curl -f http://localhost:9201/_cluster/health &> /dev/null; then
82+
echo "OpenSearch is ready"
83+
break
84+
fi
85+
echo "Waiting for OpenSearch..."
86+
sleep 2
87+
done
88+
89+
- name: Run database migrations
90+
run: pnpm run db:migrate
91+
env:
92+
DATABASE_URL: mysql://root:password@localhost:3307/catalog_test
93+
94+
- name: Run linting
95+
run: |
96+
pnpm run lint:biome
97+
pnpm run lint:types
98+
99+
- name: Run unit tests
100+
run: pnpm run test
101+
env:
102+
DATABASE_URL: mysql://root:password@localhost:3307/catalog_test
103+
OPENSEARCH_URL: http://localhost:9201
104+
NODE_ENV: test
105+
106+
- name: Check coverage threshold
107+
run: |
108+
# Extract coverage percentage from coverage report
109+
COVERAGE=$(cat coverage/coverage-summary.json | jq -r '.total.lines.pct')
110+
echo "Coverage: $COVERAGE%"
111+
112+
# Fail if coverage is below 95%
113+
if (( $(echo "$COVERAGE < 95" | bc -l) )); then
114+
echo "Coverage $COVERAGE% is below required 95%"
115+
exit 1
116+
fi
117+
echo "Coverage check passed: $COVERAGE%"
118+
119+
- name: Upload coverage reports
120+
uses: codecov/codecov-action@v4
121+
if: always()
122+
with:
123+
file: ./coverage/coverage-final.json
124+
fail_ci_if_error: false
125+
126+
- name: "Report Coverage"
127+
if: always()
128+
uses: davelosert/vitest-coverage-report-action@v2
129+
130+
# Job to enforce that tests must pass
131+
test-status-check:
132+
runs-on: ubuntu-latest
133+
needs: test
134+
if: always()
135+
steps:
136+
- name: Test Status Check
137+
run: |
138+
if [ "${{ needs.test.result }}" != "success" ]; then
139+
echo "Tests failed or were cancelled"
140+
exit 1
141+
fi
142+
echo "All tests passed successfully"
143+

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ dist
1616

1717
# prisma
1818
src/generated/prisma/
19+
20+
coverage

.knip.jsonc

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,6 @@
11
{
22
"$schema": "https://unpkg.com/knip@5/schema-jsonc.json",
3-
"entry": [
4-
"src/index.ts"
5-
// // CDK
6-
// "bin/paragest.ts",
7-
// "lib/paragest-stack.ts",
8-
// "reset.d.ts",
9-
//
10-
// // Our scripts
11-
// "bin/list-failures.mts",
12-
// "bin/replay-s3-event.mts",
13-
//
14-
// // Lambdas
15-
// "src/tsconfig.json",
16-
// "src/*.ts",
17-
// "src/common/*.ts",
18-
// "src/cron/*.ts",
19-
// "src/audio/*.ts",
20-
// "src/image/*.ts",
21-
// "src/video/*.ts",
22-
// "src/other/*.ts",
23-
// "src/tsconfig.json"
24-
],
25-
"ignore": ["example/src/index.express.ts", "example/src/index.fastify.ts"],
3+
"ignore": ["example/src/index.express.ts", "example/src/index.fastify.ts", "scripts/loadEntities.ts"],
264
"ignoreDependencies": [
275
// Used in prisma.schema, not directly in code
286
"prisma-json-types-generator",

0 commit comments

Comments
 (0)