Gathering detailed insights and metrics for vitest-sonar-reporter
Gathering detailed insights and metrics for vitest-sonar-reporter
Gathering detailed insights and metrics for vitest-sonar-reporter
Gathering detailed insights and metrics for vitest-sonar-reporter
npm install vitest-sonar-reporter
Typescript
Module System
Min. Node Version
Node Version
NPM Version
v2.0.1
Updated on May 02, 2025
v2.0.0
Updated on Feb 25, 2024
v1.1.0 - custom options support
Updated on Feb 17, 2024
v1.0.0 - Support Vitest 1.0
Updated on Dec 04, 2023
v0.5.0 - Support vitest@1.0.0-beta.3
Updated on Oct 27, 2023
v0.4.1 - Workspace support fixed
Updated on May 18, 2023
TypeScript (92.48%)
JavaScript (7.52%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
33 Stars
341 Commits
4 Forks
2 Watchers
1 Branches
3 Contributors
Updated on Jul 07, 2025
Latest Version
2.0.1
Package Id
vitest-sonar-reporter@2.0.1
Unpacked Size
18.11 kB
Size
6.27 kB
File Count
11
NPM Version
10.9.2
Node Version
22.15.0
Published on
May 02, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Live examples | Installation | Configuration | Code coverage | Examples
Generates Generic Execution reports from vitest
tests for SonarQube to analyze.
{ type: "module" }
| Stackblitz{ type: "commonjs" }
| Stackblitzvitest-sonar-reporter
should be included in development dependencies. vitest
is required as peer dependency.
1npm install --save-dev vitest-sonar-reporter
Add new custom reporter and define outputFile
in your vite.config.ts
:
1import { defineConfig } from 'vitest/config';
2
3export default defineConfig({
4 test: {
5 reporters: [
6 'default', // Vitest's default reporter so that terminal output is still visible
7 ['vitest-sonar-reporter', { outputFile: 'sonar-report.xml' }],
8 ],
9 },
10});
If you are using Vitest below version ^1.3.0
you can define file in test.outputFile
:
1test: { 2 reporters: ['json', 'verbose', 'vitest-sonar-reporter'], 3 outputFile: { 4 json: 'my-json-report.json', 5 'vitest-sonar-reporter': 'sonar-report.xml', 6 }, 7},
Instruct SonarQube to pick report in your sonar-project.properties
:
sonar.testExecutionReportPaths=sonar-report.xml
You can pass additional options to reporter. Note that this requires vitest@^1.3.0
.
silent
Silence reporter's verbose logging.
1test: { 2 reporters: [ 3 ['vitest-sonar-reporter', { silent: true }] 4 ], 5}
onWritePath
Rewrite path
attribute of <file>
. This can be useful when you need to change relative paths of the files.
1test: { 2 reporters: [ 3 ['vitest-sonar-reporter', { 4 onWritePath(path: string) { 5 // Prefix all paths with root directory 6 // e.g. '<file path="test/math.ts">' to '<file path="frontend/test/math.ts">' 7 return `frontend/${path}`; 8 } 9 }] 10 ], 11}
1<testExecutions version="1"> 2- <file path="test/math.ts"> 3+ <file path="frontend/test/math.ts"> 4 <testCase name="multiply" duration="123" /> 5 </file> 6</testExecutions>
outputFile
Location for the report.
1test: { 2 reporters: [ 3 ['vitest-sonar-reporter', { outputFile: 'sonar-report.xml' }] 4 ], 5}
This reporter does not process code coverage - Vitest already supports that out-of-the-box!
Simply configure vitest
to output LCOV reports and instruct SonarQube to pick these reports.
1test: { 2 coverage: { 3 reporters: 'lcov', 4 }, 5},
sonar.javascript.lcov.reportPaths=./coverage/lcov.info
See examples/example-workspace for example setup using Vitest Workspaces.
1import { describe, expect, test } from 'vitest'; 2 3describe('animals', () => { 4 test('dogs say woof', () => { 5 const dog = { say: () => 'woof' }; 6 expect(dog.say()).toBe('woof'); 7 }); 8 9 test.todo('figure out what rabbits say', () => { 10 const rabbit = { say: () => '????' }; 11 expect(rabbit.say()).toBe('?'); 12 }); 13 14 describe('flying ones', () => { 15 test('cats can fly', () => { 16 const cat = { fly: () => false }; 17 expect(cat.fly()).toBe(true); 18 }); 19 20 test('birds can fly', () => { 21 const bird = { fly: () => true }; 22 expect(bird.fly()).toBe(true); 23 }); 24 }); 25});
1<?xml version="1.0" encoding="UTF-8"?> 2<testExecutions version="1"> 3 <file path="test/animals.test.ts"> 4 <testCase name="animals - dogs say woof" duration="2" /> 5 <testCase name="animals - figure out what rabbits say" duration="0"> 6 <skipped message="figure out what rabbits say" /> 7 </testCase> 8 <testCase name="animals - flying ones - cats can fly" duration="4"> 9 <failure message="expected false to be true // Object.is equality"> 10 <![CDATA[AssertionError: expected false to be true // Object.is equality 11 at /workspaces/example/test/animals.test.ts:15:47 12 at /workspaces/example/node_modules/vitest/dist/chunk-runtime-chain.7032872a.js:82:26 13 at runTest (/workspaces/example/node_modules/vitest/dist/entry.js:771:40) 14 at async runSuite (/workspaces/example/node_modules/vitest/dist/entry.js:836:13) 15 at async runSuite (/workspaces/example/node_modules/vitest/dist/entry.js:836:13) 16 at async runSuite (/workspaces/example/node_modules/vitest/dist/entry.js:836:13) 17 at async runFiles (/workspaces/example/node_modules/vitest/dist/entry.js:873:5) 18 at async startTests (/workspaces/example/node_modules/vitest/dist/entry.js:879:3) 19 at async /workspaces/example/node_modules/vitest/dist/entry.js:906:7 20 at async withEnv (/workspaces/example/node_modules/vitest/dist/entry.js:503:5)]]> 21 </failure> 22 </testCase> 23 <testCase name="animals - flying ones - birds can fly" duration="5" /> 24 </file> 25</testExecutions>
No vulnerabilities found.
No security vulnerabilities found.