Skip to content

Commit 90cd769

Browse files
committed
chore(test-coverage): add vitest coverage configuration
TH-1409. The Vitest should make a coverage report for Sonarcloud. Therefore, this commit adds `vitest-sonar-reporter` as a dependency and configures the vitest coverage reporters. Set sonar default branch to "main".
1 parent c7053c1 commit 90cd769

19 files changed

Lines changed: 273 additions & 144 deletions

File tree

apps/events-helsinki/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@
8383
"react-i18next": "15.6.0",
8484
"react-scroll": "^1.9.3",
8585
"react-toastify": "^11.0.5",
86-
"sanitize-html": "^2.17.0"
86+
"sanitize-html": "^2.17.0",
87+
"vitest-sonar-reporter": "2.0.4"
8788
},
8889
"devDependencies": {
8990
"@commitlint/cli": "^19.8.1",

apps/events-helsinki/sonar-project.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
sonar.projectKey = City-of-Helsinki_tapahtumat-ui
2+
sonar.branch.name = main
23
sonar.organization = city-of-helsinki
34
sonar.exclusions = **/__tests__/**,**/browser-tests/**
45
sonar.sources = src

apps/events-helsinki/vitest.config.ts

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -53,36 +53,49 @@ const aliasPaths = paths
5353
: [];
5454

5555
export default defineConfig({
56-
plugins: [
57-
react(),
58-
cssInjectedByJsPlugin(), // CSS transformation: CSS/Image handling in Jest's transform.
59-
],
56+
plugins: [react(), cssInjectedByJsPlugin()],
6057
test: {
6158
environment: 'jsdom',
6259
globals: true, // Makes test, expect, vi global
6360
setupFiles: ['./vitest-setup.ts'],
6461
cache: {
6562
dir: '../../.cache/events-helsinki/vitest', // Vitest specific cache
6663
},
67-
include: ['src/**/*.{spec,test}.{js,jsx,ts,tsx}'], // Match your Jest testMatch
64+
include: ['src/**/*.{spec,test}.{js,jsx,ts,tsx}'],
6865
exclude: [...configDefaults.exclude, './.next/', '/__mocks__/'],
69-
// Optional: Configure coverage if needed (equivalent to Jest's collectCoverageFrom, coverageDirectory)
70-
// coverage: {
71-
// provider: 'v8', // or 'istanbul'
72-
// reporter: ['json', 'html', 'text'],
73-
// include: ['src/**/*.{ts,tsx,js,jsx}'],
74-
// exclude: [
75-
// 'src/**/*.test.ts',
76-
// 'src/.next/**',
77-
// // Add other patterns from Jest's coveragePathIgnorePatterns if needed
78-
// // Be careful with node_modules here, Vitest handles them differently
79-
// ],
80-
// },
81-
// deps: {
82-
// interopDefault: true, // Helps with CommonJS default exports
83-
// Force these packages to be transformed
84-
// inline: ['react-helsinki-headless-cms', '@apollo/client', '@next/env'],
85-
// },
66+
reporters: ['json', 'verbose', 'vitest-sonar-reporter'],
67+
outputFile: {
68+
json: 'sonar-report.json',
69+
'vitest-sonar-reporter': 'sonar-report.xml',
70+
},
71+
coverage: {
72+
provider: 'v8', // or 'istanbul'
73+
reporter: ['lcov', 'html', 'text'],
74+
include: ['src/**/*.{ts,tsx,js,jsx}'],
75+
exclude: [
76+
'src/**/*.test.ts',
77+
'src/.next/**',
78+
'**/*.d.ts',
79+
'**/*.json',
80+
'**/*.xml',
81+
'**/*.yaml',
82+
'**/*.md',
83+
'**/*.html',
84+
'**/*.css',
85+
'**/*.properties',
86+
'*.config.*js',
87+
'node_modules/',
88+
'browser-tests/',
89+
'build/',
90+
'codegen.ts',
91+
'src/index.tsx',
92+
'**/__tests__/**',
93+
'**/__snapshots__/**',
94+
'**/*.test.ts',
95+
'**/*.spec.ts',
96+
'**/query.ts',
97+
],
98+
},
8699
},
87100
resolve: {
88101
alias: [

apps/hobbies-helsinki/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@
8383
"react-i18next": "15.6.0",
8484
"react-scroll": "^1.9.3",
8585
"react-toastify": "^11.0.5",
86-
"sanitize-html": "^2.17.0"
86+
"sanitize-html": "^2.17.0",
87+
"vitest-sonar-reporter": "2.0.4"
8788
},
8889
"devDependencies": {
8990
"@commitlint/cli": "^19.8.1",

apps/hobbies-helsinki/sonar-project.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
sonar.projectKey = City-of-Helsinki_harrastukset-ui
2+
sonar.branch.name = main
23
sonar.organization = city-of-helsinki
34
sonar.exclusions = **/__tests__/**,**/browser-tests/**
45
sonar.sources = src

apps/hobbies-helsinki/vitest.config.ts

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -53,36 +53,49 @@ const aliasPaths = paths
5353
: [];
5454

5555
export default defineConfig({
56-
plugins: [
57-
react(),
58-
cssInjectedByJsPlugin(), // CSS transformation: CSS/Image handling in Jest's transform.
59-
],
56+
plugins: [react(), cssInjectedByJsPlugin()],
6057
test: {
6158
environment: 'jsdom',
6259
globals: true, // Makes test, expect, vi global
6360
setupFiles: ['./vitest-setup.ts'],
6461
cache: {
6562
dir: '../../.cache/hobbies-helsinki/vitest', // Vitest specific cache
6663
},
67-
include: ['src/**/*.{spec,test}.{js,jsx,ts,tsx}'], // Match your Jest testMatch
64+
include: ['src/**/*.{spec,test}.{js,jsx,ts,tsx}'],
6865
exclude: [...configDefaults.exclude, './.next/', '/__mocks__/'],
69-
// Optional: Configure coverage if needed (equivalent to Jest's collectCoverageFrom, coverageDirectory)
70-
// coverage: {
71-
// provider: 'v8', // or 'istanbul'
72-
// reporter: ['json', 'html', 'text'],
73-
// include: ['src/**/*.{ts,tsx,js,jsx}'],
74-
// exclude: [
75-
// 'src/**/*.test.ts',
76-
// 'src/.next/**',
77-
// // Add other patterns from Jest's coveragePathIgnorePatterns if needed
78-
// // Be careful with node_modules here, Vitest handles them differently
79-
// ],
80-
// },
81-
// deps: {
82-
// interopDefault: true, // Helps with CommonJS default exports
83-
// Force these packages to be transformed
84-
// inline: ['react-helsinki-headless-cms', '@apollo/client', '@next/env'],
85-
// },
66+
reporters: ['json', 'verbose', 'vitest-sonar-reporter'],
67+
outputFile: {
68+
json: 'sonar-report.json',
69+
'vitest-sonar-reporter': 'sonar-report.xml',
70+
},
71+
coverage: {
72+
provider: 'v8', // or 'istanbul'
73+
reporter: ['lcov', 'html', 'text'],
74+
include: ['src/**/*.{ts,tsx,js,jsx}'],
75+
exclude: [
76+
'src/**/*.test.ts',
77+
'src/.next/**',
78+
'**/*.d.ts',
79+
'**/*.json',
80+
'**/*.xml',
81+
'**/*.yaml',
82+
'**/*.md',
83+
'**/*.html',
84+
'**/*.css',
85+
'**/*.properties',
86+
'*.config.*js',
87+
'node_modules/',
88+
'browser-tests/',
89+
'build/',
90+
'codegen.ts',
91+
'src/index.tsx',
92+
'**/__tests__/**',
93+
'**/__snapshots__/**',
94+
'**/*.test.ts',
95+
'**/*.spec.ts',
96+
'**/query.ts',
97+
],
98+
},
8699
},
87100
resolve: {
88101
alias: [

apps/sports-helsinki/sonar-project.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
sonar.projectKey = City-of-Helsinki_liikunta-ui
2+
sonar.branch.name = main
23
sonar.organization = city-of-helsinki
34
sonar.exclusions = **/__tests__/**,**/browser-tests/**
45
sonar.sources = src

apps/sports-helsinki/vitest.config.ts

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -53,36 +53,49 @@ const aliasPaths = paths
5353
: [];
5454

5555
export default defineConfig({
56-
plugins: [
57-
react(),
58-
cssInjectedByJsPlugin(), // CSS transformation: CSS/Image handling in Jest's transform.
59-
],
56+
plugins: [react(), cssInjectedByJsPlugin()],
6057
test: {
6158
environment: 'jsdom',
6259
globals: true, // Makes test, expect, vi global
6360
setupFiles: ['./vitest-setup.ts'],
6461
cache: {
6562
dir: '../../.cache/sports-helsinki/vitest', // Vitest specific cache
6663
},
67-
include: ['src/**/*.{spec,test}.{js,jsx,ts,tsx}'], // Match your Jest testMatch
64+
include: ['src/**/*.{spec,test}.{js,jsx,ts,tsx}'],
6865
exclude: [...configDefaults.exclude, './.next/', '/__mocks__/'],
69-
// Optional: Configure coverage if needed (equivalent to Jest's collectCoverageFrom, coverageDirectory)
70-
// coverage: {
71-
// provider: 'v8', // or 'istanbul'
72-
// reporter: ['json', 'html', 'text'],
73-
// include: ['src/**/*.{ts,tsx,js,jsx}'],
74-
// exclude: [
75-
// 'src/**/*.test.ts',
76-
// 'src/.next/**',
77-
// // Add other patterns from Jest's coveragePathIgnorePatterns if needed
78-
// // Be careful with node_modules here, Vitest handles them differently
79-
// ],
80-
// },
81-
// deps: {
82-
// interopDefault: true, // Helps with CommonJS default exports
83-
// Force these packages to be transformed
84-
// inline: ['react-helsinki-headless-cms', '@apollo/client', '@next/env'],
85-
// },
66+
reporters: ['json', 'verbose', 'vitest-sonar-reporter'],
67+
outputFile: {
68+
json: 'sonar-report.json',
69+
'vitest-sonar-reporter': 'sonar-report.xml',
70+
},
71+
coverage: {
72+
provider: 'v8', // or 'istanbul'
73+
reporter: ['lcov', 'html', 'text'],
74+
include: ['src/**/*.{ts,tsx,js,jsx}'],
75+
exclude: [
76+
'src/**/*.test.ts',
77+
'src/.next/**',
78+
'**/*.d.ts',
79+
'**/*.json',
80+
'**/*.xml',
81+
'**/*.yaml',
82+
'**/*.md',
83+
'**/*.html',
84+
'**/*.css',
85+
'**/*.properties',
86+
'*.config.*js',
87+
'node_modules/',
88+
'browser-tests/',
89+
'build/',
90+
'codegen.ts',
91+
'src/index.tsx',
92+
'**/__tests__/**',
93+
'**/__snapshots__/**',
94+
'**/*.test.ts',
95+
'**/*.spec.ts',
96+
'**/query.ts',
97+
],
98+
},
8699
},
87100
resolve: {
88101
alias: [

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@
110110
"next-transpile-modules": "10.0.1",
111111
"postcss": "^8.5.6",
112112
"react": "18.3.1",
113-
"react-dom": "18.3.1"
113+
"react-dom": "18.3.1",
114+
"vitest-sonar-reporter": "2.0.4"
114115
},
115116
"devDependencies": {
116117
"@babel/core": "7.28.0",

packages/components/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@
8383
"react-i18next": "15.6.0",
8484
"react-leaflet": "4.2.1",
8585
"react-toastify": "^11.0.5",
86-
"sanitize-html": "^2.17.0"
86+
"sanitize-html": "^2.17.0",
87+
"vitest-sonar-reporter": "2.0.4"
8788
},
8889
"devDependencies": {
8990
"@babel/core": "7.28.0",

0 commit comments

Comments
 (0)