Skip to content

Commit 010826b

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.
1 parent 937fcc6 commit 010826b

15 files changed

Lines changed: 264 additions & 138 deletions

File tree

apps/events-helsinki/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@
159159
"vite-plugin-css-injected-by-js": "3.5.2",
160160
"vitest": "3.2.4",
161161
"vitest-axe": "0.1.0",
162+
"vitest-sonar-reporter": "2.0.4",
162163
"waait": "^1.0.5",
163164
"webpack": "5.100.1"
164165
}

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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@
159159
"vite-plugin-css-injected-by-js": "3.5.2",
160160
"vitest": "3.2.4",
161161
"vitest-axe": "0.1.0",
162+
"vitest-sonar-reporter": "2.0.4",
162163
"waait": "^1.0.5",
163164
"webpack": "5.100.1"
164165
}

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/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@
167167
"vite-plugin-css-injected-by-js": "3.5.2",
168168
"vitest": "3.2.4",
169169
"vitest-axe": "0.1.0",
170+
"vitest-sonar-reporter": "2.0.4",
170171
"waait": "^1.0.5",
171172
"webpack": "5.100.1"
172173
}

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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@
155155
"vite": "7.0.4",
156156
"vitest": "3.2.4",
157157
"vitest-axe": "0.1.0",
158+
"vitest-sonar-reporter": "2.0.4",
158159
"waait": "^1.0.5",
159160
"webpack": "5.100.1"
160161
},

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: [

packages/graphql-proxy-server/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"typescript": "5.8.3",
7272
"vite": "7.0.4",
7373
"vitest": "3.2.4",
74+
"vitest-sonar-reporter": "2.0.4",
7475
"webpack": "5.100.1",
7576
"winston": "3.17.0"
7677
},

packages/graphql-proxy-server/vitest.config.ts

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

0 commit comments

Comments
 (0)