Skip to content

Commit a51175c

Browse files
committed
Adding feature unit tests package.json and also adding unit tests steps in Jenkinsfile.
1 parent dd60c93 commit a51175c

File tree

4 files changed

+81
-6
lines changed

4 files changed

+81
-6
lines changed

Jenkinsfile

+12-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pipeline {
1212
}
1313
}
1414

15-
stage('Chechout Node.js and npm') {
15+
stage('Check Node.js and npm') {
1616
steps {
1717
script {
1818
sh "node -v"
@@ -27,6 +27,12 @@ pipeline {
2727
}
2828
}
2929

30+
stage('Run Unit Tests') {
31+
steps {
32+
sh 'npm run test -- --coverage --reporters=jest-junit'
33+
}
34+
}
35+
3036
stage('Build Project') {
3137
steps {
3238
sh 'npm run build'
@@ -36,14 +42,16 @@ pipeline {
3642

3743
post {
3844
always {
39-
cleanWs(cleanWhenNotBuilt: false,
40-
notFailBuild: true)
45+
cleanWs(cleanWhenNotBuilt: false, notFailBuild: true)
4146
}
4247
success {
4348
echo 'Build completed successfully!'
49+
junit 'reports/junit.xml'
50+
archiveArtifacts artifacts: 'reports/**', fingerprint: true
4451
}
4552
failure {
4653
echo 'Build failed!'
54+
junit 'reports/junit.xml' // Ensures test results are captured even on failure
4755
}
4856
}
49-
}
57+
}

apps/frontend/project.json

+7
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@
4646
"lint": {
4747
"executor": "@nx/eslint:lint",
4848
"outputs": ["{options.outputFile}"]
49+
},
50+
"test": {
51+
"executor": "@nx/jest:jest",
52+
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
53+
"options": {
54+
"jestConfig": "apps/frontend/jest.config.ts"
55+
}
4956
}
5057
},
5158
"tags": []

package-lock.json

+47
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+15-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@
2929
"prisma-reset": "cd ./libraries/nestjs-libraries/src/database/prisma && npx prisma db push --force-reset && npx prisma db push",
3030
"docker-build": "./var/docker/docker-build.sh",
3131
"docker-create": "./var/docker/docker-create.sh",
32-
"postinstall": "npm run update-plugins && npm run prisma-generate"
32+
"postinstall": "npm run update-plugins && npm run prisma-generate",
33+
"test": "npx nx run-many --target=test --projects=frontend,backend,workers,cron,commands --parallel=5",
34+
"test:frontend": "npx nx run frontend:test",
35+
"test:backend": "npx nx run backend:test",
36+
"test:workers": "npx nx run workers:test",
37+
"test:cron": "npx nx run cron:test",
38+
"test:commands": "npx nx run commands:test"
3339
},
3440
"private": true,
3541
"dependencies": {
@@ -221,6 +227,7 @@
221227
"jest": "29.7.0",
222228
"jest-environment-jsdom": "29.7.0",
223229
"jest-environment-node": "^29.4.1",
230+
"jest-junit": "^16.0.0",
224231
"jsdom": "~22.1.0",
225232
"postcss": "8.4.38",
226233
"prettier": "^2.6.2",
@@ -235,5 +242,11 @@
235242
},
236243
"volta": {
237244
"node": "20.17.0"
238-
}
245+
},
246+
"jest": {
247+
"reporters": [
248+
"default",
249+
["jest-junit", { "outputDirectory": "reports", "outputName": "junit.xml" }]
250+
]
251+
}
239252
}

0 commit comments

Comments
 (0)