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
51.7
Supply Chain
88
Quality
78.2
Maintenance
100
Vulnerability
97.9
License
v2.0.0
Published on 25 Feb 2024
v1.1.0 - custom options support
Published on 17 Feb 2024
v1.0.0 - Support Vitest 1.0
Published on 04 Dec 2023
v0.5.0 - Support vitest@1.0.0-beta.3
Published on 27 Oct 2023
v0.4.1 - Workspace support fixed
Published on 18 May 2023
v0.4.0
Published on 22 Mar 2023
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
30 Stars
296 Commits
4 Forks
3 Watching
1 Branches
3 Contributors
Updated on 25 Nov 2024
TypeScript (92.31%)
JavaScript (7.69%)
Cumulative downloads
Total Downloads
Last day
3.9%
13,970
Compared to previous day
Last week
6.3%
73,987
Compared to previous week
Last month
7.6%
302,538
Compared to previous month
Last year
237.9%
2,465,650
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<testExecutions version="1"> 2 <file path="test/animals.test.ts"> 3 <testCase name="animals - dogs say woof" duration="2" /> 4 <testCase name="animals - figure out what rabbits say" duration="0"> 5 <skipped message="figure out what rabbits say" /> 6 </testCase> 7 <testCase name="animals - flying ones - cats can fly" duration="4"> 8 <failure message="expected false to be true // Object.is equality"> 9 <![CDATA[AssertionError: expected false to be true // Object.is equality 10 at /workspaces/example/test/animals.test.ts:15:47 11 at /workspaces/example/node_modules/vitest/dist/chunk-runtime-chain.7032872a.js:82:26 12 at runTest (/workspaces/example/node_modules/vitest/dist/entry.js:771:40) 13 at async runSuite (/workspaces/example/node_modules/vitest/dist/entry.js:836:13) 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 runFiles (/workspaces/example/node_modules/vitest/dist/entry.js:873:5) 17 at async startTests (/workspaces/example/node_modules/vitest/dist/entry.js:879:3) 18 at async /workspaces/example/node_modules/vitest/dist/entry.js:906:7 19 at async withEnv (/workspaces/example/node_modules/vitest/dist/entry.js:503:5)]]> 20 </failure> 21 </testCase> 22 <testCase name="animals - flying ones - birds can fly" duration="5" /> 23 </file> 24</testExecutions>
No vulnerabilities found.
No security vulnerabilities found.