Skip to content

Commit d8d7ae4

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 d8d7ae4

18 files changed

Lines changed: 270 additions & 143 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: [

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",

packages/components/vitest.config.ts

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,41 @@ export default defineConfig(({ mode }) => ({
1919
cache: {
2020
dir: '../../.cache/events-helsinki-components/vitest', // Vitest specific cache
2121
},
22-
include: ['src/**/*.{spec,test}.{js,jsx,ts,tsx}'], // Match your Jest testMatch
22+
include: ['src/**/*.{spec,test}.{js,jsx,ts,tsx}'],
2323
exclude: [...configDefaults.exclude, './.next/', '/__mocks__/'],
24-
// Optional: Configure coverage if needed (equivalent to Jest's collectCoverageFrom, coverageDirectory)
25-
// coverage: {
26-
// provider: 'v8', // or 'istanbul'
27-
// reporter: ['json', 'html', 'text'],
28-
// include: ['src/**/*.{ts,tsx,js,jsx}'],
29-
// exclude: [
30-
// 'src/**/*.test.ts',
31-
// 'src/.next/**',
32-
// // Add other patterns from Jest's coveragePathIgnorePatterns if needed
33-
// // Be careful with node_modules here, Vitest handles them differently
34-
// ],
35-
// },
36-
// deps: {
37-
// interopDefault: true, // Helps with CommonJS default exports
38-
// Force these packages to be transformed
39-
// inline: ['react-helsinki-headless-cms', '@apollo/client', '@next/env'],
40-
// },
24+
reporters: ['json', 'verbose', 'vitest-sonar-reporter'],
25+
outputFile: {
26+
json: 'sonar-report.json',
27+
'vitest-sonar-reporter': 'sonar-report.xml',
28+
},
29+
coverage: {
30+
provider: 'v8', // or 'istanbul'
31+
reporter: ['lcov', 'html', 'text'],
32+
include: ['src/**/*.{ts,tsx,js,jsx}'],
33+
exclude: [
34+
'src/**/*.test.ts',
35+
'src/.next/**',
36+
'**/*.d.ts',
37+
'**/*.json',
38+
'**/*.xml',
39+
'**/*.yaml',
40+
'**/*.md',
41+
'**/*.html',
42+
'**/*.css',
43+
'**/*.properties',
44+
'*.config.*js',
45+
'node_modules/',
46+
'browser-tests/',
47+
'build/',
48+
'codegen.ts',
49+
'src/index.tsx',
50+
'**/__tests__/**',
51+
'**/__snapshots__/**',
52+
'**/*.test.ts',
53+
'**/*.spec.ts',
54+
'**/query.ts',
55+
],
56+
},
4157
},
4258
resolve: {
4359
alias: [

0 commit comments

Comments
 (0)