Skip to content

Commit 77debb3

Browse files
committed
feat: improve tests
1 parent 0c691fc commit 77debb3

8 files changed

Lines changed: 2523 additions & 455 deletions

File tree

.github/workflows/test.yaml

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,38 @@
11
name: Run Jest Tests
2+
23
on:
34
push:
5+
pull_request:
6+
47
jobs:
58
test:
69
runs-on: ubuntu-latest
10+
711
steps:
812
- name: Checkout code
913
uses: actions/checkout@v4
14+
15+
- name: Install pnpm
16+
uses: pnpm/action-setup@v4
17+
with:
18+
version: 10
19+
1020
- name: Set up Node.js
11-
uses: actions/setup-node@v3
21+
uses: actions/setup-node@v4
1222
with:
1323
node-version: '20'
24+
cache: 'pnpm'
25+
1426
- name: Install dependencies
15-
run: |
16-
npm init -y
17-
npm install --save-dev jest ts-jest @types/jest typescript
18-
- name: Configure Jest for TypeScript
19-
run: |
20-
npx ts-jest config:init
21-
- name: Run Jest tests
22-
run: npx jest src/data/quiz-templates.test.ts
27+
run: pnpm install
28+
29+
- name: Run tests
30+
run: pnpm test
31+
32+
- name: Upload test results
33+
uses: actions/upload-artifact@v4
34+
if: always()
35+
with:
36+
name: test-results
37+
path: coverage/
38+
retention-days: 30

.prettierignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ __generated__/
2424
# Test and coverage files
2525
coverage/
2626
*.spec.*
27-
*.test.*
2827

2928
# Editor-specific files
3029
.vscode/

jest.config.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
testEnvironment: 'node',
4+
roots: ['<rootDir>/src'],
5+
testMatch: [
6+
'**/__tests__/**/*.+(ts|tsx|js)',
7+
'**/*.(test|spec).+(ts|tsx|js)'
8+
],
9+
transform: {
10+
'^.+\\.(ts|tsx)$': 'ts-jest'
11+
},
12+
collectCoverageFrom: [
13+
'src/**/*.{ts,tsx}',
14+
'!src/**/*.d.ts',
15+
],
16+
coverageDirectory: 'coverage',
17+
coverageReporters: ['text', 'lcov', 'html'],
18+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'],
19+
moduleNameMapper: {
20+
'^@/(.*)$': '<rootDir>/src/$1'
21+
}
22+
};

package.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
"astro": "astro",
1616
"build": "astro build",
1717
"dev": "astro dev",
18-
"preview": "astro preview"
18+
"preview": "astro preview",
19+
"test": "jest",
20+
"test:watch": "jest --watch",
21+
"test:coverage": "jest --coverage"
1922
},
2023
"dependencies": {
2124
"@astrojs/netlify": "^6.5.3",
@@ -24,8 +27,13 @@
2427
},
2528
"devDependencies": {
2629
"@trivago/prettier-plugin-sort-imports": "5.2.2",
30+
"@types/jest": "^30.0.0",
31+
"ajv": "^8.17.1",
32+
"jest": "^30.0.5",
2733
"prettier": "3.5.3",
28-
"prettier-plugin-astro": "0.14.1"
34+
"prettier-plugin-astro": "0.14.1",
35+
"ts-jest": "^29.4.1",
36+
"typescript": "^5.9.2"
2937
},
3038
"packageManager": "pnpm@10.10.0"
3139
}

0 commit comments

Comments
 (0)