Skip to content

Commit c03e3df

Browse files
author
Sisyphos
committed
test: add Karma/Jasmine testing setup with coverage and CI
- Install karma, jasmine, karma-coverage testing dependencies - Add karma.conf.js with coverage reporting (html, text-summary, lcov) - Add src/test.ts for Angular testing environment - Create SwissParlService unit tests - Create BusinessService unit tests - Create AppComponent integration test - Add GitHub Actions workflow for on-demand testing - Add npm scripts: test, test:ci, test:coverage
1 parent 9b0c583 commit c03e3df

File tree

9 files changed

+1417
-23
lines changed

9 files changed

+1417
-23
lines changed

.github/workflows/test.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Tests
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
branches: [main]
7+
push:
8+
branches: [main]
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Setup Node.js
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: '22'
22+
cache: 'npm'
23+
24+
- name: Install dependencies
25+
run: npm ci
26+
27+
- name: Run tests
28+
run: npm run test:ci
29+
30+
- name: Upload coverage report
31+
uses: actions/upload-artifact@v4
32+
with:
33+
name: coverage-report
34+
path: coverage/parlwatch/
35+
retention-days: 30
36+
37+
- name: Post coverage summary
38+
run: |
39+
echo "### Test Coverage Summary" >> $GITHUB_STEP_SUMMARY
40+
cat coverage/parlwatch/index.html | grep -oP '[^>]+(?=%</span>)' | head -1 | xargs -I {} echo "- Overall Coverage: {}%" >> $GITHUB_STEP_SUMMARY || echo "- Coverage report generated" >> $GITHUB_STEP_SUMMARY

karma.conf.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Karma configuration file for Angular testing
2+
// Generated for Angular 20 + Ionic project
3+
4+
module.exports = function (config) {
5+
config.set({
6+
basePath: '',
7+
frameworks: ['jasmine', '@angular-devkit/build-angular'],
8+
plugins: [
9+
require('karma-jasmine'),
10+
require('karma-jasmine-html-reporter'),
11+
require('karma-chrome-launcher'),
12+
require('karma-coverage'),
13+
require('@angular-devkit/build-angular/plugins/karma')
14+
],
15+
client: {
16+
jasmine: {
17+
// you can add configuration options for Jasmine here
18+
// the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
19+
},
20+
clearContext: false // leave Jasmine Spec Runner output visible in browser
21+
},
22+
jasmineHtmlReporter: {
23+
suppressAll: true // removes the duplicated traces
24+
},
25+
coverageReporter: {
26+
dir: require('path').join(__dirname, './coverage/parlwatch'),
27+
subdir: '.',
28+
reporters: [
29+
{ type: 'html' },
30+
{ type: 'text-summary' },
31+
{ type: 'lcovonly' }
32+
],
33+
check: {
34+
global: {
35+
statements: 0,
36+
branches: 0,
37+
functions: 0,
38+
lines: 0
39+
}
40+
}
41+
},
42+
reporters: ['progress', 'kjhtml', 'coverage'],
43+
browsers: ['ChromeHeadless'],
44+
customLaunchers: {
45+
ChromeHeadlessCI: {
46+
base: 'ChromeHeadless',
47+
flags: ['--no-sandbox', '--disable-gpu']
48+
}
49+
},
50+
restartOnFileChange: true,
51+
singleRun: false
52+
});
53+
};

0 commit comments

Comments
 (0)