Skip to content

Commit 2114dfd

Browse files
Copilotrenemadsen
andcommitted
Update workflows to be more flexible with test script detection and add package.json setup guide
Co-authored-by: renemadsen <[email protected]>
1 parent 1b7ec46 commit 2114dfd

File tree

3 files changed

+195
-8
lines changed

3 files changed

+195
-8
lines changed

.github/workflows/dotnet-core-master.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,15 @@ jobs:
7171
- name: Run Angular unit tests
7272
run: |
7373
cd eform-angular-frontend/eform-client
74-
# Check if test:ci script exists, otherwise use test with headless mode
75-
if npm run test:ci --help &> /dev/null; then
76-
npm run test:ci -- --include='**/time-planning-pn/**/*.spec.ts' || echo "Unit tests failed or not configured"
74+
# Try different test commands based on what's available in package.json
75+
if grep -q '"test:ci"' package.json 2>/dev/null; then
76+
echo "Running with test:ci script..."
77+
npm run test:ci -- --include='**/time-planning-pn/**/*.spec.ts' || true
78+
elif grep -q '"test"' package.json 2>/dev/null; then
79+
echo "Running with test script..."
80+
npm run test -- --watch=false --browsers=ChromeHeadless --include='**/time-planning-pn/**/*.spec.ts' || true
7781
else
78-
echo "test:ci not configured in main frontend, skipping unit tests for now"
82+
echo "No test script found in package.json, skipping unit tests"
7983
fi
8084
continue-on-error: true
8185
pn-test:

.github/workflows/dotnet-core-pr.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,15 @@ jobs:
6565
- name: Run Angular unit tests
6666
run: |
6767
cd eform-angular-frontend/eform-client
68-
# Check if test:ci script exists, otherwise use test with headless mode
69-
if npm run test:ci --help &> /dev/null; then
70-
npm run test:ci -- --include='**/time-planning-pn/**/*.spec.ts' || echo "Unit tests failed or not configured"
68+
# Try different test commands based on what's available in package.json
69+
if grep -q '"test:ci"' package.json 2>/dev/null; then
70+
echo "Running with test:ci script..."
71+
npm run test:ci -- --include='**/time-planning-pn/**/*.spec.ts' || true
72+
elif grep -q '"test"' package.json 2>/dev/null; then
73+
echo "Running with test script..."
74+
npm run test -- --watch=false --browsers=ChromeHeadless --include='**/time-planning-pn/**/*.spec.ts' || true
7175
else
72-
echo "test:ci not configured in main frontend, skipping unit tests for now"
76+
echo "No test script found in package.json, skipping unit tests"
7377
fi
7478
continue-on-error: true
7579
pn-test:

PACKAGE_JSON_SETUP.md

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
# Package.json Configuration for Angular Unit Tests
2+
3+
## Overview
4+
This document explains the package.json configuration needed in the main `eform-angular-frontend` repository to support running unit tests for the time-planning-pn plugin.
5+
6+
## Required Test Scripts
7+
8+
The GitHub Actions workflows will try to run tests using one of these approaches (in order):
9+
10+
### Option 1: test:ci script (Recommended)
11+
If your package.json has a `test:ci` script, it will use that:
12+
13+
```json
14+
{
15+
"scripts": {
16+
"test:ci": "ng test --watch=false --code-coverage --browsers=ChromeHeadless"
17+
}
18+
}
19+
```
20+
21+
### Option 2: test script with parameters
22+
If `test:ci` is not available, it will try to use the `test` script with additional parameters:
23+
24+
```json
25+
{
26+
"scripts": {
27+
"test": "ng test"
28+
}
29+
}
30+
```
31+
32+
The workflow will add `--watch=false --browsers=ChromeHeadless` automatically.
33+
34+
## Common Issues and Solutions
35+
36+
### Issue 1: "--include" parameter not recognized
37+
38+
If you're using Karma with Jasmine, the `--include` parameter might not work. Instead, you can:
39+
40+
**Solution A:** Use a karma.conf.js configuration that supports file filtering:
41+
```javascript
42+
// karma.conf.js
43+
module.exports = function(config) {
44+
config.set({
45+
// ... other config
46+
files: [
47+
{ pattern: './src/**/*.spec.ts', included: true, watched: true }
48+
],
49+
});
50+
};
51+
```
52+
53+
**Solution B:** Update package.json to support include patterns:
54+
```json
55+
{
56+
"scripts": {
57+
"test:ci": "ng test --watch=false --code-coverage --browsers=ChromeHeadless",
58+
"test:plugin": "ng test --watch=false --browsers=ChromeHeadless --include='**/time-planning-pn/**/*.spec.ts'"
59+
}
60+
}
61+
```
62+
63+
### Issue 2: ChromeHeadless not available
64+
65+
If ChromeHeadless browser is not configured:
66+
67+
**Solution:** Install and configure Chrome headless in karma.conf.js:
68+
```javascript
69+
// karma.conf.js
70+
module.exports = function(config) {
71+
config.set({
72+
browsers: ['ChromeHeadless'],
73+
customLaunchers: {
74+
ChromeHeadlessCI: {
75+
base: 'ChromeHeadless',
76+
flags: ['--no-sandbox', '--disable-gpu']
77+
}
78+
}
79+
});
80+
};
81+
```
82+
83+
Then update package.json:
84+
```json
85+
{
86+
"scripts": {
87+
"test:ci": "ng test --watch=false --browsers=ChromeHeadlessCI"
88+
}
89+
}
90+
```
91+
92+
### Issue 3: Angular version compatibility
93+
94+
For Angular 15+, you might need to use the new test configuration:
95+
96+
```json
97+
{
98+
"scripts": {
99+
"test": "ng test",
100+
"test:ci": "ng test --no-watch --no-progress --browsers=ChromeHeadless --code-coverage"
101+
}
102+
}
103+
```
104+
105+
### Issue 4: Jest instead of Karma
106+
107+
If your project uses Jest instead of Karma:
108+
109+
```json
110+
{
111+
"scripts": {
112+
"test": "jest",
113+
"test:ci": "jest --ci --coverage --testPathPattern='time-planning-pn'"
114+
}
115+
}
116+
```
117+
118+
## Recommended Configuration
119+
120+
For the most compatibility with the time-planning-pn plugin tests, use this configuration:
121+
122+
```json
123+
{
124+
"scripts": {
125+
"test": "ng test",
126+
"test:ci": "ng test --no-watch --no-progress --browsers=ChromeHeadless --code-coverage",
127+
"test:headless": "ng test --no-watch --browsers=ChromeHeadless"
128+
},
129+
"devDependencies": {
130+
"@angular-devkit/build-angular": "^15.0.0",
131+
"karma": "~6.4.0",
132+
"karma-chrome-launcher": "~3.1.0",
133+
"karma-coverage": "~2.2.0",
134+
"karma-jasmine": "~5.1.0",
135+
"karma-jasmine-html-reporter": "~2.0.0"
136+
}
137+
}
138+
```
139+
140+
## Workflow Behavior
141+
142+
The GitHub Actions workflow (`.github/workflows/dotnet-core-master.yml` and `dotnet-core-pr.yml`) will:
143+
144+
1. Check if `test:ci` script exists in package.json
145+
2. If yes, run: `npm run test:ci -- --include='**/time-planning-pn/**/*.spec.ts'`
146+
3. If no, check if `test` script exists
147+
4. If yes, run: `npm run test -- --watch=false --browsers=ChromeHeadless --include='**/time-planning-pn/**/*.spec.ts'`
148+
5. If neither exists, skip the tests with a message
149+
6. The step has `continue-on-error: true`, so it won't fail the entire workflow
150+
151+
## Testing Locally
152+
153+
To test if your configuration works:
154+
155+
```bash
156+
# Clone both repositories
157+
git clone https://github.com/microting/eform-angular-frontend.git
158+
git clone https://github.com/microting/eform-angular-timeplanning-plugin.git
159+
160+
# Copy plugin files
161+
cp -r eform-angular-timeplanning-plugin/eform-client/src/app/plugins/modules/time-planning-pn \
162+
eform-angular-frontend/eform-client/src/app/plugins/modules/
163+
164+
# Install dependencies
165+
cd eform-angular-frontend/eform-client
166+
npm install
167+
168+
# Try running tests
169+
npm run test:ci -- --include='**/time-planning-pn/**/*.spec.ts'
170+
# or
171+
npm run test -- --watch=false --browsers=ChromeHeadless
172+
```
173+
174+
## Contact
175+
176+
If you need help configuring the tests, check:
177+
- Angular CLI testing documentation: https://angular.io/guide/testing
178+
- Karma configuration: https://karma-runner.github.io/latest/config/configuration-file.html
179+
- The test files in this repository for examples

0 commit comments

Comments
 (0)